binius_core/constraint_system/
error.rs

1// Copyright 2024-2025 Irreducible Inc.
2
3use super::channel::ChannelId;
4use crate::{
5	oracle,
6	oracle::OracleId,
7	piop, polynomial, protocols,
8	protocols::{gkr_gpa, greedy_evalcheck},
9	ring_switch, witness,
10};
11
12#[derive(Debug, thiserror::Error)]
13pub enum Error {
14	#[error("flush selector with id {oracle} must have tower level 0 instead of {got_tower_level}")]
15	FlushSelectorTowerLevel {
16		oracle: OracleId,
17		got_tower_level: usize,
18	},
19
20	#[error("flushes must have a non-empty list of oracles")]
21	EmptyFlushOracles,
22
23	#[error(
24		"All flushes within a channel must have the same width. Expected flushed values with length {expected}, got {got}"
25	)]
26	ChannelFlushWidthMismatch { expected: usize, got: usize },
27
28	#[error(
29		"All oracles within a single flush must have the same n_vars. Expected oracle with n_vars={expected} got {got}"
30	)]
31	ChannelFlushNvarsMismatch { expected: usize, got: usize },
32
33	#[error("Channel id out of range. Got {got}, expected max={max}")]
34	ChannelIdOutOfRange { max: ChannelId, got: ChannelId },
35
36	#[error("{oracle} failed witness validation at index={index}. {reason}")]
37	VirtualOracleEvalMismatch {
38		oracle: String,
39		index: usize,
40		reason: String,
41	},
42
43	#[error(
44		"{oracle} witness has unexpected n_vars={witness_num_vars}. Expected n_vars{condition}{oracle_num_vars}"
45	)]
46	VirtualOracleNvarsMismatch {
47		oracle: String,
48		condition: char,
49		oracle_num_vars: usize,
50		witness_num_vars: usize,
51	},
52
53	#[error("flush selector oracle {selector} incompatible with oracle {id}")]
54	IncompatibleFlushSelector { id: OracleId, selector: OracleId },
55
56	#[error("Non-zero oracles contain zeros")]
57	Zeros,
58
59	#[error("False eq evaluation claim")]
60	FalseEqEvaluationClaim,
61
62	#[error("cannot commit tower level {tower_level}")]
63	CannotCommitTowerLevel { tower_level: usize },
64
65	#[error("Tower level cannot be more than 7")]
66	IncorrectTowerLevel,
67
68	#[error("{oracle} underlier witness data does not match")]
69	PackedUnderlierMismatch { oracle: String },
70
71	#[error("witness error: {0}")]
72	Witness(#[from] witness::Error),
73
74	#[error("constraint error: {0}")]
75	Constraint(#[from] protocols::sumcheck::Error),
76
77	#[error("polynomial error: {0}")]
78	Polynomial(#[from] polynomial::Error),
79
80	#[error("greedy evalcheck error: {0}")]
81	Evalcheck(#[from] greedy_evalcheck::Error),
82
83	#[error("prodcheck error: {0}")]
84	Prodcheck(#[from] gkr_gpa::Error),
85
86	#[error("oracle error: {0}")]
87	Oracle(#[from] oracle::Error),
88
89	#[error("HAL error: {0}")]
90	HalError(#[from] binius_hal::Error),
91
92	#[error("math error: {0}")]
93	MathError(#[from] binius_math::Error),
94
95	#[error("ntt error: {0}")]
96	NTTError(#[from] binius_ntt::Error),
97
98	#[error("polynomial commitment error: {0}")]
99	PolyCommitError(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
100
101	#[error("PIOP compilation error: {0}")]
102	PIOPCompilerError(#[from] piop::Error),
103
104	#[error("ring switch reduction error: {0}")]
105	RingSwitch(#[from] ring_switch::Error),
106
107	#[error("verification error: {0}")]
108	Verification(#[from] VerificationError),
109
110	#[error("transcript error: {0}")]
111	TranscriptError(#[from] crate::transcript::Error),
112
113	#[error("gkr exp error: {0}")]
114	GkrExp(#[from] crate::protocols::gkr_exp::Error),
115}
116
117#[derive(Debug, thiserror::Error)]
118pub enum VerificationError {
119	#[error("the number of commitments must equal the number of committed batches")]
120	IncorrectNumberOfCommitments,
121	#[error("the number of flush products must equal the number of flushes")]
122	IncorrectNumberOfFlushProducts,
123	#[error(
124		"Channel with id={id} is not balanced. Pushes and pulls do not contain the same elements"
125	)]
126	ChannelUnbalanced { id: ChannelId },
127}