foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feat(forge, cast): add RunArgs generate_local_signatures to enable trace with local contracts functions and events

Open byteshijinn opened this issue 11 months ago • 1 comments

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.

byteshijinn avatar Mar 10 '24 14:03 byteshijinn

I updated my code. please check again @mattsse

byteshijinn avatar Mar 17 '24 14:03 byteshijinn

how to proceed here @klkvr ?

mattsse avatar Jul 09 '24 14:07 mattsse

So this can be broken into 2 separate usecases

  1. 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 be forge selectors cache instead?

  2. Use local ABIs when decoding call trace from cast run. For this usecase I'd prefer a different implementation which would obtain Project, compile it, construct known_contracts and include them in both CallTraceDecoder and TraceIdentifiers similarly to how it's done in forge test: https://github.com/foundry-rs/foundry/blob/b1b815123b625939b833a8b5bd68031448411f4b/crates/forge/bin/cmd/test/mod.rs#L402

    The 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

klkvr avatar Jul 09 '24 15:07 klkvr

So this can be broken into 2 separate usecases

  1. 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 be forge selectors cache instead?

  2. Use local ABIs when decoding call trace from cast run. For this usecase I'd prefer a different implementation which would obtain Project, compile it, construct known_contracts and include them in both CallTraceDecoder and TraceIdentifiers similarly to how it's done in forge test: https://github.com/foundry-rs/foundry/blob/b1b815123b625939b833a8b5bd68031448411f4b/crates/forge/bin/cmd/test/mod.rs#L402

    The 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.

byteshijinn avatar Jul 12 '24 14:07 byteshijinn