use std::{error, fmt, io};
use super::{Any, Column, TableColumn};
#[derive(Debug)]
pub enum Error {
Synthesis(String),
InvalidInstances,
ConstraintSystemFailure,
BoundsFailure,
Opening,
Transcript(io::Error),
NotEnoughRowsAvailable {
current_k: u32,
},
InstanceTooLarge,
NotEnoughColumnsForConstants,
ColumnNotInPermutation(Column<Any>),
TableError(TableError),
SrsError(usize, usize),
}
impl From<io::Error> for Error {
fn from(error: io::Error) -> Self {
Error::Transcript(error)
}
}
impl Error {
pub(crate) fn not_enough_rows_available(current_k: u32) -> Self {
Error::NotEnoughRowsAvailable { current_k }
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Synthesis(msg) => write!(f, "Synthesis error: {msg}"),
Error::InvalidInstances => write!(f, "Provided instances do not match the circuit"),
Error::ConstraintSystemFailure => write!(f, "The constraint system is not satisfied"),
Error::BoundsFailure => write!(f, "An out-of-bounds index was passed to the backend"),
Error::Opening => write!(f, "Multi-opening proof was invalid"),
Error::Transcript(e) => write!(f, "Transcript error: {e}"),
Error::NotEnoughRowsAvailable { current_k } => write!(
f,
"k = {current_k} is too small for the given circuit. Try using a larger value of k",
),
Error::InstanceTooLarge => write!(f, "Instance vectors are larger than the circuit"),
Error::NotEnoughColumnsForConstants => {
write!(
f,
"Too few fixed columns are enabled for global constants usage"
)
}
Error::ColumnNotInPermutation(column) => write!(
f,
"Column {column:?} must be included in the permutation. Help: try applying `meta.enable_equalty` on the column",
),
Error::TableError(error) => write!(f, "{error}"),
Error::SrsError(srs_k, circuit_k) => write!(f, "The SRS (with size {srs_k}) does not match for the given circuit (of size {circuit_k})")
}
}
}
impl error::Error for Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Error::Transcript(e) => Some(e),
_ => None,
}
}
}
#[derive(Debug)]
pub enum TableError {
ColumnNotAssigned(TableColumn),
UnevenColumnLengths((TableColumn, usize), (TableColumn, usize)),
UsedColumn(TableColumn),
OverwriteDefault(TableColumn, String, String),
}
impl fmt::Display for TableError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
TableError::ColumnNotAssigned(col) => {
write!(
f,
"{col:?} not fully assigned. Help: assign a value at offset 0.",
)
}
TableError::UnevenColumnLengths((col, col_len), (table, table_len)) => write!(
f,
"{col:?} has length {col_len} while {table:?} has length {table_len}",
),
TableError::UsedColumn(col) => {
write!(f, "{col:?} has already been used")
}
TableError::OverwriteDefault(col, default, val) => {
write!(
f,
"Attempted to overwrite default value {default} with {val} in {col:?}",
)
}
}
}
}