-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat(cast): add selectors
command to extract function selectors and arguments from bytecode
#6684
Conversation
…ents from bytecode using the evmole library
I've fixed fmt issue, checked by |
Failed clippy check is not related to changes in this PR, same on foundry |
I have wanted this sort of functionality in |
@tynes selectors lookup is possible, but it will require a little refactoring in the existing code. Currently, decode_selector accepts only one selector in arguments, but the openchain.xyz API allows multiple selectors in one request (I use this feature in the evmole demo), and it greatly speeds up the entire process. I can work on it, but I think it should be a different MR/Issue after this one is merged. At this moment, we can use something like this:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Evalir I've already begun implementing signatures lookup. What do you think would be better – opening a "Feature request" issue now, or waiting until everything is ready for a pull request (probably in a couple of days)? I have a question regarding the interface stability of the foundry-common crate. Am I allowed to modify the interface of public functions, such as decode_selector? It seems to be an internal crate with an empty package on crates.io, and it is not intended for external dependencies beyond the Foundry project, am I right? |
… arguments from bytecode (foundry-rs#6684) * add evmole library to dependencies * cast: add 'selectors' command to extract function selectors and arguments from bytecode using the evmole library
Motivation
Sometimes, you don't have the source code/ABI for the contract but want to determine which functions exist, having only the deployed bytecode.
Solution
I am the author of the EVMole library, which addresses this problem. The library includes reproducible benchmarks for accuracy and speed, along with a comparison with other existing tools.
In this PR, I have added the
selectors
command to thecast
tool, which uses my library for the task.Example of using
cast code
to obtain the bytecode of the USD-T contract andcast selectors
to extract selectors and arguments:$ cast selectors $(cast code 0xdAC17F958D2ee523a2206206994597C13D831ec7) 0x06fdde03 0x0753c30c address 0x095ea7b3 address,uint256 0x0e136b19 0x0ecb93c0 address 0x18160ddd 0x23b872dd address,address,uint256 0x26976e3f 0x27e235e3 address 0x313ce567 0x35390714 0x3eaaf86b 0x3f4ba83a 0x59bf1abe address 0x5c658165 address,address 0x5c975abb 0x70a08231 address 0x8456cb59 0x893d20e8 0x8da5cb5b 0x95d89b41 0xa9059cbb address,uint256 0xc0324c77 uint256,uint256 0xcc872b66 uint256 0xdb006a75 uint256 0xdd62ed3e address,address 0xdd644f72 0xe47d6060 address 0xe4997dc5 address 0xe5b5019a 0xf2fde38b address 0xf3bdc228 address