Skip to content

feat(evm): bind Monad's journal state to ContextTr::Journal - #16262

Merged
figtracer merged 9 commits into
masterfrom
mablr/foundry-journal
Aug 20, 2026
Merged

feat(evm): bind Monad's journal state to ContextTr::Journal#16262
figtracer merged 9 commits into
masterfrom
mablr/foundry-journal

Conversation

@mablr

@mablr mablr commented Aug 19, 2026

Copy link
Copy Markdown
Member

Stacked on #16257.

FoundryEvmFactory/NestedEvm still carried a TransactionState associated type plus capture_transaction_state, restore_transaction_state, preserve_transaction_state_on_next_transaction methods that only Monad implements meaningfully, the same shape of leak #16257 already fixed for chain context. monad-revm's MonadJournal<DB> already wraps revm's Journal<DB> and exposes its reserve-balance tracker through MonadJournalTr, so this state doesn't need a bespoke side-channel: it's reachable through revm's native
ContextTr::journal/journal_mut.

This adds FoundryJournal, reached the same way FoundryChain reaches chain context. Unlike chain context, the reserve-balance tracker only exists on Monad's journal type, so its methods are concrete (ReserveBalanceTracker) and individually #[cfg(feature = "monad")]-gated rather than generic over an associated type. NestedEvm
gains a Journal: FoundryJournal associated type and a journal_mut() accessor, and a refresh_chain_dependent_state() hook (mirroring the one already on FoundryContextExt) to preserve the rebase-on-restore behavior the old bundled restore_transaction_state
provided.

BlockContext<FEN>/NEEDS_BLOCK_CONTEXT are unaffected and remain a separate, later scoping effort.

PR implementation was assisted by AI.

mablr added 7 commits August 19, 2026 16:31
Introduces ContextUpdateFor<F>, a type alias that resolves to
ContextUpdate<F::ChainContext> under the monad feature and to
PhantomData<F> otherwise, so DatabaseExt's fork-switching methods keep
one signature while the ContextUpdate enum, its construction sites,
and the block-position helpers that exclusively serve it become dead
code eliminated at compile time for non-Monad builds.

Consumption is centralized in a small apply_context_update helper
local to evm/fork.rs, co-located with its two callers, instead of
duplicating the Unchanged/Replace/Rebase match at each call site.
FoundryEvmFactory/NestedEvm carried a bespoke ChainContext associated
type plus capture/apply methods that only Monad ever implemented
meaningfully. revm already exposes an unconstrained Chain slot on
ContextTr with free chain()/chain_mut() accessors, and monad-revm
already plugs MonadChainContext directly into it.

Add FoundryChain, a marker trait bound on ContextTr::Chain (mirroring
FoundryBlock/FoundryTransaction), and a refresh_chain_dependent_state
hook on FoundryContextExt, default no-op, overridden only in Monad's
existing concrete FoundryContextExt impl to rebase its reserve-balance
tracker. Every call site now reads/writes the chain field directly and
calls the hook unconditionally instead of going through a
monad cfg gate from every one of those call sites.

Rename FoundryEvmFactory::ChainContext and NestedEvm::ChainContext to
Chain, and the ChainContextFor<FEN> alias to ChainFor<FEN>, matching
revm's own naming. FoundryChain only needs Clone + Debug + Default +
Send + Sync; 'static is not required by anything in the workspace.

Optimism's revm context already uses ContextTr::Chain for L1BlockInfo,
unrelated to Foundry's abstraction; OpEvmFactory::Chain is updated to
match reality instead of claiming ().
Introduce FoundryJournal, mirroring FoundryChain, so the reserve-balance
tracker Monad needs is reached through revm's native journal() /
journal_mut() accessors instead of bespoke capture/restore methods on
FoundryEvmFactory and NestedEvm. The tracker methods are concrete
(ReserveBalanceTracker) and individually feature-gated, so no Monad-only
associated type or method remains on those generic traits.
@github-actions

Copy link
Copy Markdown
Contributor

✅ Changelog found

The deterministic check will validate the changed entry.

mattsse
mattsse previously approved these changes Aug 19, 2026

@mattsse mattsse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

stevencartavia
stevencartavia previously approved these changes Aug 19, 2026
Base automatically changed from mablr/foundry-chain-journal to master August 19, 2026 19:18
@mablr
mablr dismissed stale reviews from stevencartavia and mattsse August 19, 2026 19:18

The base branch was changed.

@mablr mablr changed the title feat(evm): bind Monad's journal state to ContextTr::Journal feat(evm): bind Monad's journal state to ContextTr::Journal Aug 20, 2026
@figtracer
figtracer merged commit 96b61c4 into master Aug 20, 2026
43 checks passed
@figtracer
figtracer deleted the mablr/foundry-journal branch August 20, 2026 10:07
@github-project-automation github-project-automation Bot moved this to Done in Foundry Aug 20, 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.

4 participants