Skip to content
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

functionSelectors.js #318

Open
computerphysicslab opened this issue Jul 13, 2021 · 3 comments
Open

functionSelectors.js #318

computerphysicslab opened this issue Jul 13, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@computerphysicslab
Copy link
Contributor

Script in python or js to extend functionSignatures.sh, add params as needed, compute selectors (four bytes of the Keccak-256 or SHA-3 hash of the signature of the function)

@computerphysicslab computerphysicslab self-assigned this Jul 13, 2021
@computerphysicslab computerphysicslab added the enhancement New feature or request label Jul 13, 2021
@computerphysicslab
Copy link
Contributor Author

In order to quickly update current function and event selectors, I used this recipe, pending yet to develop a complete js script to do all the job by itself.

To get signatures from selectors, use keccak256.js script found at: f830aa9#diff-35603448485527fb547e0033f6c899e63235d8834924bbe3af371e548df6b73d
 
Pipeline code to get event signatures:

find . -type f -name '.sol' ! -path 'node_modules/' -print0 | xargs -0 sed -z "s///[^\n]\n//g" | awk '/event/,/;/' | sed "s/[[:space:]]+event/event/" | sed -z "s/\n[\t ]//g" | sed -z "s/;/;\n/g" | egrep "^event " | sed "s/ indexed / /g" | sed -E "s/(address|uint[0-9]+|bytes[0-9]|bool|string)([]) [^,\)]+/\1/g" | sed "s/event //" | sed -r "s/\s+//g" | xargs -0 node scripts/keccak256.js > eventSignatures.txt

Pipeline code to get function signatures:

find . -type f -name '.sol' ! -path 'node_modules/' -print0 | xargs -0 sed -z "s///[^\n]\n//g" | awk '/function/,/{/' | awk '/function/,/;/' | sed "s/[[:space:]]+function/function/" | sed -z "s/\n[\t ]//g" | sed -z "s/{/\n/g" | sed -z "s/;/\n/g" | egrep --text "^function " | egrep --text " (public|external) " | sed -E "s/(address|uint[0-9]+|bytes[0-9]|bool|string)([[0-9]])* [^,\)]+/\1/g" | sed "s/function //" | sed -r "s/ (public|external).*$//" | sed -r "s/\s+//g" | xargs -0 node scripts/keccak256.js > functionSignatures.txt

@computerphysicslab
Copy link
Contributor Author

Script is done! Updated event topics and function selector spreadsheet, now including AMM contracts as well:
https://docs.google.com/spreadsheets/d/16IOcLe3itNsG1fJjMrpTM802sZGd37hvb6I-leBYPUI/edit?usp=sharing

@computerphysicslab
Copy link
Contributor Author

Pending to fix 3 issues:
1.- On function signatures, interfaces should be typed as addresses.
2.- On function signatures, structs should be exploded into their components, around brackets ()
3.- According to the list swapExternal(address,address,address,address,uint256,uint256,bytes) has selector: 0x11058a8a
According to vscode: e321b540 => swapExternal(address,address,address,address,uint256,uint256,uint256,bytes)
It has an additional parameter. This case should be debugged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant