agglayer_types/
error.rs

1use agglayer_interop_types::LocalExitRoot;
2use agglayer_primitives::{Address, SignatureError};
3use agglayer_tries::error::SmtError;
4use pessimistic_proof::{core::MultisigError, error::ProofVerificationError, ProofError};
5use serde::{Deserialize, Serialize};
6use unified_bridge::{GlobalIndex, LocalExitTreeError, NetworkId, TokenInfo};
7
8use crate::{aggchain_data::AggchainDataError, Digest, GenerationType};
9
10#[derive(Debug, thiserror::Error, Clone, Serialize, Deserialize, PartialEq, Eq)]
11#[serde(rename = "agglayer_types::Error")]
12pub enum Error {
13    /// The imported bridge exits should refer to one and the same L1 info root.
14    #[error("Imported bridge exits refer to multiple L1 info root")]
15    MultipleL1InfoRoot,
16    /// The certificate refers to a new local exit root which differ from the
17    /// one computed by the agglayer.
18    #[error(
19        "Mismatch on the certificate new local exit root. declared: {declared:?}, computed: \
20         {computed:?}"
21    )]
22    MismatchNewLocalExitRoot {
23        computed: LocalExitRoot,
24        declared: LocalExitRoot,
25    },
26    /// The given token balance cannot overflow.
27    #[error("Token balance cannot overflow. token: {0:?}")]
28    BalanceOverflow(TokenInfo),
29    /// The given token balance cannot be negative.
30    #[error("Token balance cannot be negative. token: {0:?}")]
31    BalanceUnderflow(TokenInfo),
32    /// The balance proof for the given token cannot be generated.
33    #[error("Unable to generate the balance proof. token: {token:?}, error: {source}")]
34    BalanceProofGenerationFailed { source: SmtError, token: TokenInfo },
35    /// The nullifier path for the given imported bridge exit cannot be
36    /// generated.
37    #[error(
38        "Unable to generate the nullifier path. global_index: {global_index:?}, error: {source}"
39    )]
40    NullifierPathGenerationFailed {
41        source: SmtError,
42        global_index: GlobalIndex,
43    },
44    /// The operation cannot be applied on the local exit tree.
45    #[error(transparent)]
46    InvalidLocalExitTreeOperation(#[from] LocalExitTreeError),
47    #[error(
48        "Incorrect L1 Info Root for the leaf count {leaf_count}. declared: {declared}, retrieved \
49         from L1: {retrieved}"
50    )]
51    /// Invalid or unsettled L1 Info Root
52    L1InfoRootIncorrect {
53        leaf_count: u32,
54        declared: Digest,
55        retrieved: Digest,
56    },
57    #[error(
58        "Incorrect declared L1 Info Tree information: l1_leaf: {l1_leaf:?}, l1_root: \
59         {l1_info_root:?}"
60    )]
61    InconsistentL1InfoTreeInformation {
62        l1_leaf: Option<u32>,
63        l1_info_root: Option<Digest>,
64    },
65    /// The operation cannot be applied on the smt.
66    #[error(transparent)]
67    InvalidSmtOperation(#[from] SmtError),
68
69    /// Inconsistent GERs
70    #[error("Inconsistent GER")]
71    InconsistentGlobalExitRoot,
72
73    #[error("AggchainVkey missing")]
74    MissingAggchainVkey,
75
76    #[error(
77        "Invalid custom chain data length expected at least {expected_at_least}, actual {actual}"
78    )]
79    InvalidCustomChainDataLength {
80        expected_at_least: usize,
81        actual: usize,
82    },
83
84    /// The certificate refers to a prev local exit root which differ from the
85    /// one computed by the agglayer.
86    #[error(
87        "Mismatch on the certificate prev local exit root. declared: {declared:?}, computed: \
88         {computed:?}"
89    )]
90    MismatchPrevLocalExitRoot {
91        computed: LocalExitRoot,
92        declared: LocalExitRoot,
93    },
94
95    #[error("Invalid multisig, signature or aggchain proof related data. {0:?}")]
96    InvalidChainData(AggchainDataError),
97}
98
99#[derive(Clone, Debug, Serialize, Deserialize, thiserror::Error, PartialEq, Eq)]
100pub enum CertificateStatusError {
101    /// Failure on the pessimistic proof execution, either natively or in the
102    /// prover.
103    #[error("({generation_type}) proof generation error: {}", source.to_string())]
104    ProofGenerationError {
105        generation_type: GenerationType,
106        source: ProofError,
107    },
108
109    /// Failure on the proof verification.
110    #[error("Proof verification failed")]
111    ProofVerificationFailed(#[source] ProofVerificationError),
112
113    /// Failure on the pessimistic proof witness generation from the
114    /// [`LocalNetworkStateData`] and the provided [`Certificate`].
115    #[error("Cannot produce local network state from certificate")]
116    TypeConversionError(#[source] Error),
117
118    #[error("Trusted sequencer address not found for network: {0}")]
119    TrustedSequencerNotFound(NetworkId),
120
121    #[error("Internal error: {0}")]
122    InternalError(String),
123
124    #[error("Settlement error: {0}")]
125    SettlementError(String),
126
127    #[error("Pre certification error: {0}")]
128    PreCertificationError(String),
129
130    #[error("Certification error: {0}")]
131    CertificationError(String),
132
133    #[error("L1 Info root not found for l1 leaf count: {0}")]
134    L1InfoRootNotFound(u32),
135
136    #[error("Last pessimistic root not found for network: {0}")]
137    LastPessimisticRootNotFound(NetworkId),
138}
139
140#[derive(Debug, thiserror::Error)]
141pub enum SignerError {
142    #[error("Signature not provided")]
143    Missing,
144
145    #[error("Signature recovery error")]
146    Recovery(#[source] SignatureError),
147
148    #[error(
149        "Invalid PP signature either due to wrong signer or commitment. expected signer: \
150         {expected_signer}"
151    )]
152    InvalidPessimisticProofSignature { expected_signer: Address },
153
154    #[error("Invalid multisig: {0}")]
155    InvalidMultisig(#[source] MultisigError),
156}