This repository has been archived by the owner on Jan 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
etherscan-verify
executable file
·84 lines (64 loc) · 2.83 KB
/
etherscan-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
#!/usr/bin/env bash
# Copyright (c) 2022 Espresso Systems (espressosys.com)
# This file is part of the Configurable Asset Privacy for Ethereum (CAPE) library.
#
# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Verify contracts on etherscan.
#
# See "Etherscan verification" section in README.md for usage instructions.
set -euo pipefail
NETWORK=$1
function get_addr() {
cat contracts/deployments/$NETWORK/$1.json | jq -r .address
}
function get_args() {
cat contracts/deployments/$NETWORK/$1.json | jq -r '.args| join(" ")'
}
VERIFYING_KEYS_ADDRESS=$(get_addr VerifyingKeys)
RESCUE_LIB_ADDRESS=$(get_addr RescueLib)
VERIFIER_ADDRESS=$(get_addr PlonkVerifier)
RECORS_MERKLE_TREE_ADDRESS=$(get_addr RecordsMerkleTree)
RECORS_MERKLE_TREE_ARGS=$(get_args RecordsMerkleTree)
CAPE_ADDRESS=$(get_addr CAPE)
CAPE_CONSTRUCTOR_ARGS=$(get_args CAPE)
# Has to be a file with .js extension.
LIBRARIES="$(mktemp -t "cape-libraries-XXXXXXXX.js")"
cat <<EOF > $LIBRARIES
module.exports = $(cat contracts/deployments/$NETWORK/CAPE.json | jq -r '.libraries')
EOF
# Often the two libraries are already verified because of a previous deployment.
# Therefore try to verify the remaining contracts in case of failures.
# Don't abort on error.
set +e
function ensure_verified() {
output="$($@ 2>&1)"
status=$?
if [ $status -eq 0 ]; then
echo "Contract sucessfully verified."
elif echo "$output" | grep -q "Contract source code already verified"; then
echo "Contract already verified."
else
echo "$output"
echo
echo "Something went wrong when running \"$@\."
echo "Aborting."
exit 1
fi
}
echo "Removing old artifacts."
rm -rf contracts/artifacts
echo Verifying RescueLib
ensure_verified hardhat verify --network $NETWORK $RESCUE_LIB_ADDRESS
echo Verifying VerifyingKeys
ensure_verified hardhat verify --network $NETWORK $VERIFYING_KEYS_ADDRESS
echo Verifying PlonkVerifier
ensure_verified hardhat verify --network $NETWORK $VERIFIER_ADDRESS
echo Verifying RecordsMerkleTree
ensure_verified hardhat verify --network $NETWORK $RECORS_MERKLE_TREE_ADDRESS $RECORS_MERKLE_TREE_ARGS
echo Verifying CAPE
ensure_verified hardhat verify --network $NETWORK --libraries $LIBRARIES $CAPE_ADDRESS $CAPE_CONSTRUCTOR_ARGS
set -e
echo "All contracts verified!"