jf_plonk/
errors.rs

1// Copyright (c) 2022 Espresso Systems (espressosys.com)
2// This file is part of the Jellyfish library.
3
4// You should have received a copy of the MIT License
5// along with the Jellyfish library. If not, see <https://mit-license.org/>.
6
7//! Error module.
8
9use ark_std::{format, string::String};
10use displaydoc::Display;
11use jf_pcs::errors::PCSError;
12use jf_relation::CircuitError;
13
14/// A `enum` specifying the possible failure modes of the Plonk.
15#[derive(Display, Debug)]
16pub enum PlonkError {
17    /// The index is too large for the universal public parameters
18    IndexTooLarge,
19    /// Failed to create domain
20    DomainCreationError,
21    /// Failed to get array value by index
22    IndexError,
23    /// Divided by zero field element
24    DivisionError,
25    /// An error in the Plonk SNARK logic: {0}
26    SnarkError(SnarkError),
27    /// An error in the underlying polynomial commitment: {0}
28    PCSError(PCSError),
29    /// An error in the Plonk circuit: {0}
30    CircuitError(CircuitError),
31    /// An error during IO: {0}
32    IoError(ark_std::io::Error),
33    /// An error during (de)serialization
34    SerializationError(ark_serialize::SerializationError),
35    /// Plonk proof verification failed due to wrong proof
36    WrongProof,
37    /// Rescue Error
38    RescueError(jf_rescue::RescueError),
39    /// Invalid parameters
40    InvalidParameters(String),
41    /// Non-native field overflow
42    NonNativeFieldOverflow,
43    /// Iterator out of range
44    IteratorOutOfRange,
45    /// Public inputs for partial verification circuit do not match
46    PublicInputsDoNotMatch,
47}
48
49impl ark_std::error::Error for PlonkError {}
50
51impl From<PCSError> for PlonkError {
52    fn from(e: PCSError) -> Self {
53        Self::PCSError(e)
54    }
55}
56
57impl From<ark_std::io::Error> for PlonkError {
58    fn from(e: ark_std::io::Error) -> Self {
59        Self::IoError(e)
60    }
61}
62
63impl From<ark_serialize::SerializationError> for PlonkError {
64    fn from(e: ark_serialize::SerializationError) -> Self {
65        Self::SerializationError(e)
66    }
67}
68
69impl From<jf_rescue::RescueError> for PlonkError {
70    fn from(e: jf_rescue::RescueError) -> Self {
71        Self::RescueError(e)
72    }
73}
74
75/// A `enum` specifying the possible failure modes of the underlying SNARK.
76#[derive(Display, Debug)]
77pub enum SnarkError {
78    #[rustfmt::skip]
79    /// Suspect: circuit is not satisfied. The quotient polynomial has wrong degree: {0}, expected: {1}. 
80    WrongQuotientPolyDegree(usize, usize),
81    /// Invalid parameters: {0}
82    ParameterError(String),
83    /// The SNARK does not support lookup
84    SnarkLookupUnsupported,
85}
86
87#[cfg(feature = "std")]
88impl std::error::Error for SnarkError {}
89
90impl From<SnarkError> for PlonkError {
91    fn from(e: SnarkError) -> Self {
92        Self::SnarkError(e)
93    }
94}
95
96impl From<CircuitError> for PlonkError {
97    fn from(e: CircuitError) -> Self {
98        Self::CircuitError(e)
99    }
100}
101
102impl From<PlonkError> for CircuitError {
103    // this happen during invocation of Plonk proof system API inside Verifier
104    // gadget
105    fn from(e: PlonkError) -> Self {
106        Self::ParameterError(format!("Plonk proof system err: {e:?}"))
107    }
108}