foundry icon indicating copy to clipboard operation
foundry copied to clipboard

bug(monad): vm.setEvmVersion leaves reserve policy stale

Open haythemsellami opened this issue 3 months ago • 2 comments

Component

Forge / EVM

Affected version

The Monad integration proposed in #15343 at 40f293806e535762cabe33c70aa465c8e7b47918, using monad-revm at 8ba4a51b221357105465cbe6d410906d3f12baeb.

Description

Crossing Monad hardforks through vm.setEvmVersion updates the configuration, instructions, precompiles, and frame memory policy, but it does not update spec-derived policy already captured by the transaction's ReserveBalanceTracker.

The tracker captures values including the recent-code-hash behavior and MonadNine's created-and-selfdestructed-account exemption during transaction initialization. Its existing rebase operation updates chain context and tracked accounts but not those hardfork-derived flags. Foundry's runtime transition currently only rebuilds MonadCfgEnv.

This means a transaction initialized under MonadEight can execute MonadNine instructions and precompiles while reserve enforcement still applies MonadEight policy.

Reproduction

  1. Start a Forge test transaction under MonadEight.
  2. Pre-fund a deterministic CREATE2 destination.
  3. Call vm.setEvmVersion("MonadNine").
  4. Deploy constructor code to that destination that self-destructs during initialization.
  5. Query dippedIntoReserve() at 0x0000000000000000000000000000000000001001.

The transitioned execution reports a reserve violation. Running the same operation from a transaction initialized directly under MonadNine applies the created-and-selfdestructed exemption and does not report the violation.

Expected behavior

Runtime hardfork transitions should update every spec-dependent execution policy. Execution reached through Eight→Nine should match execution initialized directly under Nine, and transitions in both directions should remain coherent.

Suggested fix

Add a monad-revm tracker reconfiguration hook that updates spec-derived flags and recomputes already tracked accounts without resetting transaction sender, gas, or chain-context invariants. Invoke it whenever the Monad EVM observes a runtime spec transition, alongside instruction and precompile selection.

The Foundry integration should pin the corresponding monad-revm fix and add a vm.setEvmVersion regression. Dependency tests should cover Eight→Nine, Nine→Eight, and Nine→Eight→Nine transitions, including the created-and-selfdestructed case.

haythemsellami avatar Aug 12 '26 05:08 haythemsellami

Could you share whether the referenced fix has been merged into the monad branch, and whether the Eight→Nine and reverse-transition regression tests are included?

DefiAudit0x avatar Nov 09 '26 23:11 DefiAudit0x

Opened a fix for this:

  • Foundry: https://github.com/foundry-rs/foundry/pull/18722
  • Dependency-side reconfigure_reserve_balance_for_spec lives on https://github.com/kutluhaneth46/monad-alloy-evm2-1/tree/fix/reserve-policy-reconfigure-on-spec (dd8e9cea). I could not open the PR against category-labs/monad-alloy-evm2 from this account (API 404/permission); happy for a maintainer to open it from that commit so the Foundry pin can move back to category-labs.

The Forge regression covers Eight→Nine CREATE2 selfdestruct vs direct Nine, matching the repro in this issue.

kutluhaneth46 avatar Nov 25 '26 17:11 kutluhaneth46