binius_core/protocols/sumcheck/
error.rs

1// Copyright 2024-2025 Irreducible Inc.
2
3use crate::{
4	oracle::Error as OracleError, polynomial::Error as PolynomialError,
5	witness::Error as WitnessError,
6};
7
8#[derive(Debug, thiserror::Error)]
9pub enum Error {
10	#[error(
11		"composition polynomial has an incorrect number of variables; expected {expected}, got {actual}"
12	)]
13	InvalidComposition { actual: usize, expected: usize },
14	#[error("claims must be sorted by number of variables")]
15	ClaimsOutOfOrder,
16	#[error("claims have inconsistent evaluation orders")]
17	InconsistentEvaluationOrder,
18	#[error("failed to downcast a composition expression into a subfield expression")]
19	CircuitFieldDowncastFailed,
20	#[error("expected a call to try_finish_claim")]
21	ExpectedFinishClaim,
22	#[error("expected a call to finish_round")]
23	ExpectedFinishRound,
24	#[error("expected a call to receive_coeffs")]
25	ExpectedReceiveCoeffs,
26	#[error("expected call to finish")]
27	ExpectedFinish,
28	#[error("expected call to execute")]
29	ExpectedExecution,
30	#[error("expected call to fold")]
31	ExpectedFold,
32	#[error("expected call to project_to_skipped_variables")]
33	ExpectedProjection,
34	#[error("the number of variables for the prover multilinears must all be equal")]
35	NumberOfVariablesMismatch,
36	#[error(
37		"ProverState::execute called with incorrect number of evaluators, expected {expected}"
38	)]
39	IncorrectNumberOfEvaluators { expected: usize },
40	#[error("sumcheck naive witness validation failed: composition index {composition_index}")]
41	SumcheckNaiveValidationFailure { composition_index: usize },
42	#[error("zerocheck naive witness validation failed: {composition_name}, vertex index {vertex_index}")]
43	ZerocheckNaiveValidationFailure {
44		composition_name: String,
45		vertex_index: usize,
46	},
47	#[error("nonzerocheck naive witness validation failed: oracle {oracle}, hypercube index {hypercube_index}")]
48	NonzerocheckNaiveValidationFailure {
49		oracle: String,
50		hypercube_index: usize,
51	},
52	#[error("evaluation domain should start with zero and one, and contain Karatsuba infinity for degrees above 1")]
53	IncorrectSumcheckEvaluationDomain,
54	#[error("evaluation domains are not proper prefixes of each other")]
55	NonProperPrefixEvaluationDomain,
56	#[error("constraint set contains multilinears of different heights")]
57	ConstraintSetNumberOfVariablesMismatch,
58	#[error("batching sumchecks and zerochecks is not supported yet")]
59	MixedBatchingNotSupported,
60	#[error("base field and extension field constraint sets don't match")]
61	BaseAndExtensionFieldConstraintSetsMismatch,
62	#[error("some multilinear evals cannot be embedded into base field in the first round")]
63	MultilinearEvalsCannotBeEmbeddedInBaseField,
64	#[error("eq_ind sumcheck challenges number does not equal number of variables")]
65	IncorrectEqIndChallengesLength,
66	#[error("zerocheck challenges number does not equal number of variables")]
67	IncorrectZerocheckChallengesLength,
68	#[error("suffixes count not equal to multilinear count, const suffix longer than multilinear, or not const")]
69	IncorrectConstSuffixes,
70	#[error("incorrect size of the equality indicator expansion in eq_ind sumcheck")]
71	IncorrectEqIndPartialEvalsSize,
72	#[error("incorrect size of the partially evaluated zerocheck equality indicator")]
73	IncorrectZerocheckPartialEqIndSize,
74	#[error(
75		"the number of prime polynomial sums does not match the number of zerocheck compositions"
76	)]
77	IncorrectClaimedPrimeSumsLength,
78	#[error("constant evaluation suffix longer than trace size")]
79	ConstEvalSuffixTooLong,
80	#[error("the number of evaluations at 1 in the first round is of incorrect length")]
81	IncorrectFirstRoundEvalOnesLength,
82	#[error("batch proof shape does not conform to the provided indexed claims")]
83	ClaimProofMismatch,
84	#[error("either too many or too few sumcheck challenges")]
85	IncorrectNumberOfChallenges,
86	#[error("either too many or too few batching coefficients")]
87	IncorrectNumberOfBatchCoeffs,
88	#[error("cannot skip more rounds than the total number of variables")]
89	TooManySkippedRounds,
90	#[error(
91		"univariatizing reduction claim count does not match sumcheck, or n_vars is incorrect"
92	)]
93	IncorrectUnivariatizingReductionClaims,
94	#[error("univariatizing reduction sumcheck of incorrect length")]
95	IncorrectUnivariatizingReductionSumcheck,
96	#[error("the presampled batched coeffs count does not equal the number of claims")]
97	IncorrectPrebatchedCoeffCount,
98	#[error(
99		"specified Lagrange evaluation domain is too small to uniquely recover round polynomial"
100	)]
101	LagrangeDomainTooSmall,
102	#[error("adding together Lagrange basis evaluations over domains of different sizes")]
103	LagrangeRoundEvalsSizeMismatch,
104	#[error("oracle error: {0}")]
105	Oracle(#[from] OracleError),
106	#[error("witness error: {0}")]
107	Witness(#[from] WitnessError),
108	#[error("polynomial error: {0}")]
109	Polynomial(#[from] PolynomialError),
110	#[error("verification failure: {0}")]
111	Verification(#[from] VerificationError),
112	#[error("ntt error: {0}")]
113	NttError(#[from] binius_ntt::Error),
114	#[error("math error: {0}")]
115	MathError(#[from] binius_math::Error),
116	#[error("HAL error: {0}")]
117	HalError(#[from] binius_hal::Error),
118	#[error("Transcript error: {0}")]
119	TranscriptError(#[from] crate::transcript::Error),
120}
121
122#[derive(Debug, thiserror::Error)]
123pub enum VerificationError {
124	#[error("number of coefficients in round {round} proof is incorrect, expected {expected}")]
125	NumberOfCoefficients { round: usize, expected: usize },
126	#[error("incorrect number of rounds")]
127	NumberOfRounds,
128	#[error("the number of final evaluations must match the number of instances")]
129	NumberOfFinalEvaluations,
130	#[error("the number of reduced multilinear evaluations should conform to the claim shape")]
131	NumberOfMultilinearEvals,
132	#[error("the final batch composite evaluation is incorrect")]
133	IncorrectBatchEvaluation,
134	#[error("the proof contains an incorrect evaluation of the eq indicator")]
135	IncorrectEqIndEvaluation,
136	#[error(
137		"the proof contains an incorrect Lagrange coefficients multilinear extension evaluation"
138	)]
139	IncorrectLagrangeMultilinearEvaluation,
140	#[error("skipped rounds count is more than the number of variables in a univariate claim")]
141	IncorrectSkippedRoundsCount,
142	#[error("zero eval prefix does not match the skipped variables of the smaller univariate multinears")]
143	IncorrectZerosPrefixLen,
144	#[error("non-zero Lagrange evals count does not match expected univariate domain size")]
145	IncorrectLagrangeRoundEvalsLen,
146	#[error("claimed multilinear evaluations do not match univariate round at challenge point")]
147	ClaimedSumRoundEvalsMismatch,
148}