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("flushes must have a non-empty list of oracles")]
15	EmptyFlushOracles,
16
17	#[error("All flushes within a channel must have the same width. Expected flushed values with length {expected}, got {got}")]
18	ChannelFlushWidthMismatch { expected: usize, got: usize },
19
20	#[error("All oracles within a single flush must have the same n_vars. Expected oracle with n_vars={expected} got {got}")]
21	ChannelFlushNvarsMismatch { expected: usize, got: usize },
22
23	#[error("Channel id out of range. Got {got}, expected max={max}")]
24	ChannelIdOutOfRange { max: ChannelId, got: ChannelId },
25
26	#[error("{oracle} failed witness validation at index={index}. {reason}")]
27	VirtualOracleEvalMismatch {
28		oracle: String,
29		index: usize,
30		reason: String,
31	},
32
33	#[error("{oracle} witness has unexpected n_vars={witness_num_vars}. Expected n_vars={oracle_num_vars}")]
34	VirtualOracleNvarsMismatch {
35		oracle: String,
36		oracle_num_vars: usize,
37		witness_num_vars: usize,
38	},
39
40	#[error("flush selector oracle {selector} incompatible with oracle {id}")]
41	IncompatibleFlushSelector { id: OracleId, selector: OracleId },
42
43	#[error("Non-zero oracles contain zeros")]
44	Zeros,
45
46	#[error("False eq evaluation claim")]
47	FalseEqEvaluationClaim,
48
49	#[error("cannot commit tower level {tower_level}")]
50	CannotCommitTowerLevel { tower_level: usize },
51
52	#[error("{oracle} underlier witness data does not match")]
53	PackedUnderlierMismatch { oracle: String },
54
55	#[error("witness error: {0}")]
56	Witness(#[from] witness::Error),
57
58	#[error("constraint error: {0}")]
59	Constraint(#[from] protocols::sumcheck::Error),
60
61	#[error("polynomial error: {0}")]
62	Polynomial(#[from] polynomial::Error),
63
64	#[error("greedy evalcheck error: {0}")]
65	Evalcheck(#[from] greedy_evalcheck::Error),
66
67	#[error("prodcheck error: {0}")]
68	Prodcheck(#[from] gkr_gpa::Error),
69
70	#[error("eq-ind sumcheck error: {0}")]
71	EqSumcheck(#[from] gkr_gpa::gpa_sumcheck::error::Error),
72
73	#[error("oracle error: {0}")]
74	Oracle(#[from] oracle::Error),
75
76	#[error("HAL error: {0}")]
77	HalError(#[from] binius_hal::Error),
78
79	#[error("math error: {0}")]
80	MathError(#[from] binius_math::Error),
81
82	#[error("polynomial commitment error: {0}")]
83	PolyCommitError(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
84
85	#[error("PIOP compilation error: {0}")]
86	PIOPCompilerError(#[from] piop::Error),
87
88	#[error("ring switch reduction error: {0}")]
89	RingSwitch(#[from] ring_switch::Error),
90
91	#[error("verification error: {0}")]
92	Verification(#[from] VerificationError),
93
94	#[error("transcript error: {0}")]
95	TranscriptError(#[from] crate::transcript::Error),
96}
97
98#[derive(Debug, thiserror::Error)]
99pub enum VerificationError {
100	#[error("the number of commitments must equal the number of committed batches")]
101	IncorrectNumberOfCommitments,
102	#[error("the number of flush products must equal the number of flushes")]
103	IncorrectNumberOfFlushProducts,
104	#[error(
105		"Channel with id={id} is not balanced. Pushes and pulls do not contain the same elements"
106	)]
107	ChannelUnbalanced { id: ChannelId },
108}