dapptools icon indicating copy to clipboard operation
dapptools copied to clipboard

Hevm abi encode

Open rainbreak opened this issue 3 years ago • 2 comments

Nearly complete. Fixes #861.

  • tuple types are now supported in arguments, as (...) or tuple(...) or Whatever(...)
  • the --abi argument for hevm now accepts solidity fragments as well as json
  • hevm abi -> output json for a given solidity fragment (functions, events and errors)
  • hevm normalise -> canonical signature for a given abi
  • hevm selector -> signature hash for a given abi (cc @mds1)
  • hevm abidecode -> decode calldata and/or returndata given an abi

Note:

  • Strings output from hevm abidecode, and therefore the results of seth call, will be quoted with "...". Previously string results were unquoted
  • Similarly, Arrays output from hevm abidecode are now wrapped in [...]. Previously the output was just comma separated elements.
  • Multi-dimensional array output was broken before, e.g. uint[][] [[1, 2], [3, 4]] was output as 1, 2, 3, 4. This is now fixed.
  • The new seth abi-encode was renamed to seth --abi-encode for consistency with --abi-decode and now outputs the full calldata including signature.

Todo:

  • [ ] consider event encode / decode (kind of annoying because of indexed args), which would allow seth --decode-events to use hevm
  • [ ] maybe SolidityAbi.hs should be part of an existing file (created to speed up compile times)
  • [ ] changelog
  • [ ] there was an existing simple parser for AbiTypes in Solidity.hs, which uses MegaParsec. I didn't touch this to avoid breaking something. The parser here uses ReadP, but there is duplicated functionality. Potentially the two could be combined.

rainbreak avatar Nov 22 '21 00:11 rainbreak

CI failing because I broke seth --abi-decode by parenthesising the output on a single line.

The current --abi-decode is broken though:

$ seth --abi-decode "f()(bool[][],uint)" 0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000
true,true,true,false
1

Here we should probably have instead:

[[true, true], [true, false]]
1

rainbreak avatar Nov 22 '21 05:11 rainbreak

lgtm

MrChico avatar Dec 07 '21 19:12 MrChico