1#[derive(Debug)]
5pub enum Error {
6 Plonkish(plonkish_cat::Error),
8 WitnessSizeMismatch {
10 expected: usize,
12 actual: usize,
14 },
15 UnsatisfiedConstraint {
17 index: usize,
19 },
20 RoundCountMismatch {
22 expected: usize,
24 actual: usize,
26 },
27 SumcheckFinalMismatch,
29 MerkleVerificationFailed,
31 DimensionMismatch {
33 expected: usize,
35 actual: usize,
37 },
38 EmptyConstraintSet,
40 NotPowerOfTwo {
42 value: usize,
44 },
45 InvalidFieldEncoding,
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::WitnessSizeMismatch { expected, actual } => {
61 write!(f, "witness size mismatch: expected {expected}, got {actual}")
62 }
63 Self::UnsatisfiedConstraint { index } => {
64 write!(f, "constraint {index} not satisfied by witness")
65 }
66 Self::RoundCountMismatch { expected, actual } => {
67 write!(
68 f,
69 "sumcheck round count mismatch: expected {expected}, got {actual}"
70 )
71 }
72 Self::SumcheckFinalMismatch => {
73 write!(f, "sumcheck final evaluation does not match claim")
74 }
75 Self::MerkleVerificationFailed => {
76 write!(f, "Merkle opening verification failed")
77 }
78 Self::DimensionMismatch { expected, actual } => {
79 write!(
80 f,
81 "dimension mismatch: expected {expected} variables, got {actual}"
82 )
83 }
84 Self::EmptyConstraintSet => write!(f, "constraint set is empty"),
85 Self::NotPowerOfTwo { value } => {
86 write!(f, "{value} is not a power of two")
87 }
88 Self::InvalidFieldEncoding => write!(f, "invalid field element encoding"),
89 Self::LeafIndexOutOfBounds { index, leaf_count } => {
90 write!(
91 f,
92 "leaf index {index} out of bounds (tree has {leaf_count} leaves)"
93 )
94 }
95 }
96 }
97}
98
99impl std::error::Error for Error {
100 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
101 match self {
102 Self::Plonkish(e) => Some(e),
103 Self::WitnessSizeMismatch { .. }
104 | Self::UnsatisfiedConstraint { .. }
105 | Self::RoundCountMismatch { .. }
106 | Self::SumcheckFinalMismatch
107 | Self::MerkleVerificationFailed
108 | Self::DimensionMismatch { .. }
109 | Self::EmptyConstraintSet
110 | Self::NotPowerOfTwo { .. }
111 | Self::InvalidFieldEncoding
112 | Self::LeafIndexOutOfBounds { .. } => None,
113 }
114 }
115}
116
117impl From<plonkish_cat::Error> for Error {
118 fn from(e: plonkish_cat::Error) -> Self {
119 Self::Plonkish(e)
120 }
121}