Skip to content

Commit 8a93493

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

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

evm/sh/verify.sh

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

0 commit comments

Comments
 (0)