Skip to content

Commit ef98a5e

Browse files
committed
evm: Add verify script
1 parent ee1115c commit ef98a5e

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

evm/sh/verify.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
# Sample usage:
4+
# Sepolia: sh/verify.sh -r https://1rpc.io/sepolia 0x130e32c0B5B9c9823AAc21d7c53c753240Fd71e2
5+
# Base Sepolia: sh/verify.sh -r https://sepolia.base.org 0xb583a345f609bAbbB69ef96925BA13dea5152e34
6+
# Avalanche Fuji: sh/verify.sh -r https://rpc.ankr.com/avalanche_fuji 0xecabED02d566a6865Feb0C575375208d02D6bDf2
7+
8+
function usage() {
9+
cat <<EOF >&2
10+
Usage:
11+
12+
$(basename "$0") [-h][-r rpc] <contract address> -- Verify that the deployed on-chain bytecode matches the local build artifact
13+
14+
where:
15+
-h show this help text
16+
-r rpc url
17+
EOF
18+
exit 1
19+
}
20+
21+
while getopts ':hn:r:c:' option; do
22+
case "$option" in
23+
h) usage
24+
;;
25+
c) chain=$OPTARG
26+
;;
27+
n) network=$OPTARG
28+
;;
29+
r) rpc=$OPTARG
30+
;;
31+
:) printf "missing argument for -%s\n" "$OPTARG" >&2
32+
usage
33+
;;
34+
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
35+
usage
36+
;;
37+
esac
38+
done
39+
shift $((OPTIND - 1))
40+
[ $# -ne 1 ] && usage
41+
42+
json_file=out/Executor.sol/Executor.json
43+
contract_addr=$1
44+
45+
set -euo pipefail
46+
47+
# We'll write the bytecodes to temporary files
48+
deployed=$(mktemp)
49+
local=$(mktemp)
50+
51+
cat "$json_file" | jq -r .deployedBytecode | jq -r .object > "$local"
52+
53+
ret=0
54+
# Grab bytecode from the JSON RPC using the eth_getCode method.
55+
56+
curl "$rpc" \
57+
-X POST \
58+
-H "Content-Type: application/json" \
59+
--data "{\"method\":\"eth_getCode\",\"params\":[\"$contract_addr\",\"latest\"],\"id\":1,\"jsonrpc\":\"2.0\"}" --silent | jq -r .result > "$deployed" || ret=$?
60+
61+
if [ $ret -gt 0 ]; then
62+
printf "\033[0;31mFailed to query eth RPC '%s' while verifying %s on %s\033[0m\n" "$rpc" "$contract_addr"
63+
exit 1
64+
fi
65+
66+
echo "Deployed: " `cat $deployed`
67+
echo "Local: " `cat $local`
68+
69+
# hash, then see if they match up
70+
hash1=$(sha256sum "$deployed" | cut -f1 -d' ')
71+
hash2=$(sha256sum "$local" | cut -f1 -d' ')
72+
73+
if [ "$hash1" == "$hash2" ]; then
74+
printf "\033[0;32mDeployed bytecode of %s on %s matches %s\033[0m\n" "$contract_addr" "$json_file";
75+
exit 0;
76+
else
77+
printf "\033[0;31mDeployed bytecode of %s on %s doesn't match %s\033[0m\n" "$contract_addr" "$json_file";
78+
echo "deployed hash:"
79+
echo "$hash1"
80+
echo "$json_file hash:"
81+
echo "$hash2"
82+
exit 1;
83+
fi

0 commit comments

Comments
 (0)