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("ProverState::execute called with incorrect number of evaluators, expected {expected}")]
37	IncorrectNumberOfEvaluators { expected: usize },
38	#[error("sumcheck naive witness validation failed: composition index {composition_index}")]
39	SumcheckNaiveValidationFailure { composition_index: usize },
40	#[error(
41		"zerocheck naive witness validation failed: {composition_name}, vertex index {vertex_index}"
42	)]
43	ZerocheckNaiveValidationFailure {
44		composition_name: String,
45		vertex_index: usize,
46	},
47	#[error(
48		"nonzerocheck naive witness validation failed: oracle {oracle}, hypercube index {hypercube_index}"
49	)]
50	NonzerocheckNaiveValidationFailure {
51		oracle: String,
52		hypercube_index: usize,
53	},
54	#[error(
55		"evaluation domain should start with zero and one, and contain Karatsuba infinity for degrees above 1"
56	)]
57	IncorrectSumcheckEvaluationDomain,
58	#[error("evaluation domains are not proper prefixes of each other")]
59	NonProperPrefixEvaluationDomain,
60	#[error("constraint set contains multilinears of different heights")]
61	ConstraintSetNumberOfVariablesMismatch,
62	#[error("batching sumchecks and zerochecks is not supported yet")]
63	MixedBatchingNotSupported,
64	#[error("base field and extension field constraint sets don't match")]
65	BaseAndExtensionFieldConstraintSetsMismatch,
66	#[error("some multilinear evals cannot be embedded into base field in the first round")]
67	MultilinearEvalsCannotBeEmbeddedInBaseField,
68	#[error("eq_ind sumcheck challenges number does not equal number of variables")]
69	IncorrectEqIndChallengesLength,
70	#[error("zerocheck challenges number does not equal number of variables")]
71	IncorrectZerocheckChallengesLength,
72	#[error(
73		"suffixes count not equal to multilinear count, const suffix longer than multilinear, or not const"
74	)]
75	IncorrectConstSuffixes,
76	#[error("incorrect size of the equality indicator expansion in eq_ind sumcheck")]
77	IncorrectEqIndPartialEvalsSize,
78	#[error("incorrect size of the partially evaluated zerocheck equality indicator")]
79	IncorrectZerocheckPartialEqIndSize,
80	#[error(
81		"the number of prime polynomial sums does not match the number of zerocheck compositions"
82	)]
83	IncorrectClaimedPrimeSumsLength,
84	#[error("constant evaluation suffix longer than trace size")]
85	ConstEvalSuffixTooLong,
86	#[error("the number of evaluations at 1 in the first round is of incorrect length")]
87	IncorrectFirstRoundEvalOnesLength,
88	#[error("batch proof shape does not conform to the provided indexed claims")]
89	ClaimProofMismatch,
90	#[error("either too many or too few sumcheck challenges")]
91	IncorrectNumberOfChallenges,
92	#[error("either too many or too few batching coefficients")]
93	IncorrectNumberOfBatchCoeffs,
94	#[error("cannot skip more rounds than the total number of variables")]
95	TooManySkippedRounds,
96	#[error("univariatizing reduction claim count does not match sumcheck, or n_vars is incorrect")]
97	IncorrectUnivariatizingReductionClaims,
98	#[error("univariatizing reduction sumcheck of incorrect length")]
99	IncorrectUnivariatizingReductionSumcheck,
100	#[error("the presampled batched coeffs count does not equal the number of claims")]
101	IncorrectPrebatchedCoeffCount,
102	#[error(
103		"specified Lagrange evaluation domain is too small to uniquely recover round polynomial"
104	)]
105	LagrangeDomainTooSmall,
106	#[error("adding together Lagrange basis evaluations over domains of different sizes")]
107	LagrangeRoundEvalsSizeMismatch,
108	#[error("oracle error: {0}")]
109	Oracle(#[from] OracleError),
110	#[error("witness error: {0}")]
111	Witness(#[from] WitnessError),
112	#[error("polynomial error: {0}")]
113	Polynomial(#[from] PolynomialError),
114	#[error("verification failure: {0}")]
115	Verification(#[from] VerificationError),
116	#[error("ntt error: {0}")]
117	NttError(#[from] binius_ntt::Error),
118	#[error("math error: {0}")]
119	MathError(#[from] binius_math::Error),
120	#[error("HAL error: {0}")]
121	HalError(#[from] binius_hal::Error),
122	#[error("compute error: {0}")]
123	Compute(#[from] binius_compute::Error),
124	#[error("allocation error: {0}")]
125	Allocation(#[from] binius_compute::alloc::Error),
126	#[error("Transcript error: {0}")]
127	TranscriptError(#[from] crate::transcript::Error),
128}
129
130#[derive(Debug, thiserror::Error)]
131pub enum VerificationError {
132	#[error("number of coefficients in round {round} proof is incorrect, expected {expected}")]
133	NumberOfCoefficients { round: usize, expected: usize },
134	#[error("incorrect number of rounds")]
135	NumberOfRounds,
136	#[error("the number of final evaluations must match the number of instances")]
137	NumberOfFinalEvaluations,
138	#[error("the number of reduced multilinear evaluations should conform to the claim shape")]
139	NumberOfMultilinearEvals,
140	#[error("the final batch composite evaluation is incorrect")]
141	IncorrectBatchEvaluation,
142	#[error("the proof contains an incorrect evaluation of the eq indicator")]
143	IncorrectEqIndEvaluation,
144	#[error(
145		"the proof contains an incorrect Lagrange coefficients multilinear extension evaluation"
146	)]
147	IncorrectLagrangeMultilinearEvaluation,
148	#[error("skipped rounds count is more than the number of variables in a univariate claim")]
149	IncorrectSkippedRoundsCount,
150	#[error(
151		"zero eval prefix does not match the skipped variables of the smaller univariate multinears"
152	)]
153	IncorrectZerosPrefixLen,
154	#[error("non-zero Lagrange evals count does not match expected univariate domain size")]
155	IncorrectLagrangeRoundEvalsLen,
156	#[error("claimed multilinear evaluations do not match univariate round at challenge point")]
157	ClaimedSumRoundEvalsMismatch,
158}