1use std::cmp;
2use std::error;
3use std::fmt;
4use std::io;
56use 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}
4142impl From<io::Error> for Error {
43fn from(error: io::Error) -> Self {
44// The only place we can get io::Error from is the transcript.
45Error::Transcript(error)
46 }
47}
4849impl Error {
50/// Constructs an `Error::NotEnoughRowsAvailable`.
51pub(crate) fn not_enough_rows_available(current_k: u32) -> Self {
52 Error::NotEnoughRowsAvailable { current_k }
53 }
54}
5556impl fmt::Display for Error {
57fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58match self {
59 Error::Synthesis => write!(f, "General synthesis error"),
60 Error::InvalidInstances => write!(f, "Provided instances do not match the circuit"),
61 Error::ConstraintSystemFailure => write!(f, "The constraint system is not satisfied"),
62 Error::BoundsFailure => write!(f, "An out-of-bounds index was passed to the backend"),
63 Error::Opening => write!(f, "Multi-opening proof was invalid"),
64 Error::Transcript(e) => write!(f, "Transcript error: {}", e),
65 Error::NotEnoughRowsAvailable { current_k } => write!(
66 f,
67"k = {} is too small for the given circuit. Try using a larger value of k",
68 current_k,
69 ),
70 Error::InstanceTooLarge => write!(f, "Instance vectors are larger than the circuit"),
71 Error::NotEnoughColumnsForConstants => {
72write!(
73 f,
74"Too few fixed columns are enabled for global constants usage"
75)
76 }
77 Error::ColumnNotInPermutation(column) => write!(
78 f,
79"Column {:?} must be included in the permutation. Help: try applying `meta.enable_equalty` on the column",
80 column
81 ),
82 }
83 }
84}
8586impl error::Error for Error {
87fn source(&self) -> Option<&(dyn error::Error + 'static)> {
88match self {
89 Error::Transcript(e) => Some(e),
90_ => None,
91 }
92 }
93}