gennaro_dkg/
error.rs

1use serde::{Deserialize, Serialize};
2use thiserror::Error as DError;
3
4/// Errors produced by the gennaro DKG
5#[derive(DError, Debug)]
6pub enum Error {
7    /// Format errors
8    #[error("fmt error")]
9    FmtError(#[from] std::fmt::Error),
10    /// Io errors
11    #[error("io error")]
12    IoError(#[from] std::io::Error),
13    /// Verifiable secret sharing scheme errors
14    #[error("vsss error")]
15    VsssError(vsss_rs::Error),
16    /// Errors during secret_participant initialization
17    #[error("error during secret_participant creation: {0}")]
18    InitializationError(String),
19    /// Errors using rounds
20    #[error("round {0} invalid input: `{1}`")]
21    RoundError(usize, String),
22}
23
24impl From<vsss_rs::Error> for Error {
25    fn from(value: vsss_rs::Error) -> Self {
26        Self::VsssError(value)
27    }
28}
29
30/// Dkg results
31pub type DkgResult<T> = anyhow::Result<T, Error>;
32
33/// Detailed errors to describe problems that occurred with specific participants
34#[derive(DError, Debug, Deserialize, Serialize)]
35pub enum ParticipantError {
36    /// Round 2 - didn't receive any p2p data from secret_participant
37    #[error("secret_participant {0} has broadcast data but no peer-to-peer data")]
38    MissingP2PData(usize),
39    /// Round 2 - didn't receive any broadcast data from secret_participant
40    #[error("secret_participant {0} has peer-to-peer data but no broadcast data")]
41    MissingBroadcastData(usize),
42    /// Participant is using different parameters than expected
43    #[error("secret_participant {0} is using the different parameters than expected")]
44    MismatchedParameters(usize),
45    /// Participant has identity elements for pedersen commitments
46    #[error("secret_participant {0} has identity element pedersen commitments")]
47    IdentityElementPedersenCommitments(usize),
48    /// Participant has zero value shares
49    #[error("secret_participant {0} has zero value shares")]
50    ZeroValueShares(usize),
51    /// Participant's shares do not verify with the given commitments
52    #[error("secret_participant {0} has shares that do not verify with the given commitments")]
53    NoVerifyShares(usize),
54    /// Participant's shares are not valid field elements
55    #[error("secret_participant {0} has shares that are not in the field")]
56    BadFormatShare(usize),
57    /// Received data from a secret_participant not in the valid set
58    #[error("broadcast data for secret_participant {0} is not expected")]
59    UnexpectedBroadcast(usize),
60    /// Received data from a secret_participant in the valid set but has not peer-to-peer data from round 1
61    #[error("secret_participant {0} is missing peer-to-peer data from round 1")]
62    MissingP2PDataRound1(usize),
63    /// Received data from a secret_participant in the valid set but has not broadcast data from round 1
64    #[error("secret_participant {0} is missing broadcast data from round 1")]
65    MissingBroadcastDataRound1(usize),
66    /// Participant has identity elements for feldman commitments
67    #[error("secret_participant {0} has identity element feldman commitments")]
68    IdentityElementFeldmanCommitments(usize),
69}