Skip to main content

wsts/
errors.rs

1use aes_gcm::Error as AesGcmError;
2use core::num::TryFromIntError;
3use elliptic_curve::Error as EllipticCurveError;
4use serde::{Deserialize, Serialize};
5use thiserror::Error;
6
7use crate::curve::{point::Error as PointError, scalar::Scalar};
8
9#[derive(Error, Debug, Clone, Serialize, Deserialize, PartialEq)]
10/// Errors which can happen during distributed key generation
11pub enum DkgError {
12    #[error("missing public shares from {0:?}")]
13    /// The public shares which were missing
14    MissingPublicShares(Vec<u32>),
15    #[error("missing private shares for/from {0:?}")]
16    /// The private shares which were missing
17    MissingPrivateShares(Vec<(u32, u32)>),
18    #[error("bad public shares {0:?}")]
19    /// The public shares that failed to verify or were the wrong size
20    BadPublicShares(Vec<u32>),
21    #[error("bad private shares {0:?}")]
22    /// The private shares which failed to verify
23    BadPrivateShares(Vec<u32>),
24    #[error("point error {0:?}")]
25    /// An error during point operations
26    Point(#[from] PointError),
27    #[error("integer conversion error")]
28    /// An error during integer conversion operations
29    TryFromInt,
30}
31
32impl From<TryFromIntError> for DkgError {
33    fn from(_e: TryFromIntError) -> Self {
34        Self::TryFromInt
35    }
36}
37
38#[derive(Error, Debug, Clone, Serialize, Deserialize, PartialEq)]
39/// Errors which can happen during signature aggregation
40pub enum AggregatorError {
41    #[error("bad poly commitments {0:?}")]
42    /// The polynomial commitments which failed verification or were the wrong size
43    BadPolyCommitments(Vec<Scalar>),
44    #[error("bad nonce length (expected {0} got {1}")]
45    /// The nonce length was the wrong size
46    BadNonceLen(usize, usize),
47    #[error("bad party keys from {0:?}")]
48    /// The party public keys which failed
49    BadPartyKeys(Vec<u32>),
50    #[error("bad party sigs from {0:?}")]
51    /// The party signatures which failed to verify
52    BadPartySigs(Vec<u32>),
53    #[error("bad group sig")]
54    /// The aggregate group signature failed to verify
55    BadGroupSig,
56    #[error("integer conversion error")]
57    /// An error during integer conversion operations
58    TryFromInt,
59}
60
61impl From<TryFromIntError> for AggregatorError {
62    fn from(_e: TryFromIntError) -> Self {
63        Self::TryFromInt
64    }
65}
66
67#[derive(Error, Debug, Clone, PartialEq)]
68/// Errors which can happen during encryption
69pub enum EncryptionError {
70    #[error("AES nonce was missing from the buffer")]
71    /// AES nonce was missing from the buffer
72    MissingNonce,
73    #[error("AES data was missing from the buffer")]
74    /// AES data was missing from the buffer
75    MissingData,
76    #[error("AES GCM error {0:?}")]
77    /// Wrapped aes_gcm::Error, an opaque type
78    AesGcm(AesGcmError),
79    /// Wrapped elliptic_curve::Error
80    #[error("Elliptic curve error {0:?}")]
81    EllipticCurveError(EllipticCurveError),
82}
83
84impl From<AesGcmError> for EncryptionError {
85    fn from(e: AesGcmError) -> Self {
86        Self::AesGcm(e)
87    }
88}
89
90impl From<EllipticCurveError> for EncryptionError {
91    fn from(e: EllipticCurveError) -> Self {
92        Self::EllipticCurveError(e)
93    }
94}