#[derive(Debug)]
pub enum Error {
FieldCat(field_cat::Error),
RoundCountMismatch {
expected: usize,
actual: usize,
},
SumcheckFinalMismatch,
MerkleVerificationFailed,
DimensionMismatch {
expected: usize,
actual: usize,
},
NotPowerOfTwo {
value: usize,
},
LeafIndexOutOfBounds {
index: usize,
leaf_count: usize,
},
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::FieldCat(e) => write!(f, "field-cat error: {e}"),
Self::RoundCountMismatch { expected, actual } => {
write!(
f,
"sumcheck round count mismatch: expected {expected}, got {actual}"
)
}
Self::SumcheckFinalMismatch => {
write!(f, "sumcheck final evaluation does not match claim")
}
Self::MerkleVerificationFailed => {
write!(f, "Merkle opening verification failed")
}
Self::DimensionMismatch { expected, actual } => {
write!(
f,
"dimension mismatch: expected {expected} variables, got {actual}"
)
}
Self::NotPowerOfTwo { value } => {
write!(f, "{value} is not a power of two")
}
Self::LeafIndexOutOfBounds { index, leaf_count } => {
write!(
f,
"leaf index {index} out of bounds (tree has {leaf_count} leaves)"
)
}
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::FieldCat(e) => Some(e),
Self::RoundCountMismatch { .. }
| Self::SumcheckFinalMismatch
| Self::MerkleVerificationFailed
| Self::DimensionMismatch { .. }
| Self::NotPowerOfTwo { .. }
| Self::LeafIndexOutOfBounds { .. } => None,
}
}
}
impl From<field_cat::Error> for Error {
fn from(e: field_cat::Error) -> Self {
Self::FieldCat(e)
}
}