pessimistic_proof_core/
multi_batch_header.rs

1#![allow(clippy::too_many_arguments)]
2use std::collections::BTreeMap;
3
4use agglayer_primitives::{Digest, U256};
5use serde::{Deserialize, Serialize};
6use unified_bridge::{
7    BridgeExit, ImportedBridgeExit, ImportedBridgeExitCommitmentValues, NetworkId, TokenInfo,
8};
9
10use crate::{
11    aggchain_data::AggchainData, local_balance_tree::LocalBalancePath,
12    nullifier_tree::NullifierPath,
13};
14
15/// Represents the chain state transition for the pessimistic proof.
16#[derive(Clone, Debug, Serialize, Deserialize)]
17pub struct MultiBatchHeader {
18    /// Network that emitted this [`MultiBatchHeader`].
19    pub origin_network: NetworkId,
20    /// Current certificate height of the L2 chain.
21    pub height: u64,
22    /// Previous pessimistic root.
23    pub prev_pessimistic_root: Digest,
24    /// List of bridge exits created in this batch.
25    pub bridge_exits: Vec<BridgeExit>,
26    /// List of imported bridge exits claimed in this batch.
27    pub imported_bridge_exits: Vec<(ImportedBridgeExit, NullifierPath)>,
28    /// L1 info root used to import bridge exits.
29    pub l1_info_root: Digest,
30    /// Token balances of the origin network before processing bridge events,
31    /// with Merkle proofs of these balances in the local balance tree.
32    pub balances_proofs: BTreeMap<TokenInfo, (U256, LocalBalancePath)>,
33    /// Aggchain data which include either multisig, aggchain proof, or both.
34    pub aggchain_data: AggchainData,
35    /// Certificate id used as nonce to compute the commitment.
36    pub certificate_id: Digest,
37}
38
39impl MultiBatchHeader {
40    /// Returns the commitment on the imported bridge exits.
41    pub fn commit_imported_bridge_exits(&self) -> ImportedBridgeExitCommitmentValues {
42        ImportedBridgeExitCommitmentValues {
43            claims: self
44                .imported_bridge_exits
45                .iter()
46                .map(|(exit, _)| exit.to_indexed_exit_hash())
47                .collect(),
48        }
49    }
50}