Jelajahi Sumber

ethereum: Add scripts to verify/upgrade all contracts

Csongor Kiss 3 tahun lalu
induk
melakukan
b5a8ba2361
4 mengubah file dengan 167 tambahan dan 1 penghapusan
  1. 10 1
      ethereum/truffle-config.js
  2. 82 0
      ethereum/upgrade
  3. 13 0
      ethereum/upgrade_all_testnet
  4. 62 0
      ethereum/verify_all

+ 10 - 1
ethereum/truffle-config.js

@@ -48,6 +48,15 @@ module.exports = {
       },
       network_id: "5",
     },
+    ropsten_testnet: {
+      provider: () => {
+        return new HDWalletProvider(
+          process.env.MNEMONIC,
+          "https://rpc.ankr.com/eth_ropsten"
+        );
+      },
+      network_id: "3",
+    },
     bsc: {
       provider: () => {
         return new HDWalletProvider(
@@ -268,7 +277,7 @@ module.exports = {
         );
       },
       network_id: 1284,
-    },    
+    },
     moonbeam_testnet: {
       provider: () => {
         return new HDWalletProvider(

+ 82 - 0
ethereum/upgrade

@@ -0,0 +1,82 @@
+#!/bin/bash
+
+set -euo pipefail
+
+network=$1
+module=$2
+chain=$3
+
+secret=$MNEMONIC
+guardian_secret=""
+
+if [ "$network" = testnet ]; then
+  guardian_secret=$GUARDIAN_MNEMONIC
+fi
+
+SCRIPT=""
+verify_module=""
+case "$module" in
+    Core)
+        SCRIPT="scripts/deploy_core_bridge.js"
+        FILE="build/contracts/Implementation.json"
+        verify_module="core"
+        ;;
+    TokenBridge)
+        SCRIPT="scripts/deploy_token_bridge.js"
+        FILE="build/contracts/BridgeImplementation.json"
+        verify_module="token_bridge"
+        ;;
+    NFTBridge)
+        SCRIPT="scripts/deploy_nft_bridge.js"
+        FILE="build/contracts/NFTBridgeImplementation.json"
+        verify_module="nft_bridge"
+        ;;
+    *) echo "unknown module $module" >&2
+       ;;
+esac
+
+# TODO: add option to not compile (but compile by default)
+
+truffle_network=""
+case "$network" in
+    mainnet)
+        truffle_network="$chain"
+    ;;
+    testnet)
+        truffle_network="$chain"_testnet
+esac
+
+ret=0
+implementation=$(worm evm info -c "$chain" -m "$module" -n "$network" -i 2>/dev/null) || ret=$?
+
+if [ $ret != 0 ]; then
+  printf "☐ %s %s: skipping (no deployment available)\n" "$chain" "$module"
+  exit 1
+fi
+
+ret=0
+(./verify -n "$network" -c "$chain" $FILE "$implementation" > /dev/null) || ret=$?
+
+if [ $ret = 0 ]; then
+  printf "✔ %s %s: skipping (implementation matches same bytecode)\n" "$chain" "$module"
+  exit
+fi
+
+deploy_output=$(npx truffle exec $SCRIPT --network "$truffle_network") || ( echo "✘ $chain $module: $deploy_output" && exit 1 )
+new_implementation=$(echo "$deploy_output" | grep "address:" | cut -d' ' -f3)
+
+ret=0
+(./verify -n "$network" -c "$chain" $FILE "$new_implementation" > /dev/null) || ret=$?
+
+if [ $ret = 0 ]; then
+  printf "✔ %s %s: deployed (%s)\n" "$chain" "$module" "$new_implementation"
+else
+  printf "✘ %s %s: deployed (%s) but failed to match bytecode\n"  "$chain" "$module" "$new_implementation"
+  exit 1
+fi
+
+if [ "$network" = testnet ]; then
+  worm submit $(worm generate upgrade -c "$chain" -a "$new_implementation" -m "$module" -g "$guardian_secret") -n "$network"
+else
+  echo "./scripts/contract-upgrade-governance.sh -c $chain -m $verify_module -a $new_implementation"
+fi

+ 13 - 0
ethereum/upgrade_all_testnet

@@ -0,0 +1,13 @@
+#!/bin/bash
+set -uo pipefail
+
+modules=(Core TokenBridge NFTBridge)
+network=testnet
+chains=$(worm evm chains)
+
+
+for module in ${modules[@]}; do
+  for chain in ${chains[@]}; do
+    ./upgrade "$network" "$module" "$chain"
+  done
+done

+ 62 - 0
ethereum/verify_all

@@ -0,0 +1,62 @@
+#!/bin/bash
+set -uo pipefail
+
+function usage() {
+cat <<EOF >&2
+Usage:
+
+  $(basename "$0") [-h] [-n network] -- Verify that all deployed contracts match the local build artifact
+
+  where:
+      -h  show this help text
+      -n  set the network (mainnet, testnet, devnet)
+EOF
+exit 1
+}
+
+if ! command -v worm &> /dev/null
+then
+    echo "worm binary could not be found. See installation instructions in clients/js/README.md"
+    exit 1
+fi
+
+network=""
+while getopts ':hn:' option; do
+  case "$option" in
+    h) usage
+       ;;
+    n) network=$OPTARG
+       ;;
+    :) printf "missing argument for -%s\n" "$OPTARG" >&2
+       usage
+       ;;
+   \?) printf "illegal option: -%s\n" "$OPTARG" >&2
+       usage
+       ;;
+  esac
+done
+shift $((OPTIND - 1))
+[ -z "$network" ] && usage
+
+chains=$(worm evm chains)
+modules=(Core TokenBridge NFTBridge)
+
+for module in ${modules[@]}; do
+  for chain in ${chains[@]}; do
+    FILE=""
+    case "$module" in
+        Core)
+            FILE="build/contracts/Implementation.json"
+            ;;
+        TokenBridge)
+            FILE="build/contracts/BridgeImplementation.json"
+            ;;
+        NFTBridge)
+            FILE="build/contracts/NFTBridgeImplementation.json"
+            ;;
+        *) echo "unknown module $module" >&2
+           ;;
+    esac
+    ./verify -n $network -c "$chain" $FILE "$(worm evm info -c $chain -m $module -n $network -i)"
+  done
+done