jf_pcs/
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 super::transcript::TranscriptError;
10use ark_serialize::SerializationError;
11use ark_std::string::String;
12use displaydoc::Display;
13#[cfg(feature = "icicle")]
14use icicle_core::error::IcicleError;
15#[cfg(feature = "icicle")]
16use icicle_cuda_runtime::error::CudaError;
17
18/// A `enum` specifying the possible failure modes of the PCS.
19#[derive(Display, Debug)]
20pub enum PCSError {
21    /// Invalid Prover: {0}
22    InvalidProver(String),
23    /// Invalid Verifier: {0}
24    InvalidVerifier(String),
25    /// Invalid Proof: {0}
26    InvalidProof(String),
27    /// Invalid parameters: {0}
28    InvalidParameters(String),
29    /// An error during (de)serialization: {0}
30    SerializationError(SerializationError),
31    /// Transcript error {0}
32    TranscriptError(TranscriptError),
33    /// Error from upstream dependencies: {0}
34    UpstreamError(String),
35    #[cfg(feature = "icicle")]
36    /// Error from ICICLE: {0}
37    IcicleError(String),
38}
39
40impl ark_std::error::Error for PCSError {}
41
42impl From<SerializationError> for PCSError {
43    fn from(e: ark_serialize::SerializationError) -> Self {
44        Self::SerializationError(e)
45    }
46}
47
48impl From<TranscriptError> for PCSError {
49    fn from(e: TranscriptError) -> Self {
50        Self::TranscriptError(e)
51    }
52}
53
54#[cfg(feature = "icicle")]
55impl From<IcicleError> for PCSError {
56    fn from(e: IcicleError) -> Self {
57        Self::IcicleError(ark_std::format!("{:?}", e))
58    }
59}
60#[cfg(feature = "icicle")]
61impl From<CudaError> for PCSError {
62    fn from(e: CudaError) -> Self {
63        let icicle_err = IcicleError::from_cuda_error(e);
64        icicle_err.into()
65    }
66}