bankai_types/fetch/evm/
execution.rs

1extern crate alloc;
2use alloc::string::String;
3use alloc::vec::Vec;
4use serde::{Deserialize, Deserializer, Serialize, Serializer};
5
6#[cfg(feature = "verifier-types")]
7use crate::fetch::evm::MmrProof;
8#[cfg(feature = "verifier-types")]
9use alloy_primitives::U256;
10use alloy_primitives::{Address, Bytes, FixedBytes};
11
12#[cfg(feature = "verifier-types")]
13use alloy_rpc_types_eth::{Account, Header as ExecutionHeader};
14
15// Custom serialization for ExecutionHeader to work with bincode
16fn serialize_execution_header<S>(header: &ExecutionHeader, serializer: S) -> Result<S::Ok, S::Error>
17where
18    S: Serializer,
19{
20    let json_str = serde_json::to_string(header).map_err(serde::ser::Error::custom)?;
21    json_str.serialize(serializer)
22}
23
24fn deserialize_execution_header<'de, D>(deserializer: D) -> Result<ExecutionHeader, D::Error>
25where
26    D: Deserializer<'de>,
27{
28    // Deserialize as JSON string first
29    let json_str = String::deserialize(deserializer)?;
30    // Then parse the JSON string to ExecutionHeader
31    serde_json::from_str(&json_str).map_err(serde::de::Error::custom)
32}
33
34#[cfg(feature = "verifier-types")]
35#[cfg_attr(feature = "std", derive(Debug))]
36#[derive(Clone, Serialize, Deserialize)]
37pub struct ExecutionHeaderProof {
38    #[serde(
39        serialize_with = "serialize_execution_header",
40        deserialize_with = "deserialize_execution_header"
41    )]
42    pub header: ExecutionHeader,
43    pub mmr_proof: MmrProof,
44}
45
46#[cfg(feature = "verifier-types")]
47#[cfg_attr(feature = "std", derive(Debug))]
48#[derive(Clone, Serialize, Deserialize)]
49pub struct AccountProof {
50    pub account: Account,
51    pub address: Address,
52    pub network_id: u64,
53    pub block_number: u64,
54    pub state_root: FixedBytes<32>,
55    pub mpt_proof: Vec<Bytes>,
56}
57
58#[cfg(feature = "verifier-types")]
59#[cfg_attr(feature = "std", derive(Debug))]
60#[derive(Clone, Serialize, Deserialize)]
61pub struct TxProof {
62    pub network_id: u64,
63    pub block_number: u64,
64    pub tx_hash: FixedBytes<32>,
65    pub tx_index: u64,
66    pub proof: Vec<Bytes>,
67    pub encoded_tx: Vec<u8>,
68}
69
70/// A single storage slot with its key, value, and MPT proof
71#[cfg(feature = "verifier-types")]
72#[cfg_attr(feature = "std", derive(Debug))]
73#[derive(Clone, Serialize, Deserialize)]
74pub struct StorageSlotEntry {
75    pub slot_key: U256,
76    pub slot_value: U256,
77    pub storage_mpt_proof: Vec<Bytes>,
78}
79
80/// Proof for one or more storage slots from the same contract in a single block.
81/// The account proof is shared across all slots.
82#[cfg(feature = "verifier-types")]
83#[cfg_attr(feature = "std", derive(Debug))]
84#[derive(Clone, Serialize, Deserialize)]
85pub struct StorageSlotProof {
86    pub account: Account,
87    pub address: Address,
88    pub network_id: u64,
89    pub block_number: u64,
90    pub state_root: FixedBytes<32>,
91    pub account_mpt_proof: Vec<Bytes>,
92    pub slots: Vec<StorageSlotEntry>,
93}