confium_tc_cmp20/error.rs
1//! Error helpers for the CMP20 scheme crate.
2
3use confium_tc::error::Error as TcError;
4
5/// CMP20 sub-codes (0x60xx). Distinct from GG18's 0x50xx so callers can
6/// disambiguate the source scheme from a numeric code alone.
7#[allow(non_camel_case_types)]
8#[repr(u32)]
9pub enum Cmp20ErrorCode {
10 /// A share blob failed to deserialize or had the wrong magic / version.
11 /// Caller action: regenerate shares via DKG; the on-disk format may
12 /// have been corrupted or written by a different scheme.
13 BAD_SHARE = 0x6001,
14 /// A party's VSS commitment did not verify against the polynomial
15 /// shares it claims to distribute. Indicates a malformed or
16 /// malicious share submission.
17 /// Caller action: treat the contributing party as Byzantine.
18 VSS_VERIFY_FAILED = 0x6002,
19 /// Fewer than T shares were supplied for a sign / decapsulation
20 /// session. The threshold was set during DKG; supplying fewer
21 /// shares is a programming error, not a network fault.
22 /// Caller action: collect more shares before retrying.
23 BELOW_THRESHOLD = 0x6010,
24 /// A round message failed to deserialize or had an unexpected
25 /// sender / round number. Indicates protocol desynchronization
26 /// (one party is on a different round than the others) or a
27 /// buggy / malicious peer.
28 /// Caller action: abort the session; do not retry with the same
29 /// message feed.
30 BAD_ROUND_MESSAGE = 0x6020,
31 /// A partial signature was malformed (wrong length, out-of-range
32 /// scalar) but the offending party is not identified. This is the
33 /// non-identifiable-abort path; if identifiable abort is enabled,
34 /// [`IDENTIFIED_BYZANTINE`](Self::IDENTIFIED_BYZANTINE) is emitted
35 /// instead.
36 BAD_PARTIAL_SIGNATURE = 0x6030,
37 /// Identifiable abort: a specific peer posted an inconsistent
38 /// partial signature. The carry payload identifies the offending
39 /// party by its 1-based roster index in the low byte.
40 IDENTIFIED_BYZANTINE = 0x6040,
41 /// Internal error — a panic-equivalent condition was caught and
42 /// converted to an error return. Indicates a bug in the CMP20
43 /// implementation; please open an issue.
44 INTERNAL = 0x60FF,
45}
46
47impl From<Cmp20ErrorCode> for u32 {
48 #[inline]
49 fn from(c: Cmp20ErrorCode) -> u32 {
50 c as u32
51 }
52}
53
54/// Build a framework [`TcError`] carrying a CMP20 sub-code.
55pub fn scheme_error(code: Cmp20ErrorCode) -> TcError {
56 confium_tc::error::SchemeInternalSnafu {
57 code: u32::from(code),
58 }
59 .build()
60}
61
62pub type Result<T> = std::result::Result<T, TcError>;