diff --git a/crates/revm/src/optimism/handler_register.rs b/crates/revm/src/optimism/handler_register.rs index 5980e8613a..06b61e0c83 100644 --- a/crates/revm/src/optimism/handler_register.rs +++ b/crates/revm/src/optimism/handler_register.rs @@ -150,7 +150,7 @@ pub fn validate_tx_against_state( .l1_block_info .as_ref() .expect("L1BlockInfo should be loaded") - .operator_fee_charge(gas_limit, SPEC::SPEC_ID); + .operator_fee_charge(enveloped_tx, gas_limit, SPEC::SPEC_ID); let mut balance_check = gas_limit .checked_mul(tx.gas_price) @@ -373,7 +373,7 @@ pub fn deduct_caller( .l1_block_info .as_ref() .expect("L1BlockInfo should be loaded") - .operator_fee_charge(gas_limit, SPEC::SPEC_ID); + .operator_fee_charge(enveloped_tx, gas_limit, SPEC::SPEC_ID); caller_account.info.balance = caller_account .info @@ -413,6 +413,7 @@ pub fn reward_beneficiary( let l1_cost = l1_block_info.calculate_tx_l1_cost(enveloped_tx, SPEC::SPEC_ID); let operator_fee_cost = l1_block_info.operator_fee_charge( + enveloped_tx, U256::from(gas.spent() - gas.refunded() as u64), SPEC::SPEC_ID, ); diff --git a/crates/revm/src/optimism/l1block.rs b/crates/revm/src/optimism/l1block.rs index 345fd29503..12976273f7 100644 --- a/crates/revm/src/optimism/l1block.rs +++ b/crates/revm/src/optimism/l1block.rs @@ -190,7 +190,11 @@ impl L1BlockInfo { /// Calculate the operator fee for executing this transaction. /// /// Introduced in isthmus. Prior to isthmus, the operator fee is always zero. - pub fn operator_fee_charge(&self, gas_limit: U256, spec_id: SpecId) -> U256 { + pub fn operator_fee_charge(&self, input: &[u8], gas_limit: U256, spec_id: SpecId) -> U256 { + // If the input is a deposit transaction or empty, the default value is zero. + if input.is_empty() || input.first() == Some(&0x7F) { + return U256::ZERO; + } if !spec_id.is_enabled_in(SpecId::ISTHMUS) { return U256::ZERO; } @@ -223,6 +227,7 @@ impl L1BlockInfo { // constant. operator_fee_scalar.saturating_mul(U256::from(gas.remaining() + gas.refunded() as u64)) + / (U256::from(OPERATOR_FEE_SCALAR_DECIMAL)) } /// Calculate the data gas for posting the transaction on L1. Calldata costs 16 gas per byte @@ -575,4 +580,21 @@ mod tests { assert_eq!(l1_fee, expected_l1_fee) } + + #[test] + fn test_operator_fee_refund() { + let gas = Gas::new(50000); + + let l1_block_info = L1BlockInfo { + l1_base_fee: U256::from(1055991687), + l1_base_fee_scalar: U256::from(5227), + operator_fee_scalar: Some(U256::from(2000)), + operator_fee_constant: Some(U256::from(5)), + ..Default::default() + }; + + let refunded = l1_block_info.operator_fee_refund(&gas, SpecId::ISTHMUS); + + assert_eq!(refunded, U256::from(100)) + } }