binius_core/constraint_system/
error.rs

1// Copyright 2024-2025 Irreducible Inc.
2
3use super::channel::ChannelId;
4use crate::{
5	constraint_system::TableId,
6	oracle::{self, OracleId},
7	piop, polynomial,
8	protocols::{self, 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("table {table_id} is required to have a power-of-two size, instead got {size}")]
54	TableSizePowerOfTwoRequired { table_id: TableId, size: usize },
55	#[error("table {table_id} is required to have a fixed power-of-two size, instead got {size}")]
56	TableSizeFixedRequired { table_id: TableId, size: usize },
57	#[error("table sizes vector should have length {expected}, instead got {got}")]
58	TableSizesLenMismatch { expected: usize, got: usize },
59
60	#[error("flush selector oracle {selector} incompatible with oracle {id}")]
61	IncompatibleFlushSelector { id: OracleId, selector: OracleId },
62
63	#[error("Non-zero oracles contain zeros")]
64	Zeros,
65
66	#[error("False eq evaluation claim")]
67	FalseEqEvaluationClaim,
68
69	#[error("cannot commit tower level {tower_level}")]
70	CannotCommitTowerLevel { tower_level: usize },
71
72	#[error("Tower level cannot be more than 7")]
73	IncorrectTowerLevel,
74
75	#[error("{oracle} underlier witness data does not match")]
76	PackedUnderlierMismatch { oracle: String },
77
78	#[error("witness error: {0}")]
79	Witness(#[from] witness::Error),
80
81	#[error("constraint error: {0}")]
82	Constraint(#[from] protocols::sumcheck::Error),
83
84	#[error("polynomial error: {0}")]
85	Polynomial(#[from] polynomial::Error),
86
87	#[error("greedy evalcheck error: {0}")]
88	Evalcheck(#[from] greedy_evalcheck::Error),
89
90	#[error("prodcheck error: {0}")]
91	Prodcheck(#[from] gkr_gpa::Error),
92
93	#[error("oracle error: {0}")]
94	Oracle(#[from] oracle::Error),
95
96	#[error("HAL error: {0}")]
97	HalError(#[from] binius_hal::Error),
98
99	#[error("math error: {0}")]
100	MathError(#[from] binius_math::Error),
101
102	#[error("ntt error: {0}")]
103	NTTError(#[from] binius_ntt::Error),
104
105	#[error("polynomial commitment error: {0}")]
106	PolyCommitError(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
107
108	#[error("PIOP compilation error: {0}")]
109	PIOPCompilerError(#[from] piop::Error),
110
111	#[error("ring switch reduction error: {0}")]
112	RingSwitch(#[from] ring_switch::Error),
113
114	#[error("verification error: {0}")]
115	Verification(#[from] VerificationError),
116
117	#[error("transcript error: {0}")]
118	TranscriptError(#[from] crate::transcript::Error),
119
120	#[error("gkr exp error: {0}")]
121	GkrExp(#[from] crate::protocols::gkr_exp::Error),
122}
123
124#[derive(Debug, thiserror::Error)]
125pub enum VerificationError {
126	#[error("the number of commitments must equal the number of committed batches")]
127	IncorrectNumberOfCommitments,
128	#[error("the number of flush products must equal the number of flushes")]
129	IncorrectNumberOfFlushProducts,
130	#[error(
131		"Channel with id={id} is not balanced. Pushes and pulls do not contain the same elements"
132	)]
133	ChannelUnbalanced { id: ChannelId },
134}