winter_fri/
errors.rs

1// Copyright (c) Facebook, Inc. and its affiliates.
2//
3// This source code is licensed under the MIT license found in the
4// LICENSE file in the root directory of this source tree.
5
6use core::fmt;
7
8use crypto::RandomCoinError;
9
10// VERIFIER ERROR
11// ================================================================================================
12
13/// Defines errors which can occur during FRI proof verification.
14#[derive(Debug, Clone, PartialEq, Eq)]
15pub enum VerifierError {
16    /// Attempt to draw a random value from a public coin failed.
17    RandomCoinError(RandomCoinError),
18    /// Folding factor specified for the protocol is not supported. Currently, supported folding
19    /// factors are: 4, 8, and 16.
20    UnsupportedFoldingFactor(usize),
21    /// Number of query positions does not match the number of provided evaluations.
22    NumPositionEvaluationMismatch(usize, usize),
23    /// Evaluations at queried positions did not match layer commitment made by the prover.
24    LayerCommitmentMismatch,
25    /// Degree-respecting projection was not performed correctly at one of the layers.
26    InvalidLayerFolding(usize),
27    /// FRI remainder did not match the commitment.
28    RemainderCommitmentMismatch,
29    /// Degree-respecting projection was not performed correctly at the last layer.
30    InvalidRemainderFolding,
31    /// FRI remainder expected degree is greater than number of remainder values.
32    RemainderDegreeNotValid,
33    /// FRI remainder degree is greater than the polynomial degree expected for the last layer.
34    RemainderDegreeMismatch(usize),
35    /// Polynomial degree at one of the FRI layers could not be divided evenly by the folding
36    /// factor.
37    DegreeTruncation(usize, usize, usize),
38}
39
40impl fmt::Display for VerifierError {
41    #[rustfmt::skip]
42    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43        match self {
44            Self::RandomCoinError(err) => {
45                write!(f, "failed to draw a random value from the public coin: {err}")
46            }
47            Self::UnsupportedFoldingFactor(value) => {
48                write!(f, "folding factor {value} is not currently supported")
49            }
50            Self::NumPositionEvaluationMismatch(num_positions, num_evaluations) => write!(f,
51                "the number of query positions must be the same as the number of polynomial evaluations, but {num_positions} and {num_evaluations} were provided"
52            ),
53            Self::LayerCommitmentMismatch => {
54                write!(f, "FRI queries did not match layer commitment made by the prover")
55            }
56            Self::InvalidLayerFolding(layer) => {
57                write!(f, "degree-respecting projection is not consistent at layer {layer}")
58            }
59            Self::RemainderCommitmentMismatch => {
60                write!(f, "FRI remainder did not match the commitment")
61            }
62            Self::InvalidRemainderFolding => {
63                write!(f, "degree-respecting projection is inconsistent at the last FRI layer")
64            }
65            Self::RemainderDegreeNotValid => {
66                write!(f, "FRI remainder expected degree is greater than number of remainder values")
67            }
68            Self::RemainderDegreeMismatch(degree) => {
69                write!(f, "FRI remainder is not a valid degree {degree} polynomial")
70            }
71            Self::DegreeTruncation(degree, folding, layer) => {
72                write!(f, "degree reduction from {degree} by {folding} at layer {layer} results in degree truncation")
73            }
74        }
75    }
76}
77
78impl core::error::Error for VerifierError {}