clementine_tx_sender/citrea/
data_serialization.rs

1use borsh::{BorshDeserialize, BorshSerialize};
2
3/// Data written to DA and read from DA must be the borsh serialization of this enum
4/// WARNING: This type has to be the exact same as the one used in citrea repo, so that the borsh serializations are the same.
5/// citrea/crates/sovereign-sdk/rollup-interface/src/state_machine/da.rs
6#[derive(Debug, Clone, Eq, PartialEq, BorshDeserialize, BorshSerialize)]
7#[allow(clippy::large_enum_variant)]
8pub(crate) enum DataOnDa {
9    /// A zk proof and state diff
10    Complete(Proof),
11    /// A list of tx ids
12    Aggregate(Vec<[u8; 32]>, Vec<[u8; 32]>),
13    /// A chunk of an aggregate
14    Chunk(Vec<u8>),
15    /// A new batch proof method_id
16    BatchProofMethodId(BatchProofMethodId),
17    /// Sequencer commitment
18    SequencerCommitment(SequencerCommitment),
19}
20
21/// Commitments made to the DA layer from the sequencer.
22/// Has merkle root of l2 block hashes from L1 start block to L1 end block (inclusive)
23#[derive(Debug, Clone, Eq, PartialEq, BorshDeserialize, BorshSerialize)]
24pub(crate) struct SequencerCommitment {
25    /// Merkle root of l2 block hashes
26    pub merkle_root: [u8; 32],
27    /// Absolute order of the sequencer commitment, the first commitment has index 0, the next one has 1...
28    pub index: u32,
29    /// End L2 block's number
30    pub l2_end_block_number: u64,
31}
32
33/// The ZK proof generated by the [`ZkvmHost::run`] method.
34type Proof = Vec<u8>;
35
36/// Minimum number of verified signatures required to approve a method id upgrade.
37const SECURITY_COUNCIL_SIGNATURE_THRESHOLD: usize = 3;
38/// Size of a signature in bytes.
39const SECURITY_COUNCIL_SIGNATURE_SIZE: usize = 64;
40
41/// A new batch proof method_id starting to be applied from the l2_block_number (inclusive).
42#[derive(Debug, Clone, Eq, PartialEq, BorshSerialize, BorshDeserialize)]
43pub(crate) struct BatchProofMethodId {
44    /// Body of the method id update, the message to be signed
45    /// Includes method id and activation height
46    pub body: BatchProofMethodIdBody,
47    /// Signatures to be verified for the method id update used for a 3 of 5 security council
48    /// Consists of 64 byte keccak256(eip191 prefixed message) prehash signed signatures
49    /// The public keys can be recovered from the signatures and the prehash
50    /// The indices point to the pubkeys in the light client circuit initial values
51    /// To verify the signature the pubkey should be fetched from the initial values corresponding to the signature
52    /// If one signature verification fails the whole method id update is invalid
53    /// Also assumes the indexes are in ascending order and there are no duplicates
54    pub signatures_with_index:
55        [([u8; SECURITY_COUNCIL_SIGNATURE_SIZE], u8); SECURITY_COUNCIL_SIGNATURE_THRESHOLD],
56}
57
58/// Body of the batch proof method id update for light client
59#[derive(Debug, Clone, Eq, PartialEq, BorshDeserialize, BorshSerialize)]
60pub(crate) struct BatchProofMethodIdBody {
61    /// New method id of upcoming fork
62    pub method_id: [u32; 8],
63    /// Activation L2 height of the new method id
64    pub activation_l2_height: u64,
65    /// Network identifier to prevent cross network replay attacks
66    pub chain_id: u64,
67}