22use crate :: {
33 api:: exec:: OpContextTr ,
44 constants:: {
5- BASE_FEE_RECIPIENT , GAS_ORACLE_CONTRACT , L1_FEE_RECIPIENT , OPERATOR_FEE_RECIPIENT ,
6- BVM_ETH_MINT_GAS_COMPENSATION ,
5+ BASE_FEE_RECIPIENT , BVM_ETH_MINT_GAS_COMPENSATION , GAS_ORACLE_CONTRACT , L1_FEE_RECIPIENT ,
6+ OPERATOR_FEE_RECIPIENT ,
77 } ,
88 transaction:: { deposit:: DEPOSIT_TRANSACTION_TYPE , OpTransactionError , OpTxTr } ,
99 BvmEth , L1BlockInfo , OpHaltReason , OpSpecId ,
@@ -33,7 +33,7 @@ use revm::{
3333 } ,
3434 primitives:: { hardfork:: SpecId , U256 } ,
3535} ;
36- use std:: { boxed:: Box , vec:: Vec } ;
36+ use std:: { boxed:: Box , vec, vec :: Vec } ;
3737
3838/// Optimism handler extends the [`Handler`] with Optimism specific logic.
3939#[ derive( Debug , Clone ) ]
@@ -442,7 +442,10 @@ where
442442 // The condition guards against false positives: without eth_value/eth_tx_value no
443443 // BVM_ETH warming occurs, and without input no contract code executes.
444444 if ( tx. eth_value ( ) . is_some ( ) || tx. eth_tx_value ( ) . is_some ( ) ) && !tx. input ( ) . is_empty ( ) {
445- gas. set_remaining ( gas. remaining ( ) . saturating_sub ( BVM_ETH_MINT_GAS_COMPENSATION ) ) ;
445+ gas. set_remaining (
446+ gas. remaining ( )
447+ . saturating_sub ( BVM_ETH_MINT_GAS_COMPENSATION ) ,
448+ ) ;
446449 }
447450
448451 let limit = gas. limit ( ) ;
@@ -464,7 +467,10 @@ where
464467
465468 if !is_arsia {
466469 // scale refund and remaining by token_ratio, restore limit
467- gas. set_refund ( scale_refund_with_token_ratio ( gas. refunded ( ) , token_ratio_u64) ) ;
470+ gas. set_refund ( scale_refund_with_token_ratio (
471+ gas. refunded ( ) ,
472+ token_ratio_u64,
473+ ) ) ;
468474 gas. set_remaining ( gas. remaining ( ) . saturating_mul ( token_ratio_u64) ) ;
469475 gas. set_limit ( limit) ;
470476 }
@@ -815,7 +821,12 @@ mod tests {
815821 info. calculate_tx_l1_cost ( input, spec)
816822 }
817823
818- fn regular_tx ( caller : Address , to : Address , gas_limit : u64 , input : & [ u8 ] ) -> OpTransaction < TxEnv > {
824+ fn regular_tx (
825+ caller : Address ,
826+ to : Address ,
827+ gas_limit : u64 ,
828+ input : & [ u8 ] ,
829+ ) -> OpTransaction < TxEnv > {
819830 OpTransaction :: builder ( )
820831 . base (
821832 TxEnv :: builder ( )
@@ -1953,7 +1964,8 @@ mod tests {
19531964 let caller = Address :: from_str ( "0x1000000000000000000000000000000000000001" ) . unwrap ( ) ;
19541965 let recipient = Address :: from_str ( "0x2000000000000000000000000000000000000002" ) . unwrap ( ) ;
19551966 let regular_input = bytes ! ( "faca01" ) ;
1956- let deposit_caller = Address :: from_str ( "0x9000000000000000000000000000000000000009" ) . unwrap ( ) ;
1967+ let deposit_caller =
1968+ Address :: from_str ( "0x9000000000000000000000000000000000000009" ) . unwrap ( ) ;
19571969
19581970 let mut db = InMemoryDB :: default ( ) ;
19591971 update_fee_params_in_db (
@@ -2011,9 +2023,10 @@ mod tests {
20112023 l1_block_contract
20122024 . storage
20132025 . insert ( L1_BASE_FEE_SLOT , U256 :: from ( NEW_L1_BASE_FEE ) ) ;
2014- l1_block_contract
2015- . storage
2016- . insert ( ECOTONE_L1_BLOB_BASE_FEE_SLOT , U256 :: from ( NEW_L1_BLOB_BASE_FEE ) ) ;
2026+ l1_block_contract. storage . insert (
2027+ ECOTONE_L1_BLOB_BASE_FEE_SLOT ,
2028+ U256 :: from ( NEW_L1_BLOB_BASE_FEE ) ,
2029+ ) ;
20172030 l1_block_contract. storage . insert (
20182031 ECOTONE_L1_FEE_SCALARS_SLOT ,
20192032 ecotone_fee_scalars (
@@ -2057,7 +2070,10 @@ mod tests {
20572070 assert_eq ! ( chain. token_ratio, U256 :: from( TOKEN_RATIO ) ) ;
20582071 assert_eq ! ( chain. l1_base_fee, U256 :: from( NEW_L1_BASE_FEE ) ) ;
20592072 if spec. is_enabled_in ( OpSpecId :: ARSIA ) {
2060- assert_eq ! ( chain. l1_blob_base_fee, Some ( U256 :: from( NEW_L1_BLOB_BASE_FEE ) ) ) ;
2073+ assert_eq ! (
2074+ chain. l1_blob_base_fee,
2075+ Some ( U256 :: from( NEW_L1_BLOB_BASE_FEE ) )
2076+ ) ;
20612077 assert_eq ! (
20622078 chain. l1_blob_base_fee_scalar,
20632079 Some ( U256 :: from( NEW_L1_BLOB_BASE_FEE_SCALAR ) )
@@ -2255,7 +2271,8 @@ mod tests {
22552271
22562272 let caller = Address :: from_str ( "0x5000000000000000000000000000000000000005" ) . unwrap ( ) ;
22572273 let recipient = Address :: from_str ( "0x6000000000000000000000000000000000000006" ) . unwrap ( ) ;
2258- let deposit_caller = Address :: from_str ( "0x7000000000000000000000000000000000000007" ) . unwrap ( ) ;
2274+ let deposit_caller =
2275+ Address :: from_str ( "0x7000000000000000000000000000000000000007" ) . unwrap ( ) ;
22592276 let regular_input = bytes ! ( "faca03" ) ;
22602277 let set_token_ratio_input =
22612278 bytes ! ( "e38e91f900000000000000000000000000000000000000000000000000000000000010cc" ) ;
@@ -2316,9 +2333,10 @@ mod tests {
23162333 l1_block_contract
23172334 . storage
23182335 . insert ( L1_BASE_FEE_SLOT , U256 :: from ( NEW_L1_BASE_FEE ) ) ;
2319- l1_block_contract
2320- . storage
2321- . insert ( ECOTONE_L1_BLOB_BASE_FEE_SLOT , U256 :: from ( NEW_L1_BLOB_BASE_FEE ) ) ;
2336+ l1_block_contract. storage . insert (
2337+ ECOTONE_L1_BLOB_BASE_FEE_SLOT ,
2338+ U256 :: from ( NEW_L1_BLOB_BASE_FEE ) ,
2339+ ) ;
23222340 l1_block_contract. storage . insert (
23232341 ECOTONE_L1_FEE_SCALARS_SLOT ,
23242342 ecotone_fee_scalars (
@@ -2560,11 +2578,7 @@ mod tests {
25602578
25612579 // Verify caller nonce was bumped and mint balance was credited.
25622580 // Per the OP deposit spec, these must persist even on deposit failure.
2563- let caller_acc = evm
2564- . ctx ( )
2565- . journal_mut ( )
2566- . load_account ( caller)
2567- . unwrap ( ) ;
2581+ let caller_acc = evm. ctx ( ) . journal_mut ( ) . load_account ( caller) . unwrap ( ) ;
25682582 assert_eq ! (
25692583 caller_acc. info. nonce, 1 ,
25702584 "Caller nonce must be bumped for failed deposits"
@@ -3024,24 +3038,29 @@ mod tests {
30243038 . modify_cfg_chained ( |cfg| cfg. spec = OpSpecId :: ISTHMUS ) ;
30253039 // eth_value is None by default, so compensation should not be applied
30263040
3027- let gas_with_compensation =
3028- call_last_frame_return ( ctx_with_compensation, InstructionResult :: Stop , Gas :: new ( remaining_gas) ) ;
3029- let gas_without_compensation =
3030- call_last_frame_return ( ctx_without_compensation, InstructionResult :: Stop , Gas :: new ( remaining_gas) ) ;
3041+ let gas_with_compensation = call_last_frame_return (
3042+ ctx_with_compensation,
3043+ InstructionResult :: Stop ,
3044+ Gas :: new ( remaining_gas) ,
3045+ ) ;
3046+ let gas_without_compensation = call_last_frame_return (
3047+ ctx_without_compensation,
3048+ InstructionResult :: Stop ,
3049+ Gas :: new ( remaining_gas) ,
3050+ ) ;
30313051
30323052 // Calculate the difference in remaining gas
3033- let gas_difference = gas_without_compensation. remaining ( ) - gas_with_compensation. remaining ( ) ;
3053+ let gas_difference =
3054+ gas_without_compensation. remaining ( ) - gas_with_compensation. remaining ( ) ;
30343055
30353056 // Verify the difference is exactly 4500
30363057 assert_eq ! (
3037- gas_difference,
3038- BVM_ETH_MINT_GAS_COMPENSATION ,
3058+ gas_difference, BVM_ETH_MINT_GAS_COMPENSATION ,
30393059 "Gas compensation should be exactly {} (account diff 2500 + storage diff 2000)" ,
30403060 BVM_ETH_MINT_GAS_COMPENSATION
30413061 ) ;
30423062 assert_eq ! (
3043- BVM_ETH_MINT_GAS_COMPENSATION ,
3044- 4500 ,
3063+ BVM_ETH_MINT_GAS_COMPENSATION , 4500 ,
30453064 "BVM_ETH_MINT_GAS_COMPENSATION constant should be 4500"
30463065 ) ;
30473066 }
@@ -3056,9 +3075,7 @@ mod tests {
30563075 . with_tx (
30573076 OpTransaction :: builder ( )
30583077 . base (
3059- TxEnv :: builder ( )
3060- . gas_limit ( initial_gas)
3061- . data ( Bytes :: new ( ) ) , // Empty input
3078+ TxEnv :: builder ( ) . gas_limit ( initial_gas) . data ( Bytes :: new ( ) ) , // Empty input
30623079 )
30633080 . source_hash ( B256 :: from ( [ 1u8 ; 32 ] ) )
30643081 . build_fill ( ) ,
@@ -3069,7 +3086,7 @@ mod tests {
30693086 . modify_cfg_chained ( |cfg| cfg. spec = OpSpecId :: ISTHMUS ) ;
30703087
30713088 let gas = call_last_frame_return ( ctx, InstructionResult :: Stop , Gas :: new ( remaining_gas) ) ;
3072-
3089+
30733090 // Gas compensation should NOT be applied when input is empty
30743091 assert_eq ! (
30753092 gas. remaining( ) ,
@@ -3098,7 +3115,7 @@ mod tests {
30983115 // eth_value and eth_tx_value are None by default
30993116
31003117 let gas = call_last_frame_return ( ctx, InstructionResult :: Stop , Gas :: new ( remaining_gas) ) ;
3101-
3118+
31023119 // Gas compensation should NOT be applied when both eth_value and eth_tx_value are None
31033120 assert_eq ! (
31043121 gas. remaining( ) ,
@@ -3161,7 +3178,7 @@ mod tests {
31613178 . modify_cfg_chained ( |cfg| cfg. spec = OpSpecId :: ISTHMUS ) ;
31623179
31633180 let gas = call_last_frame_return ( ctx, InstructionResult :: Stop , Gas :: new ( remaining_gas) ) ;
3164-
3181+
31653182 // Gas compensation should NOT be applied when eth_value is zero (returns None)
31663183 assert_eq ! (
31673184 gas. remaining( ) ,
@@ -3201,9 +3218,9 @@ mod tests {
32013218 . modify_cfg_chained ( |cfg| cfg. spec = OpSpecId :: ISTHMUS ) ;
32023219
32033220 let gas = call_last_frame_return ( ctx, InstructionResult :: Stop , Gas :: new ( remaining_gas) ) ;
3204-
3221+
32053222 // Gas compensation (4500) should be subtracted from remaining gas
3206- // Since remaining_gas (5000) > BVM_ETH_MINT_GAS_COMPENSATION (4500),
3223+ // Since remaining_gas (5000) > BVM_ETH_MINT_GAS_COMPENSATION (4500),
32073224 // remaining should be 5000 - 4500 = 500
32083225 assert_eq ! (
32093226 gas. remaining( ) ,
@@ -3348,11 +3365,15 @@ mod tests {
33483365 let error = EVMError :: Transaction ( OpTransactionError :: HaltedDepositPostRegolith ) ;
33493366 let result = handler. catch_error ( & mut evm, error) ;
33503367
3351- assert ! ( result. is_ok( ) , "Failed deposit should return Ok(FailedDeposit)" ) ;
3368+ assert ! (
3369+ result. is_ok( ) ,
3370+ "Failed deposit should return Ok(FailedDeposit)"
3371+ ) ;
33523372
33533373 // Verify cleanup was performed.
33543374 assert_eq ! (
3355- evm. ctx( ) . chain. tx_l1_cost, None ,
3375+ evm. ctx( ) . chain. tx_l1_cost,
3376+ None ,
33563377 "clear_tx_l1_cost must be called after catch_error"
33573378 ) ;
33583379 }
@@ -3395,12 +3416,11 @@ mod tests {
33953416 assert_eq ! ( nonce_before, 1 , "Nonce should be 1 before catch_error" ) ;
33963417
33973418 // catch_error for non-deposit should return Err and call discard_tx().
3398- let error = EVMError :: Transaction (
3399- OpTransactionError :: Base ( InvalidTransaction :: NonceTooLow {
3419+ let error =
3420+ EVMError :: Transaction ( OpTransactionError :: Base ( InvalidTransaction :: NonceTooLow {
34003421 tx : 0 ,
34013422 state : 1 ,
3402- } ) ,
3403- ) ;
3423+ } ) ) ;
34043424 let result = handler. catch_error ( & mut evm, error) ;
34053425
34063426 assert ! ( result. is_err( ) , "Non-deposit error should propagate as Err" ) ;
@@ -3449,11 +3469,7 @@ mod tests {
34493469 // This must NOT revert the previously committed nonce/mint.
34503470 evm. ctx ( ) . journal_mut ( ) . discard_tx ( ) ;
34513471
3452- let caller_acc = evm
3453- . ctx ( )
3454- . journal_mut ( )
3455- . load_account ( caller)
3456- . unwrap ( ) ;
3472+ let caller_acc = evm. ctx ( ) . journal_mut ( ) . load_account ( caller) . unwrap ( ) ;
34573473 assert_eq ! (
34583474 caller_acc. info. nonce, 1 ,
34593475 "Committed nonce must survive subsequent discard_tx"
0 commit comments