confium_tc_gg18/error.rs
1//! Error helpers for the GG18 scheme crate.
2
3use confium_tc::error::Error as TcError;
4
5/// GG18 sub-codes (0x50xx). Distinct from CMP20's 0x60xx so callers can
6/// disambiguate the source scheme from a numeric code alone.
7#[allow(non_camel_case_types)]
8#[repr(u32)]
9pub enum Gg18ErrorCode {
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 = 0x5001,
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 = 0x5002,
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 = 0x5010,
24 /// A round message failed to deserialize or had an unexpected
25 /// sender / round number. GG18 has 4 rounds; a message from the
26 /// wrong round indicates protocol desynchronization or a buggy
27 /// peer.
28 /// Caller action: abort the session; do not retry with the same
29 /// message feed.
30 BAD_ROUND_MESSAGE = 0x5020,
31 /// A partial signature was malformed (wrong length, out-of-range
32 /// scalar). GG18 does not support identifiable abort; if you need
33 /// to attribute the failure to a specific peer, use CMP20 instead.
34 BAD_PARTIAL_SIGNATURE = 0x5030,
35 /// Internal error — a panic-equivalent condition was caught and
36 /// converted to an error return. Indicates a bug in the GG18
37 /// implementation; please open an issue.
38 INTERNAL = 0x50FF,
39}
40
41impl From<Gg18ErrorCode> for u32 {
42 #[inline]
43 fn from(c: Gg18ErrorCode) -> u32 {
44 c as u32
45 }
46}
47
48/// Build a framework [`TcError`] carrying a GG18 sub-code.
49pub fn scheme_error(code: Gg18ErrorCode) -> TcError {
50 confium_tc::error::SchemeInternalSnafu {
51 code: u32::from(code),
52 }
53 .build()
54}
55
56pub type Result<T> = std::result::Result<T, TcError>;