#[derive(Debug)]
pub enum Error {
ProofCat(proof_cat::Error),
Plonkish(plonkish_cat::Error),
ColumnOutOfBounds {
index: usize,
column_count: usize,
},
EmptyTrace,
ColumnCountMismatch {
expected: usize,
actual: usize,
},
TraceNotPowerOfTwo {
row_count: usize,
},
UnsatisfiedAirConstraint {
row: usize,
},
NoConstraints,
InsufficientRows {
row_count: usize,
},
RowLengthMismatch {
row: usize,
expected: usize,
actual: usize,
},
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::ProofCat(e) => write!(f, "proof-cat error: {e}"),
Self::Plonkish(e) => write!(f, "plonkish-cat error: {e}"),
Self::ColumnOutOfBounds {
index,
column_count,
} => write!(
f,
"column index {index} out of bounds (column count: {column_count})"
),
Self::EmptyTrace => write!(f, "trace has zero rows"),
Self::ColumnCountMismatch { expected, actual } => {
write!(
f,
"column count mismatch: expected {expected}, got {actual}"
)
}
Self::TraceNotPowerOfTwo { row_count } => {
write!(f, "trace row count {row_count} is not a power of two")
}
Self::UnsatisfiedAirConstraint { row } => {
write!(f, "AIR constraint not satisfied at row pair ({row}, {})", row + 1)
}
Self::NoConstraints => write!(f, "AIR has no constraints"),
Self::InsufficientRows { row_count } => {
write!(f, "trace has {row_count} rows, need at least 2")
}
Self::RowLengthMismatch {
row,
expected,
actual,
} => write!(
f,
"row {row} has {actual} elements, expected {expected}"
),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::ProofCat(e) => Some(e),
Self::Plonkish(e) => Some(e),
Self::ColumnOutOfBounds { .. }
| Self::EmptyTrace
| Self::ColumnCountMismatch { .. }
| Self::TraceNotPowerOfTwo { .. }
| Self::UnsatisfiedAirConstraint { .. }
| Self::NoConstraints
| Self::InsufficientRows { .. }
| Self::RowLengthMismatch { .. } => None,
}
}
}
impl From<proof_cat::Error> for Error {
fn from(e: proof_cat::Error) -> Self {
Self::ProofCat(e)
}
}
impl From<plonkish_cat::Error> for Error {
fn from(e: plonkish_cat::Error) -> Self {
Self::Plonkish(e)
}
}