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 total length of the value vector must be a power of two")]
11	ValueVecLenNotPowerOfTwo,
12	#[error("the public input segment must have power of two length")]
13	PublicInputPowerOfTwo,
14	#[error(
15		"the public input segment must be at least {MIN_WORDS_PER_SEGMENT} words, got: {pub_input_size}"
16	)]
17	PublicInputTooShort { pub_input_size: usize },
18	#[error("the data length doesn't match layout")]
19	ValueVecLenMismatch { expected: usize, actual: usize },
20	#[error(
21		"{constraint_type} #{constraint_index} uses non canonical shift in its {operand_name} operand"
22	)]
23	NonCanonicalShift {
24		constraint_type: &'static str,
25		constraint_index: usize,
26		operand_name: &'static str,
27	},
28	#[error(
29		"{constraint_type} #{constraint_index} refers to padding in its {operand_name} operand"
30	)]
31	PaddingValueIndex {
32		constraint_type: &'static str,
33		operand_name: &'static str,
34		constraint_index: usize,
35	},
36	#[error(
37		"{constraint_type} #{constraint_index} uses shift amount n={shift_amount}>=64 {operand_name} operand"
38	)]
39	ShiftAmountTooLarge {
40		constraint_type: &'static str,
41		constraint_index: usize,
42		operand_name: &'static str,
43		shift_amount: usize,
44	},
45	#[error(
46		"{constraint_type} #{constraint_index} refers to out-of-range value index in {operand_name} operand (index {value_index} >= total length {total_len})"
47	)]
48	OutOfRangeValueIndex {
49		constraint_type: &'static str,
50		constraint_index: usize,
51		operand_name: &'static str,
52		value_index: u32,
53		total_len: usize,
54	},
55}