forked from wormhole-foundation/wormhole
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify
executable file
·187 lines (170 loc) · 6.57 KB
/
verify
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
set -euo pipefail
usage="Usage:
$(basename "$0") [-h] [-n network] [-c chain] [-w .wasm file] [-i code id || -a contract address] -- Verify that the deployed on-chain bytecode matches the local object file
where:
-h show this help text
-n set the network (mainnet, testnet, devnet. defaults to \$NETWORK if set)
-c set the chain (terra, terra2, injective, xpla)
-w set the .wasm file to verify against
-i set the code id of the stored wasm contract on chain
-a set the on chain address of the contract to verify"
chain=""
network=""
wasm=""
code_id=""
contract_addr=""
if [[ ! -z "${NETWORK+x}" ]]; then
network=$NETWORK
fi
while getopts ':hn:c:i:w:a:' option; do
case "$option" in
h) echo "$usage"
exit
;;
n) network=$OPTARG
;;
c) chain=$OPTARG
;;
w) wasm=$OPTARG
;;
i) code_id=$OPTARG
;;
a) contract_addr=$OPTARG
;;
:) printf "missing argument for -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
if [[ -z $code_id && -z $contract_addr ]]; then
printf "Need one of the -i and -a parameters to be specified.\n" >&2
echo "$usage" >&2
exit 1
fi
if [[ ! -z $code_id && ! -z $contract_addr ]]; then
printf "Both of the -i and -a parameters cannot be specified.\n" >&2
echo "$usage" >&2
exit 1
fi
if [[ -z $chain || -z $network || -z $wasm ]]; then
printf "The -c, -n, and -w parameters are required.\n" >&2
echo "$usage" >&2
exit 1
fi
url=""
jq_cmd=""
code_id_url=""
code_id_jq=""
# Fill in the above values based on network and chain
case "$network" in
mainnet)
case "$chain" in
terra) url="https://columbus-lcd.terra.dev/terra/wasm/v1beta1/codes/"
jq_cmd="jq '.code_info.code_hash' -r | base64 -d | hexdump -v -e '/1 \"%02x\" '"
code_id_url="https://columbus-lcd.terra.dev/terra/wasm/v1beta1/contracts/"
code_id_jq="jq '.contract_info.code_id' -r "
;;
terra2) url="https://phoenix-lcd.terra.dev/wasm/code/"
jq_cmd="jq '.result.data_hash' -r "
code_id_url="https://phoenix-lcd.terra.dev/wasm/contract/"
code_id_jq="jq '.result.code_id' -r "
;;
xpla) url="https://dimension-lcd.xpla.dev/cosmwasm/wasm/v1/code/"
jq_cmd="jq '.code_info.data_hash' -r "
code_id_url="https://dimension-lcd.xpla.dev/cosmwasm/wasm/v1/contract/"
code_id_jq="jq '.contract_info.code_id' -r"
;;
injective)
url="https://k8s.mainnet.lcd.injective.network/cosmwasm/wasm/v1/code/"
jq_cmd="jq '.code_info.data_hash' -r | cut -d 'x' -f2"
code_id_url="https://k8s.mainnet.lcd.injective.network/cosmwasm/wasm/v1/contract/"
code_id_jq="jq '.contract_info.code_id' -r"
;;
esac ;;
testnet)
case "$chain" in
terra2) url="https://pisco-lcd.terra.dev/wasm/code/"
jq_cmd="jq '.result.data_hash' -r "
code_id_url="https://pisco-lcd.terra.dev/wasm/contract/"
code_id_jq="jq '.result.code_id' -r "
;;
injective) url="https://k8s.testnet.exchange.grpc-web.injective.network/api/explorer/v1/wasm/codes/"
jq_cmd="jq '.checksum.hash' -r | cut -d 'x' -f2"
code_id_url="https://k8s.testnet.lcd.injective.network/cosmwasm/wasm/v1/contract/"
code_id_jq="jq '.contract_info.code_id' -r"
;;
xpla) url="https://cube-lcd.xpla.dev/cosmwasm/wasm/v1/code/"
jq_cmd="jq '.code_info.data_hash' -r "
code_id_url="https://cube-lcd.xpla.dev/cosmwasm/wasm/v1/contract/"
code_id_jq="jq '.contract_info.code_id' -r "
;;
esac ;;
devnet)
case "$chain" in
terra) url="http://localhost:1317/terra/wasm/v1beta1/codes/"
jq_cmd="jq '.code_info.code_hash' -r | base64 -d | hexdump -v -e '/1 \"%02x\" '"
;;
terra2) url="http://localhost:1318/terra/wasm/v1beta1/codes/"
jq_cmd="jq '.code_info.code_hash' -r | base64 -d | hexdump -v -e '/1 \"%02x\" '"
;;
esac ;;
*) printf "Network not set. Specify with -n\n" >&2
echo "$usage" >&2
exit 1
;;
esac
if [[ -z $url ]]; then
printf "The combination of $network and $chain is not supported.\n" >&2
exit 1
fi
if [[ ! -z $contract_addr && -z $code_id_url ]]; then
printf "There is no contract to code_id conversion for the combination of $network and $chain.\n" >&2
exit 1
fi
if [[ ! -z $contract_addr ]]; then
code_id=`curl "$code_id_url$contract_addr" --silent | eval $code_id_jq`
printf "Found code_id $code_id\n"
fi
hash1=`curl "$url$code_id" --silent | eval $jq_cmd | tr '[:upper:]' '[:lower:]'`
hash2=`sha256sum $wasm | cut -f1 -d' ' | tr '[:upper:]' '[:lower:]'`
echo "Deployed bytecode hash (on $network):"
echo $hash1
echo "$wasm hash:"
echo $hash2
if [[ "$hash1" == "$hash2" ]]; then
printf "\033[0;32mSuccessfully verified\033[0m\n";
exit 0;
else
printf "\033[0;31mFailed to verify\033[0m\n";
exit 1;
fi
# Test Cases:
# Terra:
# Mainnet: wormhole code id = 557, tokenBridge code id = 6097
# Mainnet: wormhole contract address = terra1dq03ugtd40zu9hcgdzrsq6z2z4hwhc9tqk2uy5
# Mainnet: tokenBridge contract Address = terra10nmmwe8r3g99a9newtqa7a75xfgs2e8z87r2sf
# Terra2:
# Mainnet: wormhole code id = 146, tokenBridge code id = 151
# Mainnet: wormhole contract address = terra12mrnzvhx3rpej6843uge2yyfppfyd3u9c3uq223q8sl48huz9juqffcnhp
# Mainnet: tokenBridge contract address = terra153366q50k7t8nn7gec00hg66crnhkdggpgdtaxltaq6xrutkkz3s992fw9
# Testnet: wormhole code id = 890, tokenBridge code id = 4773
# Testnet: wormhole contract address = terra19nv3xr5lrmmr7egvrk2kqgw4kcn43xrtd5g0mpgwwvhetusk4k7s66jyv0
# Testnet: tokenBridge contract address = terra1c02vds4uhgtrmcw7ldlg75zumdqxr8hwf7npseuf2h58jzhpgjxsgmwkvk
# Injective:
# Testnet: wormhole code id = 126, tokenBridge code id = 124
# Testnet: wormhole contract address = inj1xx3aupmgv3ce537c0yce8zzd3sz567syuyedpg
# Testnet: tokenBridge contract address = inj1q0e70vhrv063eah90mu97sazhywmeegp7myvnh
# Xpla:
# Mainnet: wormhole code id = 10, tokenBridge code id = 13
# Mainnet: wormhole contract address = xpla1jn8qmdda5m6f6fqu9qv46rt7ajhklg40ukpqchkejcvy8x7w26cqxamv3w
# Mainnet: tokenBridge contract address = xpla137w0wfch2dfmz7jl2ap8pcmswasj8kg06ay4dtjzw7tzkn77ufxqfw7acv
# Testnet: wormhole code id = 53, tokenBridge code id = 135
# Testnet: wormhole contract address = xpla1upkjn4mthr0047kahvn0llqx4qpqfn75lnph4jpxfn8walmm8mqsanyy35
# Testnet: tokenBridge contract address = xpla1kek6zgdaxcsu35nqfsyvs2t9vs87dqkkq6hjdgczacysjn67vt8sern93x