Skip to content

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

Merged
merged 9 commits into from
Sep 12, 2021

Conversation

mds1
Copy link
Contributor

@mds1 mds1 commented Aug 31, 2021

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

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate of seth sig?

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor

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

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

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

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.
Copy link
Member

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

Copy link
Contributor Author

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)

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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 🤷

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@nanexcool
Copy link
Contributor

nanexcool commented Aug 31, 2021 via email

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
### seth-slot -- Prints the slot number for the specified mapping type and input data
Copy link
Contributor

@transmissions11 transmissions11 Sep 6, 2021

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote seth index

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like it!

Copy link
Contributor Author

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

@mds1 mds1 marked this pull request as ready for review September 9, 2021 22:24
@mds1
Copy link
Contributor Author

mds1 commented Sep 9, 2021

Ok everything should now be working and ready for review/testing!

Comment on lines 673 to 675
Show the timestamp of a block (the latest block by default).

seth age [--block <block>]
Copy link
Contributor

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...

Copy link
Contributor Author

@mds1 mds1 Sep 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d523c2e

Comment on lines +2 to +8
### 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
Copy link
Contributor

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

Copy link
Contributor Author

@mds1 mds1 Sep 12, 2021

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

Copy link
Contributor

@d-xo d-xo Sep 12, 2021

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

Copy link
Contributor Author

@mds1 mds1 Sep 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d523c2e

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
Copy link
Contributor

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?

Copy link
Contributor Author

@mds1 mds1 Sep 12, 2021

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>]
Copy link
Contributor

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?

Copy link
Contributor Author

@mds1 mds1 Sep 12, 2021

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

@d-xo
Copy link
Contributor

d-xo commented Sep 12, 2021

These are very nice! Thanks a lot ✨

Can you please add a changelog entry with the new commands?

@mds1
Copy link
Contributor Author

mds1 commented Sep 12, 2021

@d-xo addressed all your comments!

@d-xo d-xo merged commit c26db40 into dapphub:master Sep 12, 2021
@mds1 mds1 mentioned this pull request Oct 7, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants