tlsn_prover/
error.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use std::{error::Error, fmt};
use tls_mpc::MpcTlsError;

/// Error for [`Prover`](crate::Prover).
#[derive(Debug, thiserror::Error)]
pub struct ProverError {
    kind: ErrorKind,
    source: Option<Box<dyn Error + Send + Sync + 'static>>,
}

impl ProverError {
    fn new<E>(kind: ErrorKind, source: E) -> Self
    where
        E: Into<Box<dyn Error + Send + Sync + 'static>>,
    {
        Self {
            kind,
            source: Some(source.into()),
        }
    }

    pub(crate) fn config<E>(source: E) -> Self
    where
        E: Into<Box<dyn Error + Send + Sync + 'static>>,
    {
        Self::new(ErrorKind::Config, source)
    }

    pub(crate) fn attestation<E>(source: E) -> Self
    where
        E: Into<Box<dyn Error + Send + Sync + 'static>>,
    {
        Self::new(ErrorKind::Attestation, source)
    }
}

#[derive(Debug)]
enum ErrorKind {
    Io,
    Mpc,
    Config,
    Attestation,
}

impl fmt::Display for ProverError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.write_str("prover error: ")?;

        match self.kind {
            ErrorKind::Io => f.write_str("io error")?,
            ErrorKind::Mpc => f.write_str("mpc error")?,
            ErrorKind::Config => f.write_str("config error")?,
            ErrorKind::Attestation => f.write_str("attestation error")?,
        }

        if let Some(source) = &self.source {
            write!(f, " caused by: {}", source)?;
        }

        Ok(())
    }
}

impl From<std::io::Error> for ProverError {
    fn from(e: std::io::Error) -> Self {
        Self::new(ErrorKind::Io, e)
    }
}

impl From<tls_client_async::ConnectionError> for ProverError {
    fn from(e: tls_client_async::ConnectionError) -> Self {
        Self::new(ErrorKind::Io, e)
    }
}

impl From<uid_mux::yamux::ConnectionError> for ProverError {
    fn from(e: uid_mux::yamux::ConnectionError) -> Self {
        Self::new(ErrorKind::Io, e)
    }
}

impl From<mpz_common::ContextError> for ProverError {
    fn from(e: mpz_common::ContextError) -> Self {
        Self::new(ErrorKind::Mpc, e)
    }
}

impl From<MpcTlsError> for ProverError {
    fn from(e: MpcTlsError) -> Self {
        Self::new(ErrorKind::Mpc, e)
    }
}

impl From<mpz_ot::OTError> for ProverError {
    fn from(e: mpz_ot::OTError) -> Self {
        Self::new(ErrorKind::Mpc, e)
    }
}

impl From<mpz_ot::kos::SenderError> for ProverError {
    fn from(e: mpz_ot::kos::SenderError) -> Self {
        Self::new(ErrorKind::Mpc, e)
    }
}

impl From<mpz_ole::OLEError> for ProverError {
    fn from(e: mpz_ole::OLEError) -> Self {
        Self::new(ErrorKind::Mpc, e)
    }
}

impl From<mpz_ot::kos::ReceiverError> for ProverError {
    fn from(e: mpz_ot::kos::ReceiverError) -> Self {
        Self::new(ErrorKind::Mpc, e)
    }
}

impl From<mpz_garble::VmError> for ProverError {
    fn from(e: mpz_garble::VmError) -> Self {
        Self::new(ErrorKind::Mpc, e)
    }
}

impl From<mpz_garble::protocol::deap::DEAPError> for ProverError {
    fn from(e: mpz_garble::protocol::deap::DEAPError) -> Self {
        Self::new(ErrorKind::Mpc, e)
    }
}

impl From<mpz_garble::MemoryError> for ProverError {
    fn from(e: mpz_garble::MemoryError) -> Self {
        Self::new(ErrorKind::Mpc, e)
    }
}

impl From<mpz_garble::ProveError> for ProverError {
    fn from(e: mpz_garble::ProveError) -> Self {
        Self::new(ErrorKind::Mpc, e)
    }
}