1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! This module implements the [`ProverError`] type.

use crate::circuits::lookup::index::LookupError; // not sure about hierarchy
use poly_commitment::error::CommitmentError;
use thiserror::Error;

/// Errors that can arise when creating a proof
// TODO(mimoo): move this out of oracle
#[derive(Error, Debug, Clone, Copy)]
pub enum ProverError {
    #[error("the circuit is too large")]
    NoRoomForZkInWitness,

    #[error(
        "there are not enough random rows to achieve zero-knowledge (expected: {0}, got: {1})"
    )]
    NotZeroKnowledge(usize, usize),

    #[error("the witness columns are not all the same size")]
    WitnessCsInconsistent,

    #[error("the proof could not be constructed: {0}")]
    Prover(&'static str),

    #[error("the permutation was not constructed correctly: {0}")]
    Permutation(&'static str),

    #[error("the lookup failed to find a match in the table: row={0}")]
    ValueNotInTable(usize),

    #[error("the runtime tables provided did not match the index's configuration")]
    RuntimeTablesInconsistent,

    #[error("wrong number of custom blinders given: {0}")]
    WrongBlinders(CommitmentError),
}

/// Errors that can arise when verifying a proof
#[derive(Error, Debug, Clone, Copy)]
pub enum VerifyError {
    #[error("the commitment to {0} is of an unexpected size (expected {1}, got {2})")]
    IncorrectCommitmentLength(&'static str, usize, usize),

    #[error("the public input is of an unexpected size (expected {0})")]
    IncorrectPubicInputLength(usize),

    #[error("the previous challenges have an unexpected length (expected {0}, got {1})")]
    IncorrectPrevChallengesLength(usize, usize),

    #[error(
        "proof malformed: an evaluation for {2} was of the incorrect size (expected {0}, got {1})"
    )]
    IncorrectEvaluationsLength(usize, usize, &'static str),

    #[error("the opening proof failed to verify")]
    OpenProof,

    #[error("lookup used in circuit, but proof is missing lookup commitments")]
    LookupCommitmentMissing,

    #[error("lookup used in circuit, but proof is missing lookup evaluations")]
    LookupEvalsMissing,

    #[error("lookup used in circuit, but proof has inconsistent number of lookup evaluations and commitments")]
    ProofInconsistentLookup,

    #[error("cannot batch proofs using different SRSes")]
    DifferentSRS,

    #[error("SRS size is smaller than the domain size required by the circuit")]
    SRSTooSmall,

    #[error("runtime tables are used, but missing from the proof")]
    IncorrectRuntimeProof,

    #[error("the evaluation for {0:?} is missing")]
    MissingEvaluation(crate::circuits::berkeley_columns::Column),

    #[error("the evaluation for PublicInput is missing")]
    MissingPublicInputEvaluation,

    #[error("the commitment for {0:?} is missing")]
    MissingCommitment(crate::circuits::berkeley_columns::Column),
}

/// Errors that can arise when preparing the setup
#[derive(Error, Debug, Clone)]
pub enum DomainCreationError {
    #[error("could not compute the size of domain for {0}")]
    DomainSizeFailed(usize),

    #[error("construction of domain {0} for size {1} failed")]
    DomainConstructionFailed(String, usize),
}

/// Errors that can arise when preparing the setup
#[derive(Error, Debug, Clone)]
pub enum SetupError {
    #[error("the domain could not be constructed: {0}")]
    ConstraintSystem(String),

    #[error("the domain could not be constructed: {0}")]
    DomainCreation(DomainCreationError),

    #[error("the lookup constraint system cannot not be constructed: {0}")]
    LookupCreation(LookupError),
}

/// Errors that can arise when creating a verifier index
#[derive(Error, Debug, Clone)]
pub enum VerifierIndexError {
    #[error("srs has already been set")]
    SRSHasBeenSet,
}