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

Hevm abi encode #868

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/hevm/hevm-cli/hevm-cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,10 +1006,10 @@ abidecode (Just abi) (Just calldata) Nothing =
abiSelector = strip0x (selector sig)
(dataSelector, dataBody) =
ByteString.splitAt 4 (hexByteString "--calldata" $ strip0x $ calldata)
values = decodeAbiValue (AbiTupleType (V.fromList types)) (Lazy.fromStrict $ dataBody)
AbiTuple (values) = decodeAbiValue (AbiTupleType (V.fromList types)) (Lazy.fromStrict $ dataBody)
in
if (abiSelector == dataSelector) then
pack $ show values
pack $ intercalate "\n" (show <$> V.toList values)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
pack $ intercalate "\n" (show <$> V.toList values)
pack $ unlines (show <$> V.toList values)

and sim

else
error $ "abi and calldata signatures do not match."
<> "\nabi: " <> show (ByteStringS abiSelector)
Expand All @@ -1018,13 +1018,13 @@ abidecode (Just abi) (Just calldata) Nothing =
abidecode (Just abi) Nothing (Just returndata) =
let (_, types) = parseAbiOutputs abi
dataBody = hexByteString "--returndata" $ strip0x $ returndata
values = decodeAbiValue (AbiTupleType (V.fromList types)) (Lazy.fromStrict $ dataBody)
in pack $ show values
AbiTuple values = decodeAbiValue (AbiTupleType (V.fromList types)) (Lazy.fromStrict $ dataBody)
in pack $ intercalate "\n" (show <$> V.toList values)

abidecode (Just abi) (Just calldata) (Just returndata) =
let inputs = abidecode (Just abi) (Just calldata) Nothing
outputs = abidecode (Just abi) Nothing (Just returndata)
in inputs <> " -> " <> outputs
in inputs <> "\n->\n" <> outputs

abiselector :: String -> ByteString
abiselector abi = selector $ fst $ parseAbi abi
Expand Down
6 changes: 3 additions & 3 deletions src/seth/libexec/seth/seth---calldata-decode
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
### seth---abi-decode -- extract return values from hexdata
### Usage: seth --abi-decode <name>(<in-types>)(<out-types) <hexdata>
### seth---calldata-decode -- extract calldata values from hexdata
### Usage: seth --calldata-decode <name>(<in-types>)(<out-types) <hexdata>
###
### Decode <hexdata> according to <out-types> (<in-types> are ignored).
### Decode <hexdata> according to <in-types> (<out-types> are ignored).
hevm abidecode --abi "$1" --calldata "$2"
3 changes: 2 additions & 1 deletion src/seth/libexec/seth/seth-lookup-address
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ namehash=0x$(seth namehash $namein | cut -c3-)
ENS_REGISTRY=${SETH_ENS_REGISTRY:-'0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e'} # same on all supported networks
resolver=$(seth call $ENS_REGISTRY "resolver(bytes32)(address)" $namehash)
name=$(seth call $resolver "name(bytes32)(string)" $namehash)
name=${name//\"/} # dequote

# check the reverse direction and make sure the addresses match
address=$(seth resolve-name $name)
address=$(seth resolve-name "$name")
if [[ $(seth --to-hexdata $address) != $addressin ]]; then
seth --fail "${0##*/}: error: forward resolution of the found ENS name $name did not match"
fi
Expand Down