Skip to content

Commit 919aa25

Browse files
authored
fix: skip floor gas check for l1 messages (#67)
* fix: skip floor gas check for l1 messages * tests: use helper
1 parent f5ae93d commit 919aa25

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

src/handler.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use revm::{
1212
handler::{
1313
post_execution, EthFrame, EvmTr, EvmTrError, FrameResult, FrameTr, Handler, MainnetHandler,
1414
},
15-
interpreter::{interpreter::EthInterpreter, interpreter_action::FrameInit, Gas},
15+
interpreter::{
16+
interpreter::EthInterpreter, interpreter_action::FrameInit, Gas, InitialAndFloorGas,
17+
},
1618
primitives::U256,
1719
};
1820
use revm_inspector::{Inspector, InspectorEvmTr, InspectorHandler};
@@ -199,6 +201,20 @@ where
199201
Ok(())
200202
}
201203

204+
#[inline]
205+
fn eip7623_check_gas_floor(
206+
&self,
207+
evm: &mut Self::Evm,
208+
exec_result: &mut <<Self::Evm as EvmTr>::Frame as FrameTr>::FrameResult,
209+
init_and_floor_gas: InitialAndFloorGas,
210+
) {
211+
// skip floor gas check for l1 messages.
212+
if evm.ctx().tx().is_l1_msg() {
213+
return;
214+
}
215+
self.mainnet.eip7623_check_gas_floor(evm, exec_result, init_and_floor_gas)
216+
}
217+
202218
#[inline]
203219
fn refund(
204220
&self,

src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::vec::Vec;
1212

1313
pub const TX_L1_FEE_PRECISION: U256 = U256::from_limbs([1_000_000_000u64, 0, 0, 0]);
1414
pub const CALLER: Address = address!("0x000000000000000000000000000000000000dead");
15-
pub const TO: Address = address!("0x0000000000000000000000000000000000000001");
15+
pub const TO: Address = address!("0x00000000000000000000000000000000000dead1");
1616
pub const BENEFICIARY: Address = address!("0x0000000000000000000000000000000000000002");
1717
pub const MIN_TRANSACTION_COST: U256 = U256::from_limbs([21_000u64, 0, 0, 0]);
1818
pub const L1_DATA_COST: U256 = U256::from_limbs([40_000u64, 0, 0, 0]);

src/tests/l1_message.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ use revm::{
1414
result::{EVMError, ExecutionResult, HaltReason, InvalidTransaction, ResultAndState},
1515
ContextTr, JournalTr,
1616
},
17+
context_interface::result::ExecutionResult::Halt,
1718
handler::{EthFrame, EvmTr, FrameResult, Handler},
18-
interpreter::{CallOutcome, Gas, InstructionResult, InterpreterResult},
19+
interpreter::{
20+
gas::calculate_initial_tx_gas_for_tx, CallOutcome, Gas, InstructionResult,
21+
InterpreterResult,
22+
},
1923
state::Bytecode,
2024
ExecuteEvm,
2125
};
22-
use revm_primitives::U256;
26+
use revm_primitives::{bytes, hardfork::SpecId, U256};
2327

2428
#[test]
2529
fn test_l1_message_validate_lacking_funds() -> Result<(), Box<dyn core::error::Error>> {
@@ -210,3 +214,28 @@ fn test_l1_message_eip_3607() -> Result<(), Box<dyn core::error::Error>> {
210214

211215
Ok(())
212216
}
217+
218+
#[test]
219+
fn test_l1_message_should_not_have_floor_gas_as_gas_used() -> Result<(), Box<dyn core::error::Error>>
220+
{
221+
let ctx =
222+
context().modify_cfg_chained(|cfg| cfg.enable_eip7623 = true).modify_tx_chained(|tx| {
223+
tx.base.data =
224+
bytes!("0x000000000123456789abcdef00000000123456789abcdef00000000123456789abcdef");
225+
tx.base.tx_type = L1_MESSAGE_TYPE;
226+
tx.base.caller = CALLER;
227+
tx.base.gas_limit = 200000;
228+
tx.base.value = U256::ONE;
229+
});
230+
let tx = ctx.tx.clone();
231+
let mut evm = ctx.build_scroll();
232+
let res = evm.transact(tx.clone())?;
233+
234+
// floor gas is TOTAL_COST_FLOOR_PER_TOKEN * tokens_in_calldata + 21_000 = 22070;
235+
let expected_init_gas =
236+
calculate_initial_tx_gas_for_tx(tx, SpecId::SHANGHAI, true, true).initial_gas;
237+
238+
assert_eq!(res.result, Halt { reason: HaltReason::OutOfFunds, gas_used: expected_init_gas });
239+
240+
Ok(())
241+
}

0 commit comments

Comments
 (0)