kimchi/
error.rs

1//! This module implements the [`ProverError`] type.
2
3use crate::circuits::lookup::index::LookupError; // not sure about hierarchy
4use o1_utils::lazy_cache::{LazyCacheError, LazyCacheErrorOr};
5use poly_commitment::error::CommitmentError;
6use thiserror::Error;
7
8/// Errors that can arise when creating a proof
9// TODO(mimoo): move this out of oracle
10#[derive(Error, Debug, Clone)]
11pub enum ProverError {
12    #[error("the circuit is too large")]
13    NoRoomForZkInWitness,
14
15    #[error(
16        "there are not enough random rows to achieve zero-knowledge (expected: {0}, got: {1})"
17    )]
18    NotZeroKnowledge(usize, usize),
19
20    #[error("the witness columns are not all the same size")]
21    WitnessCsInconsistent,
22
23    #[error("the proof could not be constructed: {0}")]
24    Prover(&'static str),
25
26    #[error("the permutation was not constructed correctly: {0}")]
27    Permutation(&'static str),
28
29    #[error("the lookup failed to find a match in the table: row={0}")]
30    ValueNotInTable(usize),
31
32    #[error("the runtime tables provided did not match the index's configuration")]
33    RuntimeTablesInconsistent,
34
35    #[error("wrong number of custom blinders given: {0}")]
36    WrongBlinders(CommitmentError),
37
38    #[error("relation polynomials failed to initialize in lazy mode: {0}")]
39    LazySetup(SetupError),
40}
41
42/// Errors that can arise when verifying a proof
43#[derive(Error, Debug, Clone, Copy)]
44pub enum VerifyError {
45    #[error("the commitment to {0} is of an unexpected size (expected {1}, got {2})")]
46    IncorrectCommitmentLength(&'static str, usize, usize),
47
48    #[error("the public input is of an unexpected size (expected {0})")]
49    IncorrectPubicInputLength(usize),
50
51    #[error("the previous challenges have an unexpected length (expected {0}, got {1})")]
52    IncorrectPrevChallengesLength(usize, usize),
53
54    #[error(
55        "proof malformed: an evaluation for {2} was of the incorrect size (expected {0}, got {1})"
56    )]
57    IncorrectEvaluationsLength(usize, usize, &'static str),
58
59    #[error("the opening proof failed to verify")]
60    OpenProof,
61
62    #[error("lookup used in circuit, but proof is missing lookup commitments")]
63    LookupCommitmentMissing,
64
65    #[error("lookup used in circuit, but proof is missing lookup evaluations")]
66    LookupEvalsMissing,
67
68    #[error("lookup used in circuit, but proof has inconsistent number of lookup evaluations and commitments")]
69    ProofInconsistentLookup,
70
71    #[error("cannot batch proofs using different SRSes")]
72    DifferentSRS,
73
74    #[error("SRS size is smaller than the domain size required by the circuit")]
75    SRSTooSmall,
76
77    #[error("runtime tables are used, but missing from the proof")]
78    IncorrectRuntimeProof,
79
80    #[error("the evaluation for {0:?} is missing")]
81    MissingEvaluation(crate::circuits::berkeley_columns::Column),
82
83    #[error("the evaluation for PublicInput is missing")]
84    MissingPublicInputEvaluation,
85
86    #[error("the commitment for {0:?} is missing")]
87    MissingCommitment(crate::circuits::berkeley_columns::Column),
88}
89
90/// Errors that can arise when preparing the setup
91#[derive(Error, Debug, Clone)]
92pub enum DomainCreationError {
93    #[error("could not compute the size of domain for {0}")]
94    DomainSizeFailed(usize),
95
96    #[error("construction of domain {0} for size {1} failed")]
97    DomainConstructionFailed(String, usize),
98}
99
100/// Errors that can arise when preparing the setup
101#[derive(Error, Debug, Clone)]
102pub enum SetupError {
103    #[error("the domain could not be constructed: {0}")]
104    ConstraintSystem(String),
105
106    #[error("the domain could not be constructed: {0}")]
107    DomainCreation(DomainCreationError),
108
109    #[error("the lookup constraint system cannot not be constructed: {0}")]
110    LookupCreation(LookupError),
111
112    #[error("lazy evaluation failed")]
113    LazyEvaluation(LazyCacheError),
114}
115
116/// Errors that can arise when creating a verifier index
117#[derive(Error, Debug, Clone)]
118pub enum VerifierIndexError {
119    #[error("srs has already been set")]
120    SRSHasBeenSet,
121}
122
123// Handling of lookup errors happening inside creation of LookupConstraintSystem
124impl From<LazyCacheErrorOr<LookupError>> for SetupError {
125    fn from(e: LazyCacheErrorOr<LookupError>) -> Self {
126        match e {
127            LazyCacheErrorOr::Inner(inner) => SetupError::LookupCreation(inner.clone()),
128            LazyCacheErrorOr::Outer(err) => SetupError::LazyEvaluation(err),
129        }
130    }
131}
132
133impl From<LazyCacheErrorOr<LookupError>> for ProverError {
134    fn from(e: LazyCacheErrorOr<LookupError>) -> Self {
135        ProverError::LazySetup(SetupError::from(e))
136    }
137}