snarkvm_algorithms/polycommit/
error.rs

1// Copyright 2024 Aleo Network Foundation
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16/// The error type for `PolynomialCommitment`.
17#[derive(Debug, Error)]
18pub enum PCError {
19    #[error("{0}")]
20    AnyhowError(#[from] anyhow::Error),
21
22    #[error("QuerySet` refers to polynomial \"{label}\", but it was not provided.")]
23    MissingPolynomial {
24        /// The label of the missing polynomial
25        label: String,
26    },
27
28    #[error("`QuerySet` refers to polynomial \"{label}\", but `Evaluations` does not contain an evaluation for it.")]
29    MissingEvaluation {
30        /// The label of the missing polynomial.
31        label: String,
32    },
33
34    #[error("The provided polynomial was meant to be hiding, but `rng` was `None`.")]
35    MissingRng,
36
37    #[error("The degree provided in setup was too small; degree 0 polynomials are not supported.")]
38    DegreeIsZero,
39
40    #[error(
41        "the number of coefficients in the polynomial ({num_coefficients:?}) is greater than \
42             the maximum number of powers in `Powers` ({num_powers:?})"
43    )]
44    TooManyCoefficients {
45        /// The number of coefficients in the polynomial.
46        num_coefficients: usize,
47        /// The maximum number of powers provided in `Powers`.
48        num_powers: usize,
49    },
50
51    #[error("The hiding bound was not `None`, but the hiding bound was zero.")]
52    HidingBoundIsZero,
53
54    #[error(
55        "the degree of the hiding poly ({hiding_poly_degree:?}) is not less than the maximum number of powers in `Powers` ({num_powers:?})"
56    )]
57    HidingBoundToolarge {
58        /// The hiding bound
59        hiding_poly_degree: usize,
60        /// The number of powers.
61        num_powers: usize,
62    },
63
64    #[error("The lagrange basis is not a power of two.")]
65    LagrangeBasisSizeIsNotPowerOfTwo,
66
67    #[error("The lagrange basis is larger than the supported degree.")]
68    LagrangeBasisSizeIsTooLarge,
69
70    #[error("The degree provided to `trim` was too large.")]
71    TrimmingDegreeTooLarge,
72
73    #[error("the equation \"{0}\" contained degree-bounded polynomials")]
74    EquationHasDegreeBounds(String),
75
76    #[error("the degree bound ({0}) is not supported by the parameters")]
77    UnsupportedDegreeBound(usize),
78
79    #[error("the Lagrange basis size ({0}) is not supported by the parameters")]
80    UnsupportedLagrangeBasisSize(usize),
81
82    #[error(
83        "the degree bound ({degree_bound}) for the polynomial {label} \
84        (having degree {poly_degree}) is greater than the maximum degree ({max_degree})"
85    )]
86    IncorrectDegreeBound {
87        /// Degree of the polynomial.
88        poly_degree: usize,
89        /// Degree bound.
90        degree_bound: usize,
91        /// Maximum degree.
92        max_degree: usize,
93        /// Index of the offending polynomial.
94        label: String,
95    },
96}