Skip to content

feat: collect local abis for --print-traces #11081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

mattsse
Copy link
Member

@mattsse mattsse commented Jul 23, 2025

followup for

#11070

introduces a new anvil cli arg to provide the corresponding forge project.
if --print-traces, this record all abis.

introduces a new readiterator that reuses a string buffer because we can have a few of those and these are quite large.

cc @joshieDo

.and_then(|root| Config::load_with_root(root).ok())
.or_else(|| Config::load().ok())
{
let out = config.root.join(config.out);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wonder if instead collecting abis like this we should do the same as in cast and build project / use output (that is if project doesn't have any changes it will not be rebuilt, otherwise it will and will reflect current code)

    let project = config.project()?;
    let compiler = ProjectCompiler::new();
    let output = compiler.compile(&project)?;
    let known_contracts = ContractsByArtifact::new(
        output.artifact_ids().map(|(id, artifact)| (id, artifact.clone().into())),
    );
    decoder_builder = decoder_builder.with_known_contracts(&known_contracts);

This approach will also allow us to use contracts bytecode to identify them in traces, similar with

let mut identifier = TraceIdentifiers::new().with_etherscan(config, chain)?;
if let Some(contracts) = &known_contracts {
builder = builder.with_known_contracts(contracts);
identifier = identifier.with_local_and_bytecodes(contracts, contracts_bytecode);
}
let mut decoder = builder.build();
for (_, trace) in result.traces.as_deref_mut().unwrap_or_default() {
decoder.identify(trace, &mut identifier);
}

so we could nicely print in Anvil

Traces:
  [22418] Counter::increment()
    ├─  storage changes:
    │   @ 0: 0 → 1
    └─ ← [Stop]

instead

Traces:
  [22418] 0x5FbDB2315678afecb367f032d93F642f64180aa3::increment()
    ├─  storage changes:
    │   @ 0: 0 → 1
    └─ ← [Stop]

I can add these updates to PR if you OK with them / don't see any side effect

Copy link
Collaborator

Choose a reason for hiding this comment

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

or maybe not until this fixed #11084

Copy link
Member Author

Choose a reason for hiding this comment

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

great idea, that would be better, I only worried about having to actually compile the project first

@grandizzy
Copy link
Collaborator

closing for now, as forge selectors cache could be used to the same effect

@grandizzy grandizzy closed this Jul 25, 2025
@github-project-automation github-project-automation bot moved this to Done in Foundry Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-anvil Command: anvil T-feature Type: feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants