fullcodec_plonk/error.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4//
5// Copyright (c) DUSK NETWORK. All rights reserved.
6
7//! A collection of all possible errors encountered in PLONK.
8
9use dusk_bytes::Error as DuskBytesError;
10
11/// Defines all possible errors that can be encountered in PLONK.
12#[derive(core::fmt::Debug)]
13pub enum Error {
14 // FFT errors
15 /// This error occurs when an error triggers on any of the fft module
16 /// functions.
17 InvalidEvalDomainSize {
18 /// Log size of the group
19 log_size_of_group: u32,
20 /// Two adacity generated
21 adacity: u32,
22 },
23
24 // Prover/Verifier errors
25 /// This error occurs when a proof verification fails.
26 ProofVerificationError,
27 /// This error occurs when the circuit is not provided with all of the
28 /// required inputs.
29 CircuitInputsNotFound,
30 /// This error occurs when we want to verify a Proof but the pi_constructor
31 /// attribute is uninitialized.
32 UninitializedPIGenerator,
33 /// PublicInput serialization error
34 InvalidPublicInputBytes,
35 /// This error occurs when the Prover structure already contains a
36 /// preprocessed circuit inside, but you call preprocess again.
37 CircuitAlreadyPreprocessed,
38
39 // Preprocessing errors
40 /// This error occurs when an error triggers during the preprocessing
41 /// stage.
42 MismatchedPolyLen,
43
44 // KZG10 errors
45 /// This error occurs when the user tries to create PublicParameters
46 /// and supplies the max degree as zero.
47 DegreeIsZero,
48 /// This error occurs when the user tries to trim PublicParameters
49 /// to a degree that is larger than the maximum degree.
50 TruncatedDegreeTooLarge,
51 /// This error occurs when the user tries to trim PublicParameters
52 /// down to a degree that is zero.
53 TruncatedDegreeIsZero,
54 /// This error occurs when the user tries to commit to a polynomial whose
55 /// degree is larger than the supported degree for that proving key.
56 PolynomialDegreeTooLarge,
57 /// This error occurs when the user tries to commit to a polynomial whose
58 /// degree is zero.
59 PolynomialDegreeIsZero,
60 /// This error occurs when the pairing check fails at being equal to the
61 /// Identity point.
62 PairingCheckFailure,
63
64 // Serialization errors
65 /// Dusk-bytes serialization error
66 BytesError(DuskBytesError),
67 /// This error occurs when there are not enough bytes to read out of a
68 /// slice during deserialization.
69 NotEnoughBytes,
70 /// This error occurs when a malformed point is decoded from a byte array.
71 PointMalformed,
72 /// This error occurs when a malformed BLS scalar is decoded from a byte
73 /// array.
74 BlsScalarMalformed,
75
76 // Plonkup errors
77 /// Query element not found in lookup table
78 ElementNotIndexed,
79 /// Cannot commit to table column polynomial
80 TablePreProcessingError,
81}
82
83#[cfg(feature = "std")]
84impl std::fmt::Display for Error {
85 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86 match self {
87 Self::InvalidEvalDomainSize {
88 log_size_of_group,
89 adacity,
90 } => write!(
91 f,
92 "Log-size of the EvaluationDomain group > TWO_ADACITY\
93 Size: {:?} > TWO_ADACITY = {:?}",
94 log_size_of_group, adacity
95 ),
96 Self::ProofVerificationError => {
97 write!(f, "proof verification failed")
98 }
99 Self::CircuitInputsNotFound => {
100 write!(f, "circuit inputs not found")
101 }
102 Self::UninitializedPIGenerator => {
103 write!(f, "PI generator uninitialized")
104 }
105 Self::InvalidPublicInputBytes => {
106 write!(f, "invalid public input bytes")
107 }
108 Self::MismatchedPolyLen => {
109 write!(f, "the length of the wires is not the same")
110 }
111 Self::CircuitAlreadyPreprocessed => {
112 write!(f, "circuit has already been preprocessed")
113 }
114 Self::DegreeIsZero => {
115 write!(f, "cannot create PublicParameters with max degree 0")
116 }
117 Self::TruncatedDegreeTooLarge => {
118 write!(f, "cannot trim more than the maximum degree")
119 }
120 Self::TruncatedDegreeIsZero => write!(
121 f,
122 "cannot trim PublicParameters to a maximum size of zero"
123 ),
124 Self::PolynomialDegreeTooLarge => write!(
125 f,
126 "proving key is not large enough to commit to said polynomial"
127 ),
128 Self::PolynomialDegreeIsZero => {
129 write!(f, "cannot commit to polynomial of zero degree")
130 }
131 Self::PairingCheckFailure => write!(f, "pairing check failed"),
132 Self::NotEnoughBytes => write!(f, "not enough bytes left to read"),
133 Self::PointMalformed => write!(f, "BLS point bytes malformed"),
134 Self::BlsScalarMalformed => write!(f, "BLS scalar bytes malformed"),
135 Self::BytesError(err) => write!(f, "{:?}", err),
136 Self::ElementNotIndexed => write!(
137 f,
138 "the requested element was not indexed in the lookup table"
139 ),
140 Self::TablePreProcessingError => write!(
141 f,
142 "cannot commit to one of the table column polynomials"
143 ),
144 }
145 }
146}
147
148impl From<DuskBytesError> for Error {
149 fn from(bytes_err: DuskBytesError) -> Self {
150 Self::BytesError(bytes_err)
151 }
152}
153
154#[cfg(feature = "std")]
155impl std::error::Error for Error {}