1#[derive(Debug)]
5pub enum Error {
6 Plonkish(plonkish_cat::Error),
8 FieldCat(field_cat::Error),
10 WitnessSizeMismatch {
12 expected: usize,
14 actual: usize,
16 },
17 UnsatisfiedConstraint {
19 index: usize,
21 },
22 RoundCountMismatch {
24 expected: usize,
26 actual: usize,
28 },
29 SumcheckFinalMismatch,
31 MerkleVerificationFailed,
33 DimensionMismatch {
35 expected: usize,
37 actual: usize,
39 },
40 EmptyConstraintSet,
42 NotPowerOfTwo {
44 value: usize,
46 },
47 LeafIndexOutOfBounds {
49 index: usize,
51 leaf_count: usize,
53 },
54}
55
56impl core::fmt::Display for Error {
57 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
58 match self {
59 Self::Plonkish(e) => write!(f, "plonkish-cat error: {e}"),
60 Self::FieldCat(e) => write!(f, "field-cat error: {e}"),
61 Self::WitnessSizeMismatch { expected, actual } => {
62 write!(
63 f,
64 "witness size mismatch: expected {expected}, got {actual}"
65 )
66 }
67 Self::UnsatisfiedConstraint { index } => {
68 write!(f, "constraint {index} not satisfied by witness")
69 }
70 Self::RoundCountMismatch { expected, actual } => {
71 write!(
72 f,
73 "sumcheck round count mismatch: expected {expected}, got {actual}"
74 )
75 }
76 Self::SumcheckFinalMismatch => {
77 write!(f, "sumcheck final evaluation does not match claim")
78 }
79 Self::MerkleVerificationFailed => {
80 write!(f, "Merkle opening verification failed")
81 }
82 Self::DimensionMismatch { expected, actual } => {
83 write!(
84 f,
85 "dimension mismatch: expected {expected} variables, got {actual}"
86 )
87 }
88 Self::EmptyConstraintSet => write!(f, "constraint set is empty"),
89 Self::NotPowerOfTwo { value } => {
90 write!(f, "{value} is not a power of two")
91 }
92 Self::LeafIndexOutOfBounds { index, leaf_count } => {
93 write!(
94 f,
95 "leaf index {index} out of bounds (tree has {leaf_count} leaves)"
96 )
97 }
98 }
99 }
100}
101
102impl std::error::Error for Error {
103 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
104 match self {
105 Self::Plonkish(e) => Some(e),
106 Self::FieldCat(e) => Some(e),
107 Self::WitnessSizeMismatch { .. }
108 | Self::UnsatisfiedConstraint { .. }
109 | Self::RoundCountMismatch { .. }
110 | Self::SumcheckFinalMismatch
111 | Self::MerkleVerificationFailed
112 | Self::DimensionMismatch { .. }
113 | Self::EmptyConstraintSet
114 | Self::NotPowerOfTwo { .. }
115 | Self::LeafIndexOutOfBounds { .. } => None,
116 }
117 }
118}
119
120impl From<plonkish_cat::Error> for Error {
121 fn from(e: plonkish_cat::Error) -> Self {
122 Self::Plonkish(e)
123 }
124}
125
126impl From<field_cat::Error> for Error {
127 fn from(e: field_cat::Error) -> Self {
128 Self::FieldCat(e)
129 }
130}