wormhole/scripts/register-chain-governance.sh

194 lines
5.8 KiB
Bash
Raw Normal View History

#!/bin/bash
# This tool automates the process of writing bridge registration governance
# proposals in markdown format.
#
# There are two ways to run this script: either in "one-shot" mode, where a
# single governance VAA is generated:
#
# ./register-chain-governance.sh -m TokenBridge -c solana > governance.md
#
# or in "multi" mode, where multiple VAAs are created in the same proposal:
#
# ./register-chain-governance.sh -m TokenBridge -c solana -o my_proposal > governance.md
# ./register-chain-governance.sh -m TokenBridge -c avalanche -o my_proposal > governance.md
# ... -o my_proposal > governance.md
#
# In multi mode, there's an additional "-o" flag, which takes a directory name,
# where intermediate progress is saved between runs. If the directory doesn't
# exist, the tool will create it.
#
# In both one-shot and multi modes, the script outputs the markdown-formatted
# proposal to STDOUT, so it's a good idea to pipe it into a file (as in the above examples).
#
# In multi-mode, it always outputs the most recent version, so it's safe to
# override the previous files.
#
# Once a multi-mode run is completed, the directory specified with the -o flag can be deleted.
set -euo pipefail
function usage() {
cat <<EOF >&2
Usage:
2023-01-11 11:17:20 -08:00
$(basename "$0") [-h] [-m s] [-c s] [-o d] [-a s] -- Generate bridge registration governance proposal for a given module
where:
-h show this help text
Relayer: Generic Relayer Guardian Changes for Merging into Main (#3041) * gRelayer: surrounding files * modification to get compilation * restore devnet * remove generic relayer docker * remove wait for relayer engine * keep build time 20 * sh -> bash * sh -> bash * Remove comment * bash -> sh * Revert "bash -> sh" This reverts commit 5c37e92fa19bbdbefc79c8ee0dbceeb127c53373. * bash->sh * gRelayer: ethereum folder changes for generic-relayer-merge * add eth-devnet * Adds .github because workflow needs to install forge * sdk-ci-tests need to install forge * don't wait for nonexistent relayer engine * update package.json and package-lock.json * Remove unnecessary types from package.json * ts-node * gRelayer: ethereum folder changes for generic-relayer-merge * sdk-ci-tests need to install forge * don't wait for nonexistent relayer engine * update package.json and package-lock.json * remove these changes * Relayer: Natspec documentation in IWormholeRelayer (#3032) * WIP * Fixes * Updated interfaces * remove bash * Forward uses same refund chain id and refund address (#3034) * WIP * Fixes * Forward uses same refund chain id and refund address * Updated interfaces * Adds .github because workflow needs to install forge * sdk-ci-tests need to install forge * don't wait for nonexistent relayer engine * SDK minus payload tests * Rename sdk relayer folder and file * modify index.ts * modify path * sdk-ci-tests need to install forge * don't wait for nonexistent relayer engine * Add three governance VAA actions for generic relayers * demandOption and const * Remove forge build warnings * Add note to interface for resend * Verify additional VAAs in SDK * via-ir on unless in Tilt * Correct IWormholeReceiver interface * Wormhole message fee now part of quoteDeliveryPrice (#3043) * Fix to PR 3043 * Remove compiler warning * Remove files * remove generic relayer docker * Fix typo * Relayer/address drew review (#3060) * Fix typo in Create2Factory * Add event for contract upgrades * Prevent registering contract if it is already registered * Prevent allowing unset chainId for default delivery provider governance VAA * memory to calldata for external functions in WormholeRelayerSend * continue memory to calldata for external functions * Fix pricing in delivery provider * Sanity check new default delivery provider isn't 0 address * Don't save vaaKey as local variable * cache the length of array rather than iterate every time for vaaKeys * Replacing memory with calldata in few locations * Remove stale file DeliveryProviderMessages * Remove batch VAA sender script * Remove batch VAA from WormholeSimulator * Wait for a confirmation in deploy scripts * remove unnecessary comments * Fix Delivery Provider Pricing and add a test * remove console logs * Revert "continue memory to calldata for external functions" This reverts commit f322afb6c0bbd09e3d04ab42a90e592ff752f6bf. * Revert "memory to calldata for external functions in WormholeRelayerSend" This reverts commit 42fcaad8842d0c81506c9586d8d0fd98f6bb6ae1. * Revert "Don't save vaaKey as local variable" This reverts commit a9172379c564fd430a083645c1c42c78e014d68d. * Revert "cache the length of array rather than iterate every time for vaaKeys" This reverts commit d61380a9b0c0671e67e3bd5d874ae339e180dd34. * Revert "Replacing memory with calldata in few locations" This reverts commit 94e47b6e72eaaa52ac0ba2980c439180401fafd7. * Revert "Fix typo in Create2Factory" This reverts commit a9f7bdf461945c8abf020007d16bbc6b4301d051. * Update contract addresses for via-ir * Update register chain test to only do one registration * Slight improvements to delivery provider implementation * typed errors for delivery provider * Update SDK to have via-ir devnet address * Fix test * enable VIA-IR in CI and not in Tilt * Fix chain id * get register chain test to work * correct contract address for via ir * update sdk consts for via ir address * base 32 address * merge * -f to -r * relay provider -> delivery provider * fix await * Readme changes
2023-06-14 07:27:00 -07:00
-m module (TokenBridge, NFTBridge, WormholeRelayer)
-c chain name
2023-01-11 11:17:20 -08:00
-a emitter address (optional, derived by worm CLI by default)
-o multi-mode output directory
EOF
exit 1
}
# Check if guardiand and worm commands exist. They needed for generating the protoxt and
# computing the digest.
if ! command -v guardiand >/dev/null 2>&1; then
echo "ERROR: guardiand binary not found" >&2
exit 1
fi
if ! command -v worm >/dev/null 2>&1; then
echo "ERROR: worm binary not found" >&2
exit 1
fi
### Parse command line options
address=""
module=""
chain_name=""
multi_mode=false
out_dir=""
while getopts ':hm:c:a:o:' option; do
case "$option" in
h) usage
;;
m) module=$OPTARG
;;
2023-01-11 11:17:20 -08:00
a) address=$OPTARG
;;
c) chain_name=$OPTARG
;;
o) multi_mode=true
out_dir=$OPTARG
;;
:) printf "missing argument for -%s\n" "$OPTARG" >&2
usage
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
usage
;;
esac
done
shift $((OPTIND - 1))
2023-01-11 11:17:20 -08:00
[ -z "$chain_name" ] && usage
[ -z "$module" ] && usage
# Use the worm client to get the emitter address and wormhole chain ID.
2023-05-06 02:02:05 -07:00
[ -z "$address" ] && address=`worm info contract --emitter mainnet $chain_name $module`
[ -z "$address" ] && usage
2023-05-06 02:02:05 -07:00
chain=`worm info chain-id $chain_name`
[ -z "$chain" ] && usage
### The script constructs the governance proposal in two different steps. First,
### the governance prototxt (for VAA injection by the guardiand tool), then the voting/verification instructions.
gov_msg_file=""
instructions_file=""
if [ "$multi_mode" = true ]; then
mkdir -p "$out_dir"
gov_msg_file="$out_dir/governance.prototxt"
instructions_file="$out_dir/instructions.md"
else
gov_msg_file=$(mktemp)
instructions_file=$(mktemp)
fi
# Generate the command to create the governance prototxt
function create_governance() {
case "$module" in
TokenBridge)
echo "\
guardiand template token-bridge-register-chain \\
--chain-id $chain --module \"TokenBridge\" \\
--new-address $address"
;;
NFTBridge)
echo "\
guardiand template token-bridge-register-chain \\
--chain-id $chain --module \"NFTBridge\" \\
Relayer: Generic Relayer Guardian Changes for Merging into Main (#3041) * gRelayer: surrounding files * modification to get compilation * restore devnet * remove generic relayer docker * remove wait for relayer engine * keep build time 20 * sh -> bash * sh -> bash * Remove comment * bash -> sh * Revert "bash -> sh" This reverts commit 5c37e92fa19bbdbefc79c8ee0dbceeb127c53373. * bash->sh * gRelayer: ethereum folder changes for generic-relayer-merge * add eth-devnet * Adds .github because workflow needs to install forge * sdk-ci-tests need to install forge * don't wait for nonexistent relayer engine * update package.json and package-lock.json * Remove unnecessary types from package.json * ts-node * gRelayer: ethereum folder changes for generic-relayer-merge * sdk-ci-tests need to install forge * don't wait for nonexistent relayer engine * update package.json and package-lock.json * remove these changes * Relayer: Natspec documentation in IWormholeRelayer (#3032) * WIP * Fixes * Updated interfaces * remove bash * Forward uses same refund chain id and refund address (#3034) * WIP * Fixes * Forward uses same refund chain id and refund address * Updated interfaces * Adds .github because workflow needs to install forge * sdk-ci-tests need to install forge * don't wait for nonexistent relayer engine * SDK minus payload tests * Rename sdk relayer folder and file * modify index.ts * modify path * sdk-ci-tests need to install forge * don't wait for nonexistent relayer engine * Add three governance VAA actions for generic relayers * demandOption and const * Remove forge build warnings * Add note to interface for resend * Verify additional VAAs in SDK * via-ir on unless in Tilt * Correct IWormholeReceiver interface * Wormhole message fee now part of quoteDeliveryPrice (#3043) * Fix to PR 3043 * Remove compiler warning * Remove files * remove generic relayer docker * Fix typo * Relayer/address drew review (#3060) * Fix typo in Create2Factory * Add event for contract upgrades * Prevent registering contract if it is already registered * Prevent allowing unset chainId for default delivery provider governance VAA * memory to calldata for external functions in WormholeRelayerSend * continue memory to calldata for external functions * Fix pricing in delivery provider * Sanity check new default delivery provider isn't 0 address * Don't save vaaKey as local variable * cache the length of array rather than iterate every time for vaaKeys * Replacing memory with calldata in few locations * Remove stale file DeliveryProviderMessages * Remove batch VAA sender script * Remove batch VAA from WormholeSimulator * Wait for a confirmation in deploy scripts * remove unnecessary comments * Fix Delivery Provider Pricing and add a test * remove console logs * Revert "continue memory to calldata for external functions" This reverts commit f322afb6c0bbd09e3d04ab42a90e592ff752f6bf. * Revert "memory to calldata for external functions in WormholeRelayerSend" This reverts commit 42fcaad8842d0c81506c9586d8d0fd98f6bb6ae1. * Revert "Don't save vaaKey as local variable" This reverts commit a9172379c564fd430a083645c1c42c78e014d68d. * Revert "cache the length of array rather than iterate every time for vaaKeys" This reverts commit d61380a9b0c0671e67e3bd5d874ae339e180dd34. * Revert "Replacing memory with calldata in few locations" This reverts commit 94e47b6e72eaaa52ac0ba2980c439180401fafd7. * Revert "Fix typo in Create2Factory" This reverts commit a9f7bdf461945c8abf020007d16bbc6b4301d051. * Update contract addresses for via-ir * Update register chain test to only do one registration * Slight improvements to delivery provider implementation * typed errors for delivery provider * Update SDK to have via-ir devnet address * Fix test * enable VIA-IR in CI and not in Tilt * Fix chain id * get register chain test to work * correct contract address for via ir * update sdk consts for via ir address * base 32 address * merge * -f to -r * relay provider -> delivery provider * fix await * Readme changes
2023-06-14 07:27:00 -07:00
--new-address $address"
;;
WormholeRelayer)
echo "\
guardiand template token-bridge-register-chain \\
--chain-id $chain --module \"WormholeRelayer\" \\
--new-address $address"
;;
*) echo "unknown module $module" >&2
usage
;;
esac
}
################################################################################
# Construct the governance proto
echo "# Registration $chain_name $module" >> "$gov_msg_file"
# Append the new governance message to the gov file
eval "$(create_governance)" >> "$gov_msg_file"
# Multiple messages will include multiple 'current_set_index' fields, but the
# proto format only takes one. This next part cleans up the file so there's only
# a single 'current_set_index' field.
# 1. we grab the first one and save it
current_set_index=$(grep "current_set_index" "$gov_msg_file" | head -n 1)
# 2. remove all 'current_set_index' fields
rest=$(grep -v "current_set_index" "$gov_msg_file")
# 3. write the set index
echo "$current_set_index" > "$gov_msg_file"
# 4. then the rest of the file
echo "$rest" >> "$gov_msg_file"
################################################################################
# Compute expected digests
# just use the 'guardiand' command, which spits out a bunch of text to
# stderr. We grab that output and pick out the VAA hashes
verify=$(guardiand admin governance-vaa-verify "$gov_msg_file" 2>&1)
digest=$(echo "$verify" | grep "VAA with digest" | cut -d' ' -f6 | sed 's/://g')
# massage the digest into the same format that the inject command prints it
digest=$(echo "$digest" | awk '{print toupper($0)}' | sed 's/^0X//')
# we use the first 7 characters of the digest as an identifier for the prototxt file
gov_id=$(echo "$digest" | cut -c1-7)
################################################################################
# Print vote command and expected digests
# This we only print to stdout, because in multi mode, it gets recomputed each
# time. The rest of the output gets printed into the instructions file
cat <<-EOD
# Governance
Shell command for voting:
\`\`\`shell
cat << EOF > governance-$gov_id.prototxt
$(cat "$gov_msg_file")
EOF
guardiand admin governance-vaa-inject --socket /path/to/admin.sock governance-$gov_id.prototxt
\`\`\`
Expected digest(s):
\`\`\`
$digest
\`\`\`
EOD