Skip to content

refactor(evm): use EvmEnv::with_limits() for evm limit configuration#253

Merged
mattsse merged 9 commits intoalloy-rs:mainfrom
rezzmah:configurable-evm-execution-limits
Jan 17, 2026
Merged

refactor(evm): use EvmEnv::with_limits() for evm limit configuration#253
mattsse merged 9 commits intoalloy-rs:mainfrom
rezzmah:configurable-evm-execution-limits

Conversation

@rezzmah
Copy link
Contributor

@rezzmah rezzmah commented Jan 15, 2026

Motivation

Many chains need flexibility around MAX_CODE_SIZE, MAX_INITCODE_SIZE, and tx_gas_limit_cap (see reth#21018). This need is validated by EIP-7907.

Currently, configuring these limits requires verbose manual field assignments:

evm_env.cfg_env.limit_contract_code_size = Some(limits.max_code_size);
evm_env.cfg_env.limit_contract_initcode_size = Some(limits.max_initcode_size);
if let Some(cap) = limits.tx_gas_limit_cap {
    evm_env.cfg_env.tx_gas_limit_cap = Some(cap);
}

Solution

Add EvmLimitParams struct and a with_limits() builder method on EvmEnv:

  pub struct EvmLimitParams {
      pub max_code_size: usize,
      pub max_initcode_size: usize,
      pub tx_gas_limit_cap: Option<u64>,
  }

  // Usage:
  let evm_env = EvmEnv::for_eth_block(...).with_limits(limits);

This follows the existing builder pattern used by CfgEnv (e.g., with_chain_id(), with_spec()).

However, a alternative consideration to be made is whether this helper should be configured in revm directly, similar to helpers like below

    pub fn with_max_blobs_per_tx(mut self, max_blobs_per_tx: u64) -> Self {
        self.set_max_blobs_per_tx(max_blobs_per_tx);
        self
    }

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes -> None

@rezzmah rezzmah marked this pull request as ready for review January 16, 2026 00:06
@rezzmah rezzmah requested review from klkvr and mattsse as code owners January 16, 2026 00:06
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tiny suggestion

/// These parameters control configurable limits in the EVM that can be
/// overridden from their spec defaults (EIP-170, EIP-3860, EIP-7825).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct EvmLimitParams {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will likely be a bit inconvenient to manage because we also need this dep in the chainspec

but turns out we already have that in there

pub fn with_limits(mut self, limits: EvmLimitParams) -> Self {
self.cfg_env.limit_contract_code_size = Some(limits.max_code_size);
self.cfg_env.limit_contract_initcode_size = Some(limits.max_initcode_size);
self.cfg_env.tx_gas_limit_cap = Some(limits.tx_gas_limit_cap.unwrap_or(u64::MAX));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not unwrap here and instead leave this as is so that we respect the none value properly

Instead of translating None to u64::MAX, pass it directly to respect
the spec's fork-aware default (e.g., EIP-7825 for Osaka).
@mattsse mattsse enabled auto-merge (squash) January 17, 2026 12:14
@mattsse mattsse merged commit a1fb787 into alloy-rs:main Jan 17, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants