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