foundry
foundry copied to clipboard
feat(forge, cast): add RunArgs generate_local_signatures to enable trace with local contracts functions and events
Motivation
Supply a fast way to add all project contracts functions and events to signatures makes them decode correctly.
Solution
This PR introduces such a possibility using a cli argument --generate-local-signatures for cast run.
I updated my code. please check again @mattsse
how to proceed here @klkvr ?
So this can be broken into 2 separate usecases
-
Have a way to flush selectors from local project contracts into global signature cache (
forge build --cache_local_signatures
). Current impl lgtm, however, wondering if it makes more sense to beforge selectors cache
instead? -
Use local ABIs when decoding call trace from
cast run
. For this usecase I'd prefer a different implementation which would obtainProject
, compile it, constructknown_contracts
and include them in bothCallTraceDecoder
andTraceIdentifiers
similarly to how it's done inforge test
: https://github.com/foundry-rs/foundry/blob/b1b815123b625939b833a8b5bd68031448411f4b/crates/forge/bin/cmd/test/mod.rs#L402The motivation is that if we have an entire
Project
, then we can not only use artifacts for identification of selectors, but also to resolve return values of functions, and identify contracts by their bytecodes. ref https://github.com/foundry-rs/foundry/pull/6531 which had similar motivation
So this can be broken into 2 separate usecases
Have a way to flush selectors from local project contracts into global signature cache (
forge build --cache_local_signatures
). Current impl lgtm, however, wondering if it makes more sense to beforge selectors cache
instead?Use local ABIs when decoding call trace from
cast run
. For this usecase I'd prefer a different implementation which would obtainProject
, compile it, constructknown_contracts
and include them in bothCallTraceDecoder
andTraceIdentifiers
similarly to how it's done inforge test
: https://github.com/foundry-rs/foundry/blob/b1b815123b625939b833a8b5bd68031448411f4b/crates/forge/bin/cmd/test/mod.rs#L402The motivation is that if we have an entire
Project
, then we can not only use artifacts for identification of selectors, but also to resolve return values of functions, and identify contracts by their bytecodes. ref tracing: Improve decoding of functions output #6531 which had similar motivation
For case 1, I believe having helper options in forge build
and cast run
would make this feature more noticeable. I think adding a command to clear the cache would be useful because SignatureIdentifier merges matched signatures into the cache. My previous tests showed that if a local signature is matched, even if the parameters do not match, it still displays the matched function name.
For case 2, I have considered the solution you mentioned. However, the changes involved are quite extensive and a bit difficult for me, which is why I chose the current method. It allows me to get it working quickly.