1#[derive(Debug)]
5pub enum Error {
6 ProofCat(proof_cat::Error),
8 Plonkish(plonkish_cat::Error),
10 ColumnOutOfBounds {
12 index: usize,
14 column_count: usize,
16 },
17 EmptyTrace,
19 ColumnCountMismatch {
21 expected: usize,
23 actual: usize,
25 },
26 TraceNotPowerOfTwo {
28 row_count: usize,
30 },
31 UnsatisfiedAirConstraint {
33 row: usize,
35 },
36 NoConstraints,
38 InsufficientRows {
40 row_count: usize,
42 },
43 RowLengthMismatch {
45 row: usize,
47 expected: usize,
49 actual: usize,
51 },
52}
53
54impl core::fmt::Display for Error {
55 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
56 match self {
57 Self::ProofCat(e) => write!(f, "proof-cat error: {e}"),
58 Self::Plonkish(e) => write!(f, "plonkish-cat error: {e}"),
59 Self::ColumnOutOfBounds {
60 index,
61 column_count,
62 } => write!(
63 f,
64 "column index {index} out of bounds (column count: {column_count})"
65 ),
66 Self::EmptyTrace => write!(f, "trace has zero rows"),
67 Self::ColumnCountMismatch { expected, actual } => {
68 write!(
69 f,
70 "column count mismatch: expected {expected}, got {actual}"
71 )
72 }
73 Self::TraceNotPowerOfTwo { row_count } => {
74 write!(f, "trace row count {row_count} is not a power of two")
75 }
76 Self::UnsatisfiedAirConstraint { row } => {
77 write!(f, "AIR constraint not satisfied at row pair ({row}, {})", row + 1)
78 }
79 Self::NoConstraints => write!(f, "AIR has no constraints"),
80 Self::InsufficientRows { row_count } => {
81 write!(f, "trace has {row_count} rows, need at least 2")
82 }
83 Self::RowLengthMismatch {
84 row,
85 expected,
86 actual,
87 } => write!(
88 f,
89 "row {row} has {actual} elements, expected {expected}"
90 ),
91 }
92 }
93}
94
95impl std::error::Error for Error {
96 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
97 match self {
98 Self::ProofCat(e) => Some(e),
99 Self::Plonkish(e) => Some(e),
100 Self::ColumnOutOfBounds { .. }
101 | Self::EmptyTrace
102 | Self::ColumnCountMismatch { .. }
103 | Self::TraceNotPowerOfTwo { .. }
104 | Self::UnsatisfiedAirConstraint { .. }
105 | Self::NoConstraints
106 | Self::InsufficientRows { .. }
107 | Self::RowLengthMismatch { .. } => None,
108 }
109 }
110}
111
112impl From<proof_cat::Error> for Error {
113 fn from(e: proof_cat::Error) -> Self {
114 Self::ProofCat(e)
115 }
116}
117
118impl From<plonkish_cat::Error> for Error {
119 fn from(e: plonkish_cat::Error) -> Self {
120 Self::Plonkish(e)
121 }
122}