1use std::error;
2use std::fmt;
3use std::io;
45use super::TableColumn;
6use super::{Any, Column};
78/// This is an error that could occur during proving or circuit synthesis.
9// TODO: these errors need to be cleaned up
10#[derive(Debug)]
11pub enum Error {
12/// This is an error that can occur during synthesis of the circuit, for
13 /// example, when the witness is not present.
14Synthesis,
15/// The provided instances do not match the circuit parameters.
16InvalidInstances,
17/// The constraint system is not satisfied.
18ConstraintSystemFailure,
19/// Out of bounds index passed to a backend
20BoundsFailure,
21/// Opening error
22Opening,
23/// Transcript error
24Transcript(io::Error),
25/// `k` is too small for the given circuit.
26NotEnoughRowsAvailable {
27/// The current value of `k` being used.
28current_k: u32,
29 },
30/// Instance provided exceeds number of available rows
31InstanceTooLarge,
32/// Circuit synthesis requires global constants, but circuit configuration did not
33 /// call [`ConstraintSystem::enable_constant`] on fixed columns with sufficient space.
34 ///
35 /// [`ConstraintSystem::enable_constant`]: crate::plonk::ConstraintSystem::enable_constant
36NotEnoughColumnsForConstants,
37/// The instance sets up a copy constraint involving a column that has not been
38 /// included in the permutation.
39ColumnNotInPermutation(Column<Any>),
40/// An error relating to a lookup table.
41TableError(TableError),
42}
4344impl From<io::Error> for Error {
45fn from(error: io::Error) -> Self {
46// The only place we can get io::Error from is the transcript.
47Error::Transcript(error)
48 }
49}
5051impl Error {
52/// Constructs an `Error::NotEnoughRowsAvailable`.
53pub(crate) fn not_enough_rows_available(current_k: u32) -> Self {
54 Error::NotEnoughRowsAvailable { current_k }
55 }
56}
5758impl fmt::Display for Error {
59fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60match self {
61 Error::Synthesis => write!(f, "General synthesis error"),
62 Error::InvalidInstances => write!(f, "Provided instances do not match the circuit"),
63 Error::ConstraintSystemFailure => write!(f, "The constraint system is not satisfied"),
64 Error::BoundsFailure => write!(f, "An out-of-bounds index was passed to the backend"),
65 Error::Opening => write!(f, "Multi-opening proof was invalid"),
66 Error::Transcript(e) => write!(f, "Transcript error: {}", e),
67 Error::NotEnoughRowsAvailable { current_k } => write!(
68 f,
69"k = {} is too small for the given circuit. Try using a larger value of k",
70 current_k,
71 ),
72 Error::InstanceTooLarge => write!(f, "Instance vectors are larger than the circuit"),
73 Error::NotEnoughColumnsForConstants => {
74write!(
75 f,
76"Too few fixed columns are enabled for global constants usage"
77)
78 }
79 Error::ColumnNotInPermutation(column) => write!(
80 f,
81"Column {:?} must be included in the permutation. Help: try applying `meta.enable_equalty` on the column",
82 column
83 ),
84 Error::TableError(error) => write!(f, "{}", error)
85 }
86 }
87}
8889impl error::Error for Error {
90fn source(&self) -> Option<&(dyn error::Error + 'static)> {
91match self {
92 Error::Transcript(e) => Some(e),
93_ => None,
94 }
95 }
96}
9798/// This is an error that could occur during table synthesis.
99#[derive(Debug)]
100pub enum TableError {
101/// A `TableColumn` has not been assigned.
102ColumnNotAssigned(TableColumn),
103/// A Table has columns of uneven lengths.
104UnevenColumnLengths((TableColumn, usize), (TableColumn, usize)),
105/// Attempt to assign a used `TableColumn`
106UsedColumn(TableColumn),
107/// Attempt to overwrite a default value
108OverwriteDefault(TableColumn, String, String),
109}
110111impl fmt::Display for TableError {
112fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
113match self {
114 TableError::ColumnNotAssigned(col) => {
115write!(
116 f,
117"{:?} not fully assigned. Help: assign a value at offset 0.",
118 col
119 )
120 }
121 TableError::UnevenColumnLengths((col, col_len), (table, table_len)) => write!(
122 f,
123"{:?} has length {} while {:?} has length {}",
124 col, col_len, table, table_len
125 ),
126 TableError::UsedColumn(col) => {
127write!(f, "{:?} has already been used", col)
128 }
129 TableError::OverwriteDefault(col, default, val) => {
130write!(
131 f,
132"Attempted to overwrite default value {} with {} in {:?}",
133 default, val, col
134 )
135 }
136 }
137 }
138}