Skip to main content

molpha_verifier/
error.rs

1//! Error type for attestation verification.
2//!
3//! These are pure verification errors, mapped by downstream programs at the call boundary.
4//! Account-borrow/deserialization errors are produced and handled by the caller (which owns the
5//! framework-specific account I/O) and never cross the crate boundary.
6//!
7//! Enable the `thiserror` feature for [`std::error::Error`] and [`std::fmt::Display`] when using
8//! this crate in off-chain tooling.
9
10#[cfg_attr(feature = "thiserror", derive(thiserror::Error))]
11#[derive(Debug, PartialEq, Eq, Copy, Clone)]
12pub enum AttestationError {
13    /// Aggregate Schnorr signature failed verification (recovered address mismatch,
14    /// invalid coalition key, or invalid scalar `s`).
15    #[cfg_attr(
16        feature = "thiserror",
17        error("aggregate Schnorr signature verification failed")
18    )]
19    InvalidAggregateSignature,
20    /// A signature component was malformed (e.g. non-canonical scalar during the
21    /// Schnorr→ECDSA conversion).
22    #[cfg_attr(
23        feature = "thiserror",
24        error("malformed signature component (e.g. non-canonical Schnorr scalar)")
25    )]
26    InvalidSignature,
27    /// `popcount(signers_bitmap) < signatures_required`.
28    #[cfg_attr(
29        feature = "thiserror",
30        error("insufficient signers: popcount(signers_bitmap) < signatures_required")
31    )]
32    InsufficientSigners,
33    /// `signers_bitmap` is not a subset of the deterministically derived selection bitmap.
34    #[cfg_attr(
35        feature = "thiserror",
36        error("signers_bitmap is not a subset of the derived selection bitmap")
37    )]
38    SignersNotSubsetOfSelection,
39    /// `signers_bitmap` has bits set outside `[0, node_count)`, or is otherwise invalid.
40    #[cfg_attr(
41        feature = "thiserror",
42        error("invalid signers_bitmap (bits outside [0, node_count) or malformed)")
43    )]
44    InvalidSignersBitmap,
45    /// Selection-group bitmap derivation failed (bad node count / group size, or the
46    /// bounded sampling loop did not converge).
47    #[cfg_attr(
48        feature = "thiserror",
49        error("selection-group bitmap derivation failed")
50    )]
51    GroupBitmapDerivationFailed,
52    /// `ordered_signers.len()` does not equal `popcount(signers_bitmap)`.
53    #[cfg_attr(
54        feature = "thiserror",
55        error("ordered_signers.len() does not match popcount(signers_bitmap)")
56    )]
57    SignerCountMismatch,
58    /// The requested registry version is neither current nor a live previous version.
59    #[cfg_attr(feature = "thiserror", error("invalid registry version"))]
60    InvalidRegistryVersion,
61    /// A signer account is missing, extra, or owned by another program.
62    #[cfg_attr(
63        feature = "thiserror",
64        error("signer account missing, extra, or owned by another program")
65    )]
66    MissingSignerAccount,
67    /// A `Node` account does not match its expected bitmap index.
68    #[cfg_attr(
69        feature = "thiserror",
70        error("node account index does not match bitmap")
71    )]
72    InvalidNodeIndex,
73    /// Previous-version remove remapping was requested without valid transition metadata.
74    #[cfg_attr(
75        feature = "thiserror",
76        error("previous-version remove remapping requested without valid transition metadata")
77    )]
78    InvalidTransitionAccount,
79}
80
81#[cfg(all(test, feature = "thiserror"))]
82mod tests {
83    use super::*;
84    use std::error::Error;
85
86    #[test]
87    fn implements_error_and_display() {
88        let err = AttestationError::InsufficientSigners;
89        assert!(err.source().is_none());
90        assert!(err.to_string().contains("insufficient signers"));
91    }
92}