Skip to content

Commit 11fe1c1

Browse files
authored
fix(l1): have block execution stop when block's gas limit is surpassed by executing a transaction (#5185)
**Motivation** The ef test for Osaka that's run in the Hive integration testing site named `osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py::test_tx_gas_larger_than_block_gas_limit[fork_Osaka-blockchain_test_engine-exceed_block_gas_limit_False]` is failing due to an error message mismatch. See [here](https://hive.ethpandaops.io/#/test/fusaka/1762265312-8631b0f0f5ea8f900a071365137dd155?testnumber=364). Besides we don't have any logic implemented when processing a block to stop computing transactions once the block's gas limit was surpassed. **Description** This pr adds a conditional to check if the block's gas limit can be potentially surpassed, and in that case stop computing any other transactions. So if tx.gas_limit > gas_available the block's execution must stop with an exception, as the spec says [here](https://github.com/ethereum/execution-specs/blob/69364e2133e1d20f679455fc92680366cb72db37/src/ethereum/forks/osaka/fork.py#L460). To test it I run: ``` make build-image cd hive ./hive --sim ethereum/eels/consume-engine --client ethrex --results-root results --client-file=../fixtures/hive/clients.yaml --sim.buildarg fixtures=https://github.com/ethereum/execution-spec-tests/releases/download/v5.3.0/fixtures_develop.tar.gz --sim.buildarg branch=forks/osaka --sim.loglevel=3 --sim.limit=".*test_tx_gas_larger_than_block_gas_limit.*" ```
1 parent 80aaef8 commit 11fe1c1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crates/vm/backends/levm/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ impl LEVM {
5454
for (tx, tx_sender) in block.body.get_transactions_with_sender().map_err(|error| {
5555
EvmError::Transaction(format!("Couldn't recover addresses with error: {error}"))
5656
})? {
57+
if cumulative_gas_used + tx.gas_limit() > block.header.gas_limit {
58+
return Err(EvmError::Transaction(format!(
59+
"Gas allowance exceeded. Block gas limit {} can be surpassed by executing transaction with gas limit {}",
60+
block.header.gas_limit,
61+
tx.gas_limit()
62+
)));
63+
}
64+
5765
let report = Self::execute_tx(tx, tx_sender, &block.header, db, vm_type)?;
5866

5967
cumulative_gas_used += report.gas_used;
@@ -97,6 +105,14 @@ impl LEVM {
97105
for (tx, tx_sender) in block.body.get_transactions_with_sender().map_err(|error| {
98106
EvmError::Transaction(format!("Couldn't recover addresses with error: {error}"))
99107
})? {
108+
if cumulative_gas_used + tx.gas_limit() > block.header.gas_limit {
109+
return Err(EvmError::Transaction(format!(
110+
"Gas allowance exceeded. Block gas limit {} can be surpassed by executing transaction with gas limit {}",
111+
block.header.gas_limit,
112+
tx.gas_limit()
113+
)));
114+
}
115+
100116
let report = Self::execute_tx(tx, tx_sender, &block.header, db, vm_type)?;
101117
LEVM::send_state_transitions_tx(&merkleizer, db, queue_length)?;
102118

0 commit comments

Comments
 (0)