mpc_stark/error.rs
1//! Errors defined across the MPC implementation
2use std::{error::Error, fmt::Display};
3
4use quinn::{ConnectError, ConnectionError};
5
6/// An application level error that results from an error deeper in the MPC stack
7#[derive(Clone, Debug, PartialEq, Eq)]
8pub enum MpcError {
9 /// An error on the network
10 NetworkError(MpcNetworkError),
11 /// An error authenticating an MPC value
12 AuthenticationError,
13 /// An error resulting from visibility mismatch between two values
14 VisibilityError(String),
15 /// An error performing an arithmetic operation
16 ArithmeticError(String),
17}
18
19impl Display for MpcError {
20 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21 write!(f, "{:?}", self)
22 }
23}
24impl Error for MpcError {}
25
26/// An error on the MPC network during communication
27#[derive(Clone, Debug, PartialEq, Eq)]
28pub enum MpcNetworkError {
29 /// An error sending a value to the counterparty
30 SendError(String),
31 /// An error receiving a value from the counterparty
32 RecvError(String),
33 /// An error setting up the underlying connection
34 ConnectionSetupError(SetupError),
35 /// An error tearing down the underlying connection
36 ConnectionTeardownError,
37 /// An error emitted when a network operation is performed on a network
38 /// that has not yet been `connect`ed
39 NetworkUninitialized,
40 /// An error serializing a value
41 SerializationError(String),
42}
43
44impl Display for MpcNetworkError {
45 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 write!(f, "{:?}", self)
47 }
48}
49impl Error for MpcNetworkError {}
50
51/// An error setting up the MPC fabric
52#[derive(Clone, Debug, PartialEq, Eq)]
53pub enum SetupError {
54 /// An error connecting to the peer
55 ConnectError(ConnectError),
56 /// An error with the connection after initial setup
57 ConnectionError(ConnectionError),
58 /// An error setting up the TLS certificate
59 KeygenError,
60 /// An error emitted when there is no inbound connection attempt from the suggested peer
61 NoIncomingConnection,
62 /// An error setting up the QUIC server on the local node
63 ServerSetupError,
64}