Skip to content

feat: add --megaeth EVM mode#2

Merged
RealiCZ merged 3 commits intomainfrom
cz/feat/megaeth
Apr 21, 2026
Merged

feat: add --megaeth EVM mode#2
RealiCZ merged 3 commits intomainfrom
cz/feat/megaeth

Conversation

@RealiCZ
Copy link
Copy Markdown
Collaborator

@RealiCZ RealiCZ commented Apr 16, 2026

Summary

Adds --megaeth mode to forge test and forge coverage, routing execution through mega-evm 1.5.1 while preserving Foundry's test / coverage / trace UX.

Core integration

  • Route MegaETH transactions through MegaEvm with a dedicated inspector fan-out for MegaCtx (tracer / log collector / revert diagnostic wired; cheatcodes and isolation intentionally skipped).
  • Deploy MegaETH system contracts (Oracle, HP Timestamp, Keyless Deploy) idempotently: skip when code_hash already matches, preserve existing balance / nonce — mirrors mega-evme's pattern.
  • Translate mega-evm ExecutionResult / HaltReason into their revm counterparts for downstream reporting.

Flag validation

New shared EvmOpts::validate_megaeth() rejects unsupported combinations at fail-fast CLI layer, before any network request:

Combination Behavior
--megaeth --isolate rejected — isolation not implemented
--megaeth --fork-url <URL> rejected — no fork-aware external env
--megaeth --gas-report rejected — gas report implies isolation
Inline forge-config: isolate = true + --megaeth rejected at test time

Applied to both forge test and forge coverage. Coverage also now correctly forwards --isolate / --odyssey to the runner (previously silently dropped).

Test plan

  • cargo nextest run -p forge --test cli -E 'test(~megaeth)'
  • make test
  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets --all-features
  • cargo nextest run -p forge --test cli megaeth_live_cross_validate --run-ignored=only — passes locally and installs mega-evme@1.5.1 from crates.io into target/mega-evme-1.5.1/ on first run

Note

Alloy version bump

  • All alloy-* pinned to =1.0.23 — required by mega-evm 1.5.1's Cargo.toml.

@RealiCZ RealiCZ requested a review from Troublor as a code owner April 16, 2026 08:47
@claude
Copy link
Copy Markdown

claude Bot commented Apr 16, 2026

Review posted (see below)

@claude
Copy link
Copy Markdown

claude Bot commented Apr 16, 2026

Placeholder - ignore

@claude
Copy link
Copy Markdown

claude Bot commented Apr 16, 2026

test with backtick foo

@claude
Copy link
Copy Markdown

claude Bot commented Apr 16, 2026

Review

Good overall structure. The validation layering (CLI → builder → inline-config) is thorough and the idempotent system contract deployment mirrors mega-evme correctly. A few issues worth addressing:

Must fix — Alloy exact-pin change needs justification (REVIEW.md rule)

All alloy deps were bumped from 1.0.22 to =1.0.23 (exact pin) and alloy-primitives from 1.2.1 to 1.3.1. REVIEW.md requires that changes to alloy explain the fork-specific need and test coverage. The PR description is silent on why. If mega-evm 1.5.1 requires these exact versions to avoid a diamond-dep conflict, that should be stated explicitly.

Must fix — MegaCtx is defined twice

pub type MegaCtx is declared in both crates/evm/core/src/evm.rs and crates/evm/evm/src/inspectors/stack.rs. The definitions are structurally identical today, but if they ever drift the compiler will not catch it — callers silently get the wrong type. The stack.rs definition should be removed and replaced with: use foundry_evm_core::evm::MegaCtx;

Should fix — Backend::is_megaeth is pub

All other Backend fields are private; this one exposes mutable access to any caller. A stray backend.is_megaeth = true from an unrelated path could silently reroute execution. Use pub(crate) or a dedicated setter.

Should fix — SystemTxInvalidCallee mapped to CallNotAllowedInsideStatic

An invalid callee in a system transaction has nothing to do with static calls. Users who see CallNotAllowedInsideStatic in a MegaETH test failure will search for a staticcall that does not exist. At minimum add a comment documenting this lossy approximation.

Comment thread crates/evm/evm/src/inspectors/stack.rs Outdated
Comment thread crates/evm/core/src/backend/mod.rs
Comment thread crates/evm/core/src/evm.rs
@claude
Copy link
Copy Markdown

claude Bot commented Apr 16, 2026

All four issues from the previous review have been addressed:

  • MegaCtx duplicate — single definition in evm.rs, properly imported in stack.rs. ✓
  • Backend::is_megaeth visibility — now pub(crate) with a dedicated set_megaeth setter. ✓
  • SystemTxInvalidCallee mapping — changed to NotActivated with an explanatory comment. ✓
  • Alloy pin justification — PR description Note section explicitly attributes the exact-pin to mega-evm 1.5.1's dependency requirements. ✓

One new minor issue noted inline on cow.rs.

Comment thread crates/evm/core/src/backend/cow.rs Outdated
@claude
Copy link
Copy Markdown

claude Bot commented Apr 16, 2026

LGTM. All feedback from both prior review rounds has been addressed:

  • Third commit ("route MegaETH inspect dispatch through executor") cleanly resolves the cow.rs inline: the is_megaeth routing now lives exclusively in Executor::call_with_env / transact_with_env, keeping CowBackend::inspect and CowBackend::inspect_mega as dumb call-throughs with no branching logic.
  • The four issues from the first review (MegaCtx duplicate, is_megaeth visibility, SystemTxInvalidCallee mapping, alloy pin justification) remain fixed.
  • Validation layering (CLI → builder → inline-config) is airtight.

No further concerns.

@RealiCZ RealiCZ merged commit 0317e9c into main Apr 21, 2026
7 checks passed
@RealiCZ RealiCZ deleted the cz/feat/megaeth branch April 21, 2026 02:37
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