-
Notifications
You must be signed in to change notification settings - Fork 322
seth: add function selector and calldata encoding/decoding helpers #757
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
Conversation
src/seth/libexec/seth/seth-selector
Outdated
@@ -0,0 +1,11 @@ | |||
#!/usr/bin/env bash |
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.
duplicate of seth sig
?
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.
Heh, yes, didn't see that one. Will remove this one
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.
one thing that always bothered me about sig
, it's very literal... withdraw(uint)
is not the same as withdraw(uint256)
, whereas other functions will correctly account for this, such as seth call 0x.. 'something(uint)' 0x0
. But can be left for another day :P
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.
one thing that always bothered me about
sig
, it's very literal...withdraw(uint)
is not the same aswithdraw(uint256)
, whereas other functions will correctly account for this, such asseth call 0x.. 'something(uint)' 0x0
. But can be left for another day :P
would it be possible to fix this just by replacing uses of standalone uint
with uint256
? It's the only type with that behavior iirc
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.
I'll look into how seth call
does it, but worst case it should be easy to find/replace uint
and int
with uint256
and int256
before hashing
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.
the memory
bs also screws it up
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.
Good call, just pushed a version of seth sig
that will behave the same as seth call
### Usage: seth 4byte-decode <calldata> | ||
### | ||
### Querys 4byte.directory to find matching signatures and prompts the user to to select one. The selected | ||
### signature will be used to decode the calldata. |
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.
could be nice to have an --optimistic
(I feel lucky) flag to this if we wanna build some larger pipeline where we can't be interactive
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.
I was thinking that too, just wasn't sure of how we'd want to do it. You can sometimes deduce which sig is the correct one from the calldata, but that can get hairy for complex sigs, and you can't always deduce it
For now I learn towards a simpler approach of having --optimistic
use the oldest sig 4byte.directory has. Anecdotally this seems to often be the desired one (or at least it was the for the ERC20 methods I used for testing)
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.
wdyt about a --id
flag that accepts either an id number or earliest
/latest
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.
Hmm, what would be the use case for specifying an ID? If you know the ID then presumably you also know the function signature, meaning you could use seth --calldata-decode
instead of seth 4byte-decode
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.
meh mainly for the ability to specify earliest
/latest
and id is shorter than using the full sig 🤷
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.
That seems reasonable enough to me, being able to toggle earliest/latest is nice
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.
Would love some help with my --id
flag here. In f45ee07 I pushed an attempt that works if I set the env var manually but not with the --id
flag
that and `int` to `int256` I believe
…On Tue, Aug 31, 2021 at 6:44 PM t11s ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/seth/libexec/seth/seth-selector
<#757 (comment)>:
> @@ -0,0 +1,11 @@
+#!/usr/bin/env bash
one thing that always bothered me about sig, it's very literal...
withdraw(uint) is not the same as withdraw(uint256), whereas other
functions will correctly account for this, such as seth call 0x..
'something(uint)' 0x0. But can be left for another day :P
would it be possible to fix this just by replacing uses of standalone uint
with uint256? It's the only type with that behavior iirc
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#757 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAM2HT2VVIVMGGTNUQHOVTT7VSPVANCNFSM5DFBN7XQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
356811b
to
f45ee07
Compare
src/seth/libexec/seth/seth-slot
Outdated
@@ -0,0 +1,18 @@ | |||
#!/usr/bin/env bash | |||
### seth-slot -- Prints the slot number for the specified mapping type and input data |
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.
slot
seems too generic for what this actually is imo 😅
wdyt about changing to mapping-slot
or somethin?
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.
I vote seth index
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.
i like it!
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.
seth index
it will be! Sorry for the delay here, hoping to finish this PR up this week
Ok everything should now be working and ready for review/testing! |
src/seth/README.md
Outdated
Show the timestamp of a block (the latest block by default). | ||
|
||
seth age [--block <block>] |
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.
Looks like a lil copy / paste error here...
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.
Fixed in d523c2e
### seth-index -- Prints the slot number for the specified mapping type and input data | ||
### Usage: seth index <fromtype> <totype> <fromvalue> <slot> [<lang>] | ||
### | ||
### Prints the slot number for the specified mapping type and input data. For example, | ||
### the balances mapping in DAI is slot 2, so to find the slot where the balance | ||
### is stored for <account>, use | ||
### seth-index address uint256 <account> 2 |
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.
Can we document the allowed values for <lang>
here pls
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.
Done in d523c2e
### seth-index address uint256 <account> 2 | ||
|
||
set -e | ||
|
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.
Can we print usage info we don't have the expected number of params, right now if I run seth index
it shows a fairly inscrutable error from hevm
:
> seth index
hevm: wrong number of arguments:0: []
CallStack (from HasCallStack):
error, called at hevm-cli/hevm-cli.hs:984:11 in main:Main
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.
Done in d523c2e
src/seth/libexec/seth/seth-index
Outdated
set -e | ||
|
||
if [[ $5 = 'vyper' || $5 = 'vy' || $5 = 'v' ]]; then | ||
# note: not guaranteed to work for all Vyper versions since storage layout is not yet stable |
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.
Is it maybe worth putting some warning on std err here?
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.
Added in d523c2e
@@ -0,0 +1,12 @@ | |||
#!/usr/bin/env bash | |||
### seth-abi-encode -- ABI encode values, and prints the encoded values without the function signature | |||
### Usage: seth abi-encode <sig> [<args>] |
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.
Does it make sense to accept a tuple of types and then automatically add some dummy function signature just as an internal implementation detail?
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.
You could, but IMO we should keep the current sig
input format since it's more familiar (i.e. used in other seth methods) and as a result more composable with other methods (i.e. outputs from the 4byte methods).
Also noticed a docs issue with this command, so fixed in d523c2e
These are very nice! Thanks a lot ✨ Can you please add a changelog entry with the new commands? |
@d-xo addressed all your comments! |
Leaving this as a draft until I add docs to the README / review the existing comments.
Also looking for feebdack on the method names and syntaxes, e.g.
seth slot
feels a bit clunky to me, but I don't think there's a more concise way to generalize this