Skip to content

Commit c654afd

Browse files
authored
fix: use EVM-configured tx gas limit cap (#343)
1 parent 82c7165 commit c654afd

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

crates/evm/src/either.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{Evm, EvmEnv};
22
use alloy_primitives::{Address, Bytes};
3-
use revm::context::either;
3+
use revm::context::{either, CfgEnv};
44

55
impl<L, R> Evm for either::Either<L, R>
66
where
@@ -29,6 +29,10 @@ where
2929
either::for_both!(self, evm => evm.block())
3030
}
3131

32+
fn cfg_env(&self) -> &CfgEnv<Self::Spec> {
33+
either::for_both!(self, evm => evm.cfg_env())
34+
}
35+
3236
fn chain_id(&self) -> u64 {
3337
either::for_both!(self, evm => evm.chain_id())
3438
}

crates/evm/src/eth/block.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use alloy_hardforks::EthereumHardfork;
2424
use alloy_primitives::{Bytes, Log, B256};
2525
use revm::{
2626
context::Block, context_interface::result::ResultAndState, database::DatabaseCommitExt,
27-
primitives::eip7825::TX_GAS_LIMIT_CAP, DatabaseCommit, Inspector,
27+
DatabaseCommit, Inspector,
2828
};
2929

3030
/// Context for Ethereum block execution.
@@ -177,9 +177,12 @@ where
177177

178178
// Use regular part of transaction gas limit to check if it fits inside available block
179179
// space.
180-
let tx_min_gas_limit = min(tx.tx().gas_limit(), TX_GAS_LIMIT_CAP);
180+
let mut max_tx_gas_usage = tx.tx().gas_limit();
181+
if let Some(tx_gas_limit_cap) = self.evm.cfg_env().tx_gas_limit_cap {
182+
max_tx_gas_usage = min(max_tx_gas_usage, tx_gas_limit_cap);
183+
}
181184

182-
if tx_min_gas_limit > block_available_gas {
185+
if max_tx_gas_usage > block_available_gas {
183186
return Err(BlockValidationError::TransactionGasLimitMoreThanAvailableBlockGas {
184187
transaction_gas_limit: tx.tx().gas_limit(),
185188
block_available_gas,

crates/evm/src/eth/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ where
211211
&self.block
212212
}
213213

214+
fn cfg_env(&self) -> &CfgEnv<Self::Spec> {
215+
&self.cfg
216+
}
217+
214218
fn chain_id(&self) -> u64 {
215219
self.cfg.chain_id
216220
}

crates/evm/src/evm.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use alloy_consensus::transaction::TxHashRef;
55
use alloy_primitives::{Address, Bytes, B256};
66
use core::{error::Error, fmt::Debug, hash::Hash};
77
use revm::{
8-
context::result::ExecutionResult,
8+
context::{result::ExecutionResult, CfgEnv},
99
context_interface::{
1010
result::{HaltReasonTr, ResultAndState},
1111
ContextTr,
@@ -64,6 +64,9 @@ pub trait Evm {
6464
/// Reference to [`Evm::BlockEnv`].
6565
fn block(&self) -> &Self::BlockEnv;
6666

67+
/// Reference to [`CfgEnv`].
68+
fn cfg_env(&self) -> &CfgEnv<Self::Spec>;
69+
6770
/// Returns the chain ID of the environment.
6871
fn chain_id(&self) -> u64;
6972

0 commit comments

Comments
 (0)