plonk::Error: Introduce TableError variant

This commit is contained in:
therealyingtong 2023-03-21 14:35:23 +07:00
parent 327b47524c
commit 3f4710892a
1 changed files with 46 additions and 0 deletions

View File

@ -2,6 +2,7 @@ use std::error;
use std::fmt;
use std::io;
use super::TableColumn;
use super::{Any, Column};
/// This is an error that could occur during proving or circuit synthesis.
@ -37,6 +38,8 @@ pub enum Error {
/// The instance sets up a copy constraint involving a column that has not been
/// included in the permutation.
ColumnNotInPermutation(Column<Any>),
/// An error relating to a lookup table.
TableError(TableError),
}
impl From<io::Error> for Error {
@ -79,6 +82,7 @@ impl fmt::Display for Error {
"Column {:?} must be included in the permutation. Help: try applying `meta.enable_equalty` on the column",
column
),
Error::TableError(error) => write!(f, "{}", error)
}
}
}
@ -91,3 +95,45 @@ impl error::Error for Error {
}
}
}
/// This is an error that could occur during table synthesis.
#[derive(Debug)]
pub enum TableError {
/// A `TableColumn` has not been assigned.
ColumnNotAssigned(TableColumn),
/// A Table has columns of uneven lengths.
UnevenColumnLengths((TableColumn, usize), (TableColumn, usize)),
/// Attempt to assign a used `TableColumn`
UsedColumn(TableColumn),
/// Attempt to overwrite a default value
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,
"{:?} not fully assigned. Help: assign a value at offset 0.",
col
)
}
TableError::UnevenColumnLengths((col, col_len), (table, table_len)) => write!(
f,
"{:?} has length {} while {:?} has length {}",
col, col_len, table, table_len
),
TableError::UsedColumn(col) => {
write!(f, "{:?} has already been used", col)
}
TableError::OverwriteDefault(col, default, val) => {
write!(
f,
"Attempted to overwrite default value {} with {} in {:?}",
default, val, col
)
}
}
}
}