Skip to content

Conversation

w1tcher
Copy link
Contributor

@w1tcher w1tcher commented Sep 18, 2025

Motivation

This commit introduces support for the PreStateTracer in anvil's
debug_traceTransaction RPC method. With this change, users can now
obtain detailed pre-state information (accounts, storage, and balances)
when tracing transactions, enabling more advanced debugging and state
analysis workflows.

Solution

By storing the state changes generated during transaction execution in the exec_state variable, the PreStateTracer can later retrieve this data and return the relevant information.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

@w1tcher thank you! please rebase and add a test, here are some samples

async fn test_call_tracer_debug_trace_call() {

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.

while this works, this is mega extra overhead on top of the overhead of recorded traces that we already have

imo we should instead cleanup the existing replay functionality that we use for the js tracer and make this general purpose replay

@mattsse mattsse self-assigned this Sep 19, 2025
@mattsse mattsse added the C-anvil Command: anvil label Sep 19, 2025
@w1tcher
Copy link
Contributor Author

w1tcher commented Sep 19, 2025

@grandizzy I have added test cases.

mattsse
mattsse previously approved these changes Sep 23, 2025
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.

this is pretty neat

tysm for this.

while the actually replay+trace impl isnt super nice to read, it's fine imo
still something we can take another look at, but out of scope for this pr.

pending @grandizzy

Comment on lines +2673 to +2678
where
for<'a> I: Inspector<EthEvmContext<WrapDatabaseRef<&'a CacheDB<Box<&'a StateDb>>>>>
+ Inspector<OpContext<WrapDatabaseRef<&'a CacheDB<Box<&'a StateDb>>>>>
+ 'a,
for<'a> F:
FnOnce(ResultAndState<OpHaltReason>, CacheDB<Box<&'a StateDb>>, I, TxEnv, Env) -> T,
Copy link
Member

Choose a reason for hiding this comment

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

these are a bit horrific, but not much we can do here :D

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

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

thank you, lgtm!

@grandizzy grandizzy enabled auto-merge (squash) September 24, 2025 04:56
@grandizzy grandizzy merged commit ad1f9ab into foundry-rs:master Sep 24, 2025
25 checks passed
@github-project-automation github-project-automation bot moved this to Done in Foundry Sep 24, 2025
@grandizzy grandizzy moved this from Done to Completed in Foundry Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-anvil Command: anvil
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

debug_traceTransaction should support tracer=prestateTracer
3 participants