@@ -3,7 +3,7 @@ use std::{collections::HashMap, marker::PhantomData, mem, sync::Arc};
33use alloy:: {
44 consensus:: { BlockHeader , TxType } ,
55 eips:: BlockId ,
6- network:: TransactionBuilder ,
6+ network:: { primitives :: HeaderResponse , BlockResponse , TransactionBuilder } ,
77 rpc:: types:: { state:: StateOverride , Block , Header , Transaction , TransactionRequest } ,
88} ;
99use eyre:: Result ;
@@ -55,7 +55,18 @@ impl<E: ExecutionProvider<Ethereum>> EthereumEvm<E> {
5555 validate_tx : bool ,
5656 state_overrides : Option < StateOverride > ,
5757 ) -> Result < ( ExecutionResult , HashMap < Address , Account > ) , EvmError > {
58- let mut db = ProofDB :: new ( self . block_id , self . execution . clone ( ) , state_overrides) ;
58+ let block = self
59+ . execution
60+ . get_block ( self . block_id , false )
61+ . await
62+ . map_err ( |err| EvmError :: Generic ( err. to_string ( ) ) ) ?
63+ . ok_or ( ExecutionError :: BlockNotFound ( self . block_id ) )
64+ . map_err ( |err| EvmError :: Generic ( err. to_string ( ) ) ) ?;
65+
66+ // Pin block id to a specific hash for the entire EVM run
67+ let pinned_block_id: BlockId = block. header ( ) . hash ( ) . into ( ) ;
68+
69+ let mut db = ProofDB :: new ( pinned_block_id, self . execution . clone ( ) , state_overrides) ;
5970 _ = db. state . prefetch_state ( tx, validate_tx) . await ;
6071
6172 // Track iterations for debugging
@@ -78,7 +89,7 @@ impl<E: ExecutionProvider<Ethereum>> EthereumEvm<E> {
7889 }
7990
8091 // Create EVM after any async operations
81- let context = self . get_context ( tx, self . block_id , validate_tx) . await ? ;
92+ let context = self . get_context ( tx, & block , validate_tx) ;
8293
8394 // Execute in a scope to ensure EVM is dropped before any potential async operations
8495 let ( result, needs_update) = {
@@ -96,21 +107,13 @@ impl<E: ExecutionProvider<Ethereum>> EthereumEvm<E> {
96107 tx_res. map_err ( |err| EvmError :: Generic ( format ! ( "generic: {err}" ) ) )
97108 }
98109
99- async fn get_context (
110+ fn get_context (
100111 & self ,
101112 tx : & TransactionRequest ,
102- block_id : BlockId ,
113+ block : & Block < Transaction , Header > ,
103114 validate_tx : bool ,
104- ) -> Result < Context , EvmError > {
105- let block = self
106- . execution
107- . get_block ( block_id, false )
108- . await
109- . map_err ( |err| EvmError :: Generic ( err. to_string ( ) ) ) ?
110- . ok_or ( ExecutionError :: BlockNotFound ( block_id) )
111- . map_err ( |err| EvmError :: Generic ( err. to_string ( ) ) ) ?;
112-
113- let spec = get_spec_id_for_block_timestamp ( block. header . timestamp ( ) , & self . fork_schedule ) ;
115+ ) -> Context {
116+ let spec = get_spec_id_for_block_timestamp ( block. header ( ) . timestamp ( ) , & self . fork_schedule ) ;
114117 let mut tx_env = Self :: tx_env ( tx, spec) ;
115118
116119 if <TxType as Into < u8 > >:: into (
@@ -123,17 +126,17 @@ impl<E: ExecutionProvider<Ethereum>> EthereumEvm<E> {
123126 }
124127
125128 let mut cfg = CfgEnv :: default ( ) ;
126- cfg. spec = get_spec_id_for_block_timestamp ( block. header . timestamp , & self . fork_schedule ) ;
129+ cfg. spec = get_spec_id_for_block_timestamp ( block. header ( ) . timestamp ( ) , & self . fork_schedule ) ;
127130 cfg. chain_id = self . chain_id ;
128131 cfg. disable_block_gas_limit = !validate_tx;
129132 cfg. disable_eip3607 = !validate_tx;
130133 cfg. disable_base_fee = !validate_tx;
131134 cfg. disable_nonce_check = !validate_tx;
132135
133- Ok ( Context :: mainnet ( )
136+ Context :: mainnet ( )
134137 . with_tx ( tx_env)
135- . with_block ( Self :: block_env ( & block, & self . fork_schedule ) )
136- . with_cfg ( cfg) )
138+ . with_block ( Self :: block_env ( block, & self . fork_schedule ) )
139+ . with_cfg ( cfg)
137140 }
138141
139142 fn tx_env ( tx : & TransactionRequest , spec : SpecId ) -> TxEnv {
0 commit comments