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
67impl From<EllipticCurveError> for EncryptionError {
68    fn from(e: EllipticCurveError) -> Self {
69        Self::EllipticCurveError(e)
70    }
71}
72
73#[derive(Error, Debug, Clone, PartialEq)]
74/// Errors which can happen during encryption
75pub enum EncryptionError {
76    #[error("AES nonce was missing from the buffer")]
77    /// AES nonce was missing from the buffer")]
78    MissingNonce,
79    #[error("AES data was missing from the buffer")]
80    /// AES data was missing from the buffer")]
81    MissingData,
82    #[error("AES GCM error {0:?}")]
83    /// Wrapped aes_gcm::Error, an opaque type
84    AesGcm(AesGcmError),
85    /// Wrapped elliptic_curve::Error
86    #[error("Elliptic curve error {0:?}")]
87    EllipticCurveError(EllipticCurveError),
88}
89
90impl From<AesGcmError> for EncryptionError {
91    fn from(e: AesGcmError) -> Self {
92        Self::AesGcm(e)
93    }
94}