22
33use alloy_eips:: eip2718:: Encodable2718 ;
44use alloy_eips:: BlockId ;
5- use alloy_rpc_types:: trace:: geth:: { PreStateConfig , PreStateFrame } ;
5+ use alloy_rpc_types:: {
6+ trace:: geth:: { PreStateConfig , PreStateFrame } ,
7+ TransactionReceipt ,
8+ } ;
69use anvil:: { cmd:: NodeArgs , eth:: EthApi , NodeConfig , NodeHandle } ;
7- use anvil_core:: eth:: block :: Block ;
8- use anvil_core:: eth:: transaction:: PendingTransaction ;
10+ use anvil_core:: eth:: transaction :: { PendingTransaction , TypedTransaction } ;
11+ use anvil_core:: eth:: { block :: Block , transaction:: TypedReceipt } ;
912use cast:: traces:: { GethTraceBuilder , TracingInspectorConfig } ;
1013use clap:: Parser ;
14+ use op_alloy_consensus:: {
15+ OpDepositReceipt , OpDepositReceiptWithBloom , OpReceiptEnvelope , OpTypedTransaction , TxDeposit ,
16+ } ;
17+ use op_alloy_rpc_types:: OpTransactionReceipt ;
1118use std:: {
1219 error:: Error ,
1320 fs:: { self , File } ,
1421 path:: PathBuf ,
1522} ;
1623
1724use color_eyre:: eyre:: { ensure, eyre, Result } ;
18- use op_test_vectors:: execution:: { ExecutionFixture , ExecutionReceipt , ExecutionResult } ;
25+ use op_test_vectors:: execution:: { ExecutionEnvironment , ExecutionFixture , ExecutionResult } ;
1926use revm:: {
2027 db:: { AlloyDB , CacheDB } ,
2128 primitives:: { BlobExcessGasAndPrice , BlockEnv , CfgEnv , Env , SpecId , U256 } ,
@@ -142,19 +149,20 @@ impl Opt8n {
142149 self . capture_pre_post_alloc ( & block) ?;
143150
144151 // Append block transactions and receipts to the execution fixture
145- let mut receipts: Vec < ExecutionReceipt > = Vec :: with_capacity ( block. transactions . len ( ) ) ;
152+ let mut receipts: Vec < OpTransactionReceipt > = Vec :: with_capacity ( block. transactions . len ( ) ) ;
146153 for tx in block. transactions . iter ( ) {
147154 if let Some ( receipt) = self
148155 . eth_api
149156 . backend
150157 . transaction_receipt ( tx. transaction . hash ( ) )
151158 . await ?
152159 {
153- receipts. push ( receipt. try_into ( ) ?) ;
160+ let op_receipt = tx_receipt_to_op_tx_receipt ( receipt) ;
161+ receipts. push ( op_receipt) ;
154162 }
155- self . execution_fixture
156- . transactions
157- . push ( tx . transaction . clone ( ) ) ;
163+
164+ let op_tx = typed_tx_to_op_typed_tx ( & tx . transaction ) ;
165+ self . execution_fixture . transactions . push ( op_tx ) ;
158166 }
159167
160168 let block_header = & block. header ;
@@ -166,7 +174,17 @@ impl Opt8n {
166174 receipts,
167175 } ;
168176
169- self . execution_fixture . env = block. into ( ) ;
177+ let execution_environment = ExecutionEnvironment {
178+ current_coinbase : block_header. beneficiary ,
179+ current_difficulty : block_header. difficulty ,
180+ current_gas_limit : U256 :: from ( block. header . gas_limit ) ,
181+ previous_hash : block_header. parent_hash ,
182+ current_number : U256 :: from ( block. header . number ) ,
183+ current_timestamp : U256 :: from ( block_header. timestamp ) ,
184+ block_hashes : None ,
185+ } ;
186+
187+ self . execution_fixture . env = execution_environment;
170188 self . execution_fixture . result = execution_result;
171189
172190 // Ensure pre and post states are different
@@ -183,6 +201,94 @@ impl Opt8n {
183201 }
184202}
185203
204+ // TODO: Consider adding `From` implementation for
205+ // `TypedTransaction` -> `OpTypedTransaction` in `op-alloy-consensus`
206+ fn typed_tx_to_op_typed_tx ( tx : & TypedTransaction ) -> OpTypedTransaction {
207+ let op_tx = match tx {
208+ TypedTransaction :: Legacy ( signed_tx) => OpTypedTransaction :: Legacy ( signed_tx. tx ( ) . clone ( ) ) ,
209+ TypedTransaction :: EIP2930 ( signed_tx) => OpTypedTransaction :: Eip2930 ( signed_tx. tx ( ) . clone ( ) ) ,
210+
211+ TypedTransaction :: EIP1559 ( signed_tx) => OpTypedTransaction :: Eip1559 ( signed_tx. tx ( ) . clone ( ) ) ,
212+ TypedTransaction :: EIP4844 ( signed_tx) => OpTypedTransaction :: Eip4844 ( signed_tx. tx ( ) . clone ( ) ) ,
213+ TypedTransaction :: Deposit ( deposit_tx) => {
214+ let op_deposit_tx = TxDeposit {
215+ source_hash : deposit_tx. source_hash ,
216+ from : deposit_tx. from ,
217+ to : deposit_tx. kind ,
218+ mint : Some (
219+ deposit_tx
220+ . mint
221+ . try_into ( )
222+ . expect ( "Mint is greater than u128" ) ,
223+ ) ,
224+ value : deposit_tx. value ,
225+ gas_limit : deposit_tx. gas_limit ,
226+ is_system_transaction : deposit_tx. is_system_tx ,
227+ input : deposit_tx. input . clone ( ) ,
228+ } ;
229+
230+ OpTypedTransaction :: Deposit ( op_deposit_tx)
231+ }
232+ TypedTransaction :: EIP7702 ( _) => {
233+ unimplemented ! ( "EIP7702 not implemented" )
234+ }
235+ } ;
236+
237+ op_tx
238+ }
239+
240+ // TODO: Consider adding `From` implementation for
241+ // `TransactionReceipt` -> `OpTransactionReceipt` in `op-alloy-consensus`
242+ fn tx_receipt_to_op_tx_receipt (
243+ receipt : TransactionReceipt < TypedReceipt < alloy_rpc_types:: Log > > ,
244+ ) -> OpTransactionReceipt {
245+ let receipt_envelope = receipt. inner ;
246+ let op_receipt_envelope = match receipt_envelope {
247+ TypedReceipt :: Legacy ( receipt_with_bloom) => OpReceiptEnvelope :: Legacy ( receipt_with_bloom) ,
248+ TypedReceipt :: EIP2930 ( receipt_with_bloom) => OpReceiptEnvelope :: Eip2930 ( receipt_with_bloom) ,
249+ TypedReceipt :: EIP1559 ( receipt_with_bloom) => OpReceiptEnvelope :: Eip1559 ( receipt_with_bloom) ,
250+ TypedReceipt :: EIP4844 ( receipt_with_bloom) => OpReceiptEnvelope :: Eip4844 ( receipt_with_bloom) ,
251+ TypedReceipt :: EIP7702 ( _) => {
252+ unimplemented ! ( "EIP7702 not implemented" )
253+ }
254+ TypedReceipt :: Deposit ( deposit_receipt) => {
255+ let op_deposit_receipt = OpDepositReceipt {
256+ inner : deposit_receipt. inner . receipt ,
257+ deposit_nonce : deposit_receipt. deposit_nonce ,
258+ deposit_receipt_version : deposit_receipt. deposit_receipt_version ,
259+ } ;
260+
261+ let op_deposit_receipt_with_bloom = OpDepositReceiptWithBloom {
262+ receipt : op_deposit_receipt,
263+ logs_bloom : deposit_receipt. inner . logs_bloom ,
264+ } ;
265+
266+ OpReceiptEnvelope :: Deposit ( op_deposit_receipt_with_bloom)
267+ }
268+ } ;
269+
270+
271+
272+ OpTransactionReceipt {
273+ inner : TransactionReceipt {
274+ inner : op_receipt_envelope,
275+ transaction_hash : receipt. transaction_hash ,
276+ transaction_index : receipt. transaction_index ,
277+ block_hash : receipt. block_hash ,
278+ block_number : receipt. block_number ,
279+ gas_used : receipt. gas_used ,
280+ effective_gas_price : receipt. effective_gas_price ,
281+ blob_gas_used : receipt. blob_gas_used ,
282+ blob_gas_price : receipt. blob_gas_price ,
283+ from : receipt. from ,
284+ to : receipt. to ,
285+ contract_address : receipt. contract_address ,
286+ state_root : receipt. state_root ,
287+ authorization_list : receipt. authorization_list ,
288+ } ,
289+ }
290+ }
291+
186292/// Creates a new EVM instance from a given block, chain, database, and spec id.
187293pub fn evm < ' a , DB > ( block : & Block , chain_id : u64 , db : DB , spec_id : SpecId ) -> Evm < ' a , ( ) , Box < DB > >
188294where
0 commit comments