ark_poly_commit/
error.rs

1#[cfg(not(feature = "std"))]
2use ark_std::string::String;
3
4/// The error type for `PolynomialCommitment`.
5#[derive(Debug)]
6pub enum Error {
7    /// The query set contains a label for a polynomial that was not provided as
8    /// input to the `PC::open`.
9    MissingPolynomial {
10        /// The label of the missing polynomial.
11        label: String,
12    },
13
14    /// `Evaluations` does not contain an evaluation for the polynomial labelled
15    /// `label` at a particular query.
16    MissingEvaluation {
17        /// The label of the missing polynomial.
18        label: String,
19    },
20
21    /// The LHS of the equation is empty.
22    MissingLHS {
23        /// The label of the equation.
24        label: String,
25    },
26
27    /// The provided polynomial was meant to be hiding, but `rng` was `None`.
28    MissingRng,
29
30    /// The degree provided in setup was too small; degree 0 polynomials
31    /// are not supported.
32    DegreeIsZero,
33
34    /// The degree of the polynomial passed to `commit` or `open`
35    /// was too large.
36    TooManyCoefficients {
37        /// The number of coefficients in the polynomial.
38        num_coefficients: usize,
39        /// The maximum number of powers provided in `Powers`.
40        num_powers: usize,
41    },
42
43    /// The hiding bound was not `None`, but the hiding bound was zero.
44    HidingBoundIsZero,
45
46    /// The hiding bound was too large for the given `Powers`.
47    HidingBoundToolarge {
48        /// The hiding bound
49        hiding_poly_degree: usize,
50        /// The number of powers.
51        num_powers: usize,
52    },
53
54    /// The degree provided to `trim` was too large.
55    TrimmingDegreeTooLarge,
56
57    /// The provided `enforced_degree_bounds` was `Some<&[]>`.
58    EmptyDegreeBounds,
59
60    /// The provided equation contained multiple polynomials, of which least one
61    /// had a strict degree bound.
62    EquationHasDegreeBounds(String),
63
64    /// The required degree bound is not supported by ck/vk
65    UnsupportedDegreeBound(usize),
66
67    /// The degree bound for the `index`-th polynomial passed to `commit`, `open`
68    /// or `check` was incorrect, that is, `degree_bound >= poly_degree` or
69    /// `degree_bound <= max_degree`.
70    IncorrectDegreeBound {
71        /// Degree of the polynomial.
72        poly_degree: usize,
73        /// Degree bound.
74        degree_bound: usize,
75        /// Maximum supported degree.
76        supported_degree: usize,
77        /// Index of the offending polynomial.
78        label: String,
79    },
80
81    /// The inputs to `commit`, `open` or `verify` had incorrect lengths.
82    IncorrectInputLength(String),
83
84    /// An invalid number of variables was provided to `setup`
85    InvalidNumberOfVariables,
86
87    /// The degree of the `index`-th polynomial passed to `commit`, `open`
88    /// or `check` was incorrect, that is, `supported_degree <= poly_degree`
89    PolynomialDegreeTooLarge {
90        /// Degree of the polynomial.
91        poly_degree: usize,
92        /// Maximum supported degree.
93        supported_degree: usize,
94        /// Index of the offending polynomial.
95        label: String,
96    },
97
98    /// This means a failure in verifying the commitment or the opening.
99    InvalidCommitment,
100
101    /// This means during opening or verification, a commitment of incorrect
102    /// size (for example, with an insufficient number of entries) was
103    /// encountered
104    IncorrectCommitmentSize {
105        /// Encountered commitment size
106        encountered: usize,
107        /// Expected commitment size
108        expected: usize,
109    },
110
111    /// For PCS which rely on Fiat-Shamir to be rendered non-interactive,
112    /// these are errors that result from incorrect transcript manipulation.
113    TranscriptError,
114
115    /// This means the required soundness error bound is inherently impossible.
116    /// E.g., the field is not big enough.
117    InvalidParameters(String),
118
119    /// Error resulting from hashing in linear code - based PCS.
120    HashingError,
121
122    /// Shows that encoding is not feasible
123    EncodingError,
124
125    /// This means a commitment with a certain label was matched with a
126    /// a polynomial which has a different label - which shouldn't happen
127    MismatchedLabels {
128        /// The label of the commitment
129        commitment_label: String,
130        /// The label of the polynomial
131        polynomial_label: String,
132    },
133
134    /// This means multivariate polynomial with a certain number of variables
135    /// was matched (for instance, during commitment, opening or verification)
136    /// to a point with a different number of variables.
137    MismatchedNumVars {
138        /// The number of variables of the polynomial
139        poly_nv: usize,
140        /// The number of variables of the point
141        point_nv: usize,
142    },
143}
144
145impl core::fmt::Display for Error {
146    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
147        match self {
148            Error::MissingPolynomial { label } => write!(
149                f,
150                "`QuerySet` refers to polynomial \"{}\", but it was not provided.",
151                label
152            ),
153            Error::MissingEvaluation { label } => write!(
154                f,
155                "`QuerySet` refers to polynomial \"{}\", but `Evaluations` does not contain an evaluation for it.",
156                label
157            ),
158            Error::MissingLHS { label } => {
159                write!(f, "Equation \"{}\" does not have a LHS.", label)
160            },
161            Error::MissingRng => write!(f, "hiding commitments require `Some(rng)`"),
162            Error::DegreeIsZero => write!(
163                f,
164                "this scheme does not support committing to degree 0 polynomials"
165            ),
166            Error::TooManyCoefficients {
167                num_coefficients,
168                num_powers,
169            } => write!(
170                f,
171                "the number of coefficients in the polynomial ({:?}) is greater than\
172                 the maximum number of powers in `Powers` ({:?})",
173                num_coefficients, num_powers
174            ),
175            Error::HidingBoundIsZero => write!(
176                f,
177                "this scheme does not support non-`None` hiding bounds that are 0"
178            ),
179            Error::HidingBoundToolarge {
180                hiding_poly_degree,
181                num_powers,
182            } => write!(
183                f,
184                "the degree of the hiding poly ({:?}) is not less than the maximum number of powers in `Powers` ({:?})",
185                hiding_poly_degree, num_powers
186            ),
187            Error::TrimmingDegreeTooLarge => {
188                write!(f, "the degree provided to `trim` was too large")
189            }
190            Error::EmptyDegreeBounds => {
191                write!(f, "provided `enforced_degree_bounds` was `Some<&[]>`")
192            }
193            Error::EquationHasDegreeBounds(e) => write!(
194                f,
195                "the eqaution \"{}\" contained degree-bounded polynomials",
196                e
197            ),
198            Error::UnsupportedDegreeBound(bound) => write!(
199                f,
200                "the degree bound ({:?}) is not supported by the parameters",
201                bound,
202            ),
203            Error::IncorrectDegreeBound {
204                poly_degree,
205                degree_bound,
206                supported_degree,
207                label,
208            } => write!(
209                f,
210                "the degree bound ({:?}) for the polynomial {} \
211                 (having degree {:?}) is greater than the maximum \
212                 supported degree ({:?})",
213                degree_bound, label, poly_degree, supported_degree
214            ),
215            Error::InvalidNumberOfVariables => write!(
216                f,
217                "An invalid number of variables was provided to `setup`"
218            ),
219            Error::PolynomialDegreeTooLarge {
220                poly_degree,
221                supported_degree,
222                label,
223            } => write!(
224                f,
225                "the polynomial {} has degree {:?}, but parameters only
226                support up to degree ({:?})", label, poly_degree, supported_degree
227            ),
228            Error::IncorrectInputLength(err) => write!(f, "{}", err),
229            Error::InvalidCommitment => write!(f, "Failed to verify the commitment"),
230            Error::IncorrectCommitmentSize {
231                encountered,
232                expected,
233            } => write!(
234                f,
235                "the commitment has size {}, but size {} was expected",
236                encountered, expected
237            ),
238            Error::TranscriptError => write!(f, "Incorrect transcript manipulation"),
239            Error::InvalidParameters(err) => write!(f, "{}", err),
240            Error::HashingError => write!(f, "Error resulting from hashing"),
241            Error::EncodingError => write!(f, "Encoding failed"),
242            Error::MismatchedLabels { commitment_label, polynomial_label } =>
243                write!(f, "Mismatched labels: commitment label: {}, polynomial label: {}",
244                    commitment_label,
245                    polynomial_label
246                ),
247            Error::MismatchedNumVars { poly_nv, point_nv } =>
248                write!(f, "Mismatched number of variables: polynomial has {}, point has {}",
249                    poly_nv,
250                    point_nv,
251                ),
252        }
253    }
254}
255
256impl ark_std::error::Error for Error {}