halo2_proofs/plonk/
error.rs

1use std::cmp;
2use std::error;
3use std::fmt;
4use std::io;
5
6use super::{Any, Column};
7
8/// 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.
14    Synthesis,
15    /// The provided instances do not match the circuit parameters.
16    InvalidInstances,
17    /// The constraint system is not satisfied.
18    ConstraintSystemFailure,
19    /// Out of bounds index passed to a backend
20    BoundsFailure,
21    /// Opening error
22    Opening,
23    /// Transcript error
24    Transcript(io::Error),
25    /// `k` is too small for the given circuit.
26    NotEnoughRowsAvailable {
27        /// The current value of `k` being used.
28        current_k: u32,
29    },
30    /// Instance provided exceeds number of available rows
31    InstanceTooLarge,
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
36    NotEnoughColumnsForConstants,
37    /// The instance sets up a copy constraint involving a column that has not been
38    /// included in the permutation.
39    ColumnNotInPermutation(Column<Any>),
40}
41
42impl From<io::Error> for Error {
43    fn from(error: io::Error) -> Self {
44        // The only place we can get io::Error from is the transcript.
45        Error::Transcript(error)
46    }
47}
48
49impl Error {
50    /// Constructs an `Error::NotEnoughRowsAvailable`.
51    pub(crate) fn not_enough_rows_available(current_k: u32) -> Self {
52        Error::NotEnoughRowsAvailable { current_k }
53    }
54}
55
56impl fmt::Display for Error {
57    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58        match 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 => {
72                write!(
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}
85
86impl error::Error for Error {
87    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
88        match self {
89            Error::Transcript(e) => Some(e),
90            _ => None,
91        }
92    }
93}