cast: Improve debugger when tracing on-chain transactions/calls #10596
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The current debugger provided in
cast
is great, but it currently cannot show the source file of local contracts incast run
(for example).It seems that it can only match contracts to source code, whether from Etherscan (but this requires both an API key, and a verified contract), or locally via
--with-local-artifacts
. However, w/--with-local-artifacts
, it only matches the contracts for which the deployment is within the same transaction, to get both the deployment bytecode, as well as the runtime one.Solution
A simple solution to this problem (first commit), is to actually fetch the bytecode of all addresses involved in a trace, to pass it along to the local identifier. This is done for both
cast run
(which I guess already has all bytecodes available, since it re-executes the tx), as well ascast call
, for which I'm unsure if it's a good default, or should it be behind a flag?Another issue arose, for contracts using libraries. For those, the bytecode isn't convertible to
bytes
, as it has placeholders. A simple solution is to replace all those placeholders w/ the0x00.00
address, which should still yield some good matching score. It's also used in the sourcemap generation, in which the actual value of the library's address isn't needed anyway.Reproduction
Clone the morpho-blue repo: https://github.com/morpho-org/morpho-blue and
cast run --with-local-artifacts -r "<NODE_URL>" --debug 0x32fbce9a55b5b13d65fc5a359d40d742812d409df6c4a7483db3a18f0b8e3d22
and go through the calls until the first call to
0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb
The tx https://etherscan.io/tx/0x32fbce9a55b5b13d65fc5a359d40d742812d409df6c4a7483db3a18f0b8e3d22 calls the Morpho Blue contract in the 5th call, which shows no matching contract on
master
, but properly shows the contract source code on this branch.Same with
PR Checklist
I haven't added any tests yet, as I wanted to hear from maintainers first on the PR's logic/structure.