jf_pcs/
errors.rs

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
// Copyright (c) 2022 Espresso Systems (espressosys.com)
// This file is part of the Jellyfish library.

// You should have received a copy of the MIT License
// along with the Jellyfish library. If not, see <https://mit-license.org/>.

//! Error module.

use super::transcript::TranscriptError;
use ark_serialize::SerializationError;
use ark_std::string::String;
use displaydoc::Display;
#[cfg(feature = "icicle")]
use icicle_core::error::IcicleError;
#[cfg(feature = "icicle")]
use icicle_cuda_runtime::error::CudaError;

/// A `enum` specifying the possible failure modes of the PCS.
#[derive(Display, Debug)]
pub enum PCSError {
    /// Invalid Prover: {0}
    InvalidProver(String),
    /// Invalid Verifier: {0}
    InvalidVerifier(String),
    /// Invalid Proof: {0}
    InvalidProof(String),
    /// Invalid parameters: {0}
    InvalidParameters(String),
    /// An error during (de)serialization: {0}
    SerializationError(SerializationError),
    /// Transcript error {0}
    TranscriptError(TranscriptError),
    /// Error from upstream dependencies: {0}
    UpstreamError(String),
    #[cfg(feature = "icicle")]
    /// Error from ICICLE: {0}
    IcicleError(String),
}

impl ark_std::error::Error for PCSError {}

impl From<SerializationError> for PCSError {
    fn from(e: ark_serialize::SerializationError) -> Self {
        Self::SerializationError(e)
    }
}

impl From<TranscriptError> for PCSError {
    fn from(e: TranscriptError) -> Self {
        Self::TranscriptError(e)
    }
}

#[cfg(feature = "icicle")]
impl From<IcicleError> for PCSError {
    fn from(e: IcicleError) -> Self {
        Self::IcicleError(ark_std::format!("{:?}", e))
    }
}
#[cfg(feature = "icicle")]
impl From<CudaError> for PCSError {
    fn from(e: CudaError) -> Self {
        let icicle_err = IcicleError::from_cuda_error(e);
        icicle_err.into()
    }
}