Skip to content

refactor(evm): replace NestedEvmExt trait with free function#13652

Merged
mattsse merged 2 commits intofoundry-rs:masterfrom
figtracer:fig/nested-evm-generic-factory
Mar 7, 2026
Merged

refactor(evm): replace NestedEvmExt trait with free function#13652
mattsse merged 2 commits intofoundry-rs:masterfrom
figtracer:fig/nested-evm-generic-factory

Conversation

@figtracer
Copy link
Copy Markdown
Collaborator

@figtracer figtracer commented Mar 6, 2026

Summary

  • Replace NestedEvmExt trait with with_cloned_context free function
  • The function handles the network-agnostic work: clone env + journal, split db borrow, write back
  • Callers build their own EVM inside a callback that receives (&mut dyn DatabaseExt, Env, JournaledState)
  • Remove new_nested_evm from trait and new_evm_with_existing_context (dead code)
  • Simplify CheatsCtxExt to just FoundryContextExt with journal/db bounds (one less trait)

Stack: #13650#13651 → PR 3/3

Depends on #13651

Test plan

  • cargo check passes (zero errors, zero warnings)
  • All callers updated: InspectorStackInner, TransparentCheatcodesExecutor

@figtracer figtracer force-pushed the fig/nested-evm-generic-factory branch 3 times, most recently from d775a1c to fc5b5b8 Compare March 6, 2026 16:58
Comment thread crates/evm/core/src/evm.rs Outdated
@figtracer figtracer force-pushed the fig/nested-evm-generic-factory branch from fc5b5b8 to 31da635 Compare March 6, 2026 18:33
@figtracer figtracer changed the title refactor(evm): make NestedEvmExt network-agnostic refactor(evm): replace NestedEvmExt trait with free function Mar 6, 2026
Copy link
Copy Markdown
Collaborator

@mablr mablr left a comment

Choose a reason for hiding this comment

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

Free function with_cloned_context looks good to me.

I'm not sure about adding another abstraction via CheatsCtxExt trait for the moment, as the bounds are still subject to change (eg: FoundryContextExt support only Ethereum EVM). Let's stabilize this first? wdyt @figtracer

@figtracer
Copy link
Copy Markdown
Collaborator Author

Free function with_cloned_context looks good to me.

I'm not sure about adding another abstraction via CheatsCtxExt trait for the moment, as the bounds are still subject to change (eg: FoundryContextExt support only Ethereum EVM). Let's stabilize this first? wdyt @figtracer

imo we should proceed with this if it makes sense atm, if anything changes we come back to it?

i believe that having this extra-bounded version of it can help to frame the problem in the future if that makes sense and we stack the more refined ergonomics on top of it

@figtracer figtracer force-pushed the fig/nested-evm-generic-factory branch 3 times, most recently from dad5c49 to af38a4b Compare March 7, 2026 07:54
Remove `get_inspector()` which returned `Box<dyn InspectorExt>` (Eth-bound).
Instead, the executor now assembles the inspector internally and owns
the entire operation:

- `with_nested_evm`: runs closure with nested EVM cloned from context
- `with_fresh_nested_evm`: runs closure with fresh EVM from raw db+env
- `transact_on_db`: replays historical transaction
- `transact_from_tx_on_db`: executes a TransactionRequest

`InspectorExt` no longer appears on the `CheatcodesExecutor` trait boundary.
It only lives inside the impl bodies of `InspectorStackInner` and
`TransparentCheatcodesExecutor`.
Remove `InspectorExt` from `NestedEvmExt` entirely. The trait now
handles only network-agnostic work (clone env + journal, split db
borrow, write back). Callers build their own EVM inside a callback
that receives `(&mut dyn DatabaseExt, Env, JournaledState)`.

- Remove `new_nested_evm` from `NestedEvmExt` (callers call
  `new_evm_with_inspector` directly)
- Remove `new_evm_with_existing_context` (dead code)
- Update `InspectorStackInner` and `TransparentCheatcodesExecutor`
  to build `FoundryEvm` inside the callback
- `CheatsCtxExt: NestedEvmExt` is now fully network-agnostic
@figtracer figtracer force-pushed the fig/nested-evm-generic-factory branch from af38a4b to c9493ac Compare March 7, 2026 07:56
@mattsse mattsse merged commit 2d5b0db into foundry-rs:master Mar 7, 2026
29 of 31 checks passed
@github-project-automation github-project-automation Bot moved this to Done in Foundry Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants