dkg_core/primitives/errors.rs
1use thiserror::Error;
2use threshold_bls::{ecies::EciesError, poly, poly::Idx};
3
4/// Result type alias which returns `DKGError`
5pub type DKGResult<A> = Result<A, DKGError>;
6
7#[derive(Debug, Error)]
8/// Errors which may occur during the DKG
9pub enum DKGError {
10 /// PublicKeyNotFound is raised when the private key given to the DKG init
11 /// function does not yield a public key that is included in the group.
12 #[error("public key not found in list of participants")]
13 PublicKeyNotFound,
14
15 /// InvalidThreshold is raised when creating a group and specifying an
16 /// invalid threshold. Either the threshold is too low, inferior to
17 /// what `minimum_threshold()` returns or is too large (i.e. larger than the
18 /// number of nodes).
19 #[error("threshold {0} is not in range [{1},{2}]")]
20 InvalidThreshold(usize, usize, usize),
21
22 /// NotEnoughValidShares is raised when the DKG has not successfully
23 /// processed enough shares because they were invalid. In that case, the DKG
24 /// can not continue, the protocol MUST be aborted.
25 #[error("only has {0}/{1} valid shares, disqualified: {2:?}")]
26 NotEnoughValidShares(usize, usize, Vec<Idx>),
27
28 #[error("only has {0}/{1} required justifications, disqualified: {2:?}")]
29 NotEnoughJustifications(usize, usize, Vec<Idx>),
30
31 /// Rejected is raised when the participant is rejected from the final
32 /// output
33 #[error("this participant is rejected from the qualified set")]
34 Rejected,
35
36 /// BincodeError is raised when de(serialization) by bincode fails
37 #[error("de(serialization failed: {0})")]
38 BincodeError(#[from] bincode::Error),
39
40 /// ShareError is raised when a share is being processed
41 #[error(transparent)]
42 ShareError(#[from] ShareError),
43
44 /// NotDealer is raised when one attempts to call a method of a
45 /// dealer during a resharing when it is not a member of the current group.
46 #[error("this participant is not a dealer")]
47 NotDealer,
48
49 /// NotShareHolder is raised when one attemps to call a method of a share
50 /// holder during a resharing when it is a not a share holder in the new
51 /// group.
52 #[error("this participant is not a share holder")]
53 NotShareHolder,
54
55 #[error("invalid recovery during resharing: {0}")]
56 InvalidRecovery(#[from] poly::PolyError),
57}
58
59#[derive(Debug, Error)]
60#[allow(clippy::enum_variant_names)]
61/// Error which may occur while processing a share in Phase 1
62pub enum ShareError {
63 /// InvalidCipherText returns the error raised when decrypting the encrypted
64 /// share.
65 #[error("[dealer: {0}] Invalid ciphertext")]
66 InvalidCiphertext(Idx, EciesError),
67 /// InvalidShare is raised when the share does not corresponds to the public
68 /// polynomial associated.
69 #[error("[dealer: {0}] Share does not match associated public polynomial")]
70 InvalidShare(Idx),
71 /// InvalidPublicPolynomial is raised when the public polynomial does not
72 /// have the correct degree. Each public polynomial in the scheme must have
73 /// a degree equals to `threshold - 1` set for the DKG protocol.
74 /// The two fields are (1) the degree of the polynomial and (2) the
75 /// second is the degree it should be,i.e. `threshold - 1`.
76 #[error("[dealer: {0}] polynomial does not have the correct degree, got: {1}, expected {2}")]
77 InvalidPublicPolynomial(Idx, usize, usize),
78}