foundry icon indicating copy to clipboard operation
foundry copied to clipboard

feat(cast): trace and debug on local contracts

Open fnerdman opened this issue 1 year ago • 2 comments

Motivation

Using cast run and cast call to trace and debug can currently only fetch abi and source from explorers such as etherscan. In situations where no explorer is available, it would be intuitive to use the abi and source provided by the local files.

Solution

As with forge debug - using local files is preferred over fetching data from remote explorer. Only if etherscan_api_key is defined, will we fetch abi and source from the explorer. Without explorer it will now compile solidity files and fetch contract bytecode from build output. To identify contract addresses it fetches on chain bytecode via RPC call. Most of the required code change happens in handle_traces, where the decoder and debugger is fed with the required data fetched from local files (and RPC).

Unresolved issues

  • Debugging on inherited contracts does not resolve to the respective source code.
  • Can we use existing build artifacts instead of running the builder each time? This also solves the problem where the building source requires additional parameters.

fnerdman avatar Jan 23 '24 13:01 fnerdman

Related issues: https://github.com/foundry-rs/foundry/issues/5435, https://github.com/foundry-rs/foundry/issues/5410, https://github.com/foundry-rs/foundry/issues/4440, https://github.com/foundry-rs/foundry/issues/3498

Ruteri avatar Jan 23 '24 16:01 Ruteri

#7058 should fix inherited sourcemaps 🫡

emo-eth avatar Feb 09 '24 07:02 emo-eth

Hi @fnerdman thanks for your PR! Are there any blockers currently preventing this from marking it ready for review? Would be great to get this in.

zerosnacks avatar Jul 31 '24 11:07 zerosnacks

@zerosnacks while it definitely would be nice to have this, my focus has moved on and I don't have the time to get this cleaned up. Happy though if someone else pulls the changes and takes the lead.

fnerdman avatar Aug 01 '24 10:08 fnerdman

No problem! Thanks for your contribution. I've opened a ticket here: https://github.com/foundry-rs/foundry/issues/8581 matching the description and goal of the PR so it can be picked up in the future

zerosnacks avatar Aug 01 '24 10:08 zerosnacks