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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#[cfg(not(feature = "std"))]
use ark_std::string::String;
/// The error type for `PolynomialCommitment`.
#[derive(Debug)]
pub enum Error {
/// The query set contains a label for a polynomial that was not provided as
/// input to the `PC::open`.
MissingPolynomial {
/// The label of the missing polynomial.
label: String,
},
/// `Evaluations` does not contain an evaluation for the polynomial labelled
/// `label` at a particular query.
MissingEvaluation {
/// The label of the missing polynomial.
label: String,
},
/// The LHS of the equation is empty.
MissingLHS {
/// The label of the equation.
label: String,
},
/// The provided polynomial was meant to be hiding, but `rng` was `None`.
MissingRng,
/// The degree provided in setup was too small; degree 0 polynomials
/// are not supported.
DegreeIsZero,
/// The degree of the polynomial passed to `commit` or `open`
/// was too large.
TooManyCoefficients {
/// The number of coefficients in the polynomial.
num_coefficients: usize,
/// The maximum number of powers provided in `Powers`.
num_powers: usize,
},
/// The hiding bound was not `None`, but the hiding bound was zero.
HidingBoundIsZero,
/// The hiding bound was too large for the given `Powers`.
HidingBoundToolarge {
/// The hiding bound
hiding_poly_degree: usize,
/// The number of powers.
num_powers: usize,
},
/// The degree provided to `trim` was too large.
TrimmingDegreeTooLarge,
/// The provided `enforced_degree_bounds` was `Some<&[]>`.
EmptyDegreeBounds,
/// The provided equation contained multiple polynomials, of which least one
/// had a strict degree bound.
EquationHasDegreeBounds(String),
/// The required degree bound is not supported by ck/vk
UnsupportedDegreeBound(usize),
/// The degree bound for the `index`-th polynomial passed to `commit`, `open`
/// or `check` was incorrect, that is, `degree_bound >= poly_degree` or
/// `degree_bound <= max_degree`.
IncorrectDegreeBound {
/// Degree of the polynomial.
poly_degree: usize,
/// Degree bound.
degree_bound: usize,
/// Maximum supported degree.
supported_degree: usize,
/// Index of the offending polynomial.
label: String,
},
/// The inputs to `commit`, `open` or `verify` had incorrect lengths.
IncorrectInputLength(String),
/// An invalid number of variables was provided to `setup`
InvalidNumberOfVariables,
/// The degree of the `index`-th polynomial passed to `commit`, `open`
/// or `check` was incorrect, that is, `supported_degree <= poly_degree`
PolynomialDegreeTooLarge {
/// Degree of the polynomial.
poly_degree: usize,
/// Maximum supported degree.
supported_degree: usize,
/// Index of the offending polynomial.
label: String,
},
/// This means a failure in verifying the commitment or the opening.
InvalidCommitment,
/// This means during opening or verification, a commitment of incorrect
/// size (for example, with an insufficient number of entries) was
/// encountered
IncorrectCommitmentSize {
/// Encountered commitment size
encountered: usize,
/// Expected commitment size
expected: usize,
},
/// For PCS which rely on Fiat-Shamir to be rendered non-interactive,
/// these are errors that result from incorrect transcript manipulation.
TranscriptError,
/// This means the required soundness error bound is inherently impossible.
/// E.g., the field is not big enough.
InvalidParameters(String),
/// Error resulting from hashing in linear code - based PCS.
HashingError,
/// Shows that encoding is not feasible
EncodingError,
/// This means a commitment with a certain label was matched with a
/// a polynomial which has a different label - which shouldn't happen
MismatchedLabels {
/// The label of the commitment
commitment_label: String,
/// The label of the polynomial
polynomial_label: String,
},
/// This means multivariate polynomial with a certain number of variables
/// was matched (for instance, during commitment, opening or verification)
/// to a point with a different number of variables.
MismatchedNumVars {
/// The number of variables of the polynomial
poly_nv: usize,
/// The number of variables of the point
point_nv: usize,
},
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Error::MissingPolynomial { label } => write!(
f,
"`QuerySet` refers to polynomial \"{}\", but it was not provided.",
label
),
Error::MissingEvaluation { label } => write!(
f,
"`QuerySet` refers to polynomial \"{}\", but `Evaluations` does not contain an evaluation for it.",
label
),
Error::MissingLHS { label } => {
write!(f, "Equation \"{}\" does not have a LHS.", label)
},
Error::MissingRng => write!(f, "hiding commitments require `Some(rng)`"),
Error::DegreeIsZero => write!(
f,
"this scheme does not support committing to degree 0 polynomials"
),
Error::TooManyCoefficients {
num_coefficients,
num_powers,
} => write!(
f,
"the number of coefficients in the polynomial ({:?}) is greater than\
the maximum number of powers in `Powers` ({:?})",
num_coefficients, num_powers
),
Error::HidingBoundIsZero => write!(
f,
"this scheme does not support non-`None` hiding bounds that are 0"
),
Error::HidingBoundToolarge {
hiding_poly_degree,
num_powers,
} => write!(
f,
"the degree of the hiding poly ({:?}) is not less than the maximum number of powers in `Powers` ({:?})",
hiding_poly_degree, num_powers
),
Error::TrimmingDegreeTooLarge => {
write!(f, "the degree provided to `trim` was too large")
}
Error::EmptyDegreeBounds => {
write!(f, "provided `enforced_degree_bounds` was `Some<&[]>`")
}
Error::EquationHasDegreeBounds(e) => write!(
f,
"the eqaution \"{}\" contained degree-bounded polynomials",
e
),
Error::UnsupportedDegreeBound(bound) => write!(
f,
"the degree bound ({:?}) is not supported by the parameters",
bound,
),
Error::IncorrectDegreeBound {
poly_degree,
degree_bound,
supported_degree,
label,
} => write!(
f,
"the degree bound ({:?}) for the polynomial {} \
(having degree {:?}) is greater than the maximum \
supported degree ({:?})",
degree_bound, label, poly_degree, supported_degree
),
Error::InvalidNumberOfVariables => write!(
f,
"An invalid number of variables was provided to `setup`"
),
Error::PolynomialDegreeTooLarge {
poly_degree,
supported_degree,
label,
} => write!(
f,
"the polynomial {} has degree {:?}, but parameters only
support up to degree ({:?})", label, poly_degree, supported_degree
),
Error::IncorrectInputLength(err) => write!(f, "{}", err),
Error::InvalidCommitment => write!(f, "Failed to verify the commitment"),
Error::IncorrectCommitmentSize {
encountered,
expected,
} => write!(
f,
"the commitment has size {}, but size {} was expected",
encountered, expected
),
Error::TranscriptError => write!(f, "Incorrect transcript manipulation"),
Error::InvalidParameters(err) => write!(f, "{}", err),
Error::HashingError => write!(f, "Error resulting from hashing"),
Error::EncodingError => write!(f, "Encoding failed"),
Error::MismatchedLabels { commitment_label, polynomial_label } =>
write!(f, "Mismatched labels: commitment label: {}, polynomial label: {}",
commitment_label,
polynomial_label
),
Error::MismatchedNumVars { poly_nv, point_nv } =>
write!(f, "Mismatched number of variables: polynomial has {}, point has {}",
poly_nv,
point_nv,
),
}
}
}
impl ark_std::error::Error for Error {}