Skip to main content

binius_core/
error.rs

1// Copyright 2025 Irreducible Inc.
2//! Hosts error definitions for the core crate.
3
4use crate::consts::MIN_WORDS_PER_SEGMENT;
5
6/// Constraint system related error.
7#[allow(missing_docs)] // errors are self-documenting
8#[derive(Debug, thiserror::Error)]
9pub enum ConstraintSystemError {
10	#[error("the public input segment must have power of two length")]
11	PublicInputPowerOfTwo,
12	#[error(
13		"the public input segment must be at least {MIN_WORDS_PER_SEGMENT} words, got: {pub_input_size}"
14	)]
15	PublicInputTooShort { pub_input_size: usize },
16	#[error("the data length doesn't match layout. Expected: {expected}, Actual: {actual}")]
17	ValueVecLenMismatch { expected: usize, actual: usize },
18	#[error(
19		"{constraint_type} #{constraint_index} uses non canonical shift in its {operand_name} operand"
20	)]
21	NonCanonicalShift {
22		constraint_type: &'static str,
23		constraint_index: usize,
24		operand_name: &'static str,
25	},
26	#[error(
27		"{constraint_type} #{constraint_index} refers to padding in its {operand_name} operand"
28	)]
29	PaddingValueIndex {
30		constraint_type: &'static str,
31		operand_name: &'static str,
32		constraint_index: usize,
33	},
34	#[error(
35		"{constraint_type} #{constraint_index} uses shift amount n={shift_amount}>=64 {operand_name} operand"
36	)]
37	ShiftAmountTooLarge {
38		constraint_type: &'static str,
39		constraint_index: usize,
40		operand_name: &'static str,
41		shift_amount: usize,
42	},
43	#[error(
44		"{constraint_type} #{constraint_index} refers to out-of-range value index in {operand_name} operand (index {value_index} >= total length {total_len})"
45	)]
46	OutOfRangeValueIndex {
47		constraint_type: &'static str,
48		constraint_index: usize,
49		operand_name: &'static str,
50		value_index: u32,
51		total_len: usize,
52	},
53}