Skip to main content

hopr_protocol_pix/
errors.rs

1use crate::SsaIndex;
2
3/// List of all errors that can occur in the PIX protocol.
4#[derive(Debug, thiserror::Error)]
5pub enum PixError<P: std::fmt::Display> {
6    #[error("invalid input to the function")]
7    InvalidInput,
8    #[error("invalid configuration: {0}")]
9    InvalidConfiguration(#[from] validator::ValidationErrors),
10    #[error("acknowledgement from this peer is not paired to any encrypted share")]
11    UnexpectedShare,
12    /// No longer produced by the reconstructor: a share failing verification is expected adversarial
13    /// input rather than a fault in the call, and the caller needs the cycle's running fault total
14    /// along with it — which an error cannot carry without becoming a telemetry channel. It surfaces
15    /// as [`ShareResolution::InvalidShares`](crate::ShareResolution::InvalidShares) instead.
16    ///
17    /// Retained because it is what makes [`PixError`] generic over the pseudonym; dropping the
18    /// parameter touches every signature in the crate and is its own change.
19    #[error("received an ssa share from pseudonym {0} #{1} that could not be verified")]
20    InvalidShare(P, SsaIndex),
21    #[error("encrypted partial ssa share is empty")]
22    ShareIsEmpty,
23    /// The share was dropped rather than buffered: the reconstructor is already holding
24    /// `max_ack_buffer_bytes` worth of shares awaiting acknowledgement.
25    ///
26    /// Deliberately *not* an expected error. Reaching it means share loss — the Exit has put a
27    /// packet on the wire whose acknowledgement will now find nothing — so it should be as loud as
28    /// the caller's log level allows.
29    #[error("awaiting-acknowledgement buffer is at its configured byte budget; share dropped")]
30    AckBufferFull,
31    #[error("ssa commitment does not match ssa")]
32    InvalidSsa,
33    #[error("received duplicate commitment")]
34    DuplicateCommitment,
35    #[error("missing commitment for building ssa")]
36    MissingSsaCommitment,
37    #[error(
38        "client ssa commitment is not accompanied by a valid proof of knowledge of its discrete logarithm — the \
39         sender may be attempting to make the deposit key recoverable by itself alone"
40    )]
41    UnprovenSsaCommitment,
42    #[error("ssa index will overflow")]
43    SsaIndexOverflow,
44    #[error("crypto error: {0}")]
45    CryptoError(#[from] hopr_types::crypto::errors::CryptoError),
46    #[error("ecc calculation error: {0}")]
47    EccError(#[from] vsss_rs::elliptic_curve::Error),
48    #[error("secret sharing error: {0}")]
49    VsssError(vsss_rs::Error),
50}
51
52impl<P: std::fmt::Display> From<vsss_rs::Error> for PixError<P> {
53    fn from(err: vsss_rs::Error) -> Self {
54        PixError::VsssError(err)
55    }
56}
57
58pub type Result<T, P> = std::result::Result<T, PixError<P>>;