Skip to content

Commit

Permalink
Darwinia2.0 message protocol deploy (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
hujw77 authored Apr 28, 2023
1 parent ee37bdc commit 5ba4cd3
Show file tree
Hide file tree
Showing 32 changed files with 813 additions and 311 deletions.
2 changes: 1 addition & 1 deletion contracts/bridge/.dapprc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ then
export DAPP_TEST_MAX_ITERATIONS=6
export DAPP_TEST_VERBOSITY=0
else
export DAPP_SOLC=/nix/store/ywqbzx3y85y533x4phzkacpcr31rxy0r-solc-static-0.8.17
export DAPP_SOLC=/nix/store/ywqbzx3y85y533x4phzkacpcr31rxy0r-solc-static-0.8.17/bin/solc-0.8.17
export DAPP_TEST_FUZZ_RUNS=100
export DAPP_TEST_MAX_ITERATIONS=3
export DAPP_TEST_VERBOSITY=3
Expand Down
2 changes: 2 additions & 0 deletions contracts/bridge/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ migrate :; @./bin/migrate.sh $(mode)
verify :; @./bin/verify.sh $(mode)
# status
stats :; @./bin/stats.sh $(mode)
# check
check :; @./bin/check.sh $(mode)

# Local testnet starter
local-testnet :; @./bin/start-services.sh
Expand Down
23 changes: 10 additions & 13 deletions contracts/bridge/bin/addr/prod/darwinia.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
{
"DEPLOYER": "0x7aE77149ed38c5dD313e9069d790Ce7085caf0A6",
"DEPLOYER": "0xa4FA5429544B225985F8438F2E013A9CCE7102f2",
"BridgeProxyAdmin": "0x86c85A9bf5DEAfdeD40D9C70517883D95F50Df03",
"ChainMessageCommitter": "0xEf5425b3B0111297e7178BAA8E7483430Ddc69D0",
"ChainMessageCommitterProxy": "0xea7d0fE22AF25d9655f7AdDd6a59E37e84B3AB5F",
"ethlive": {
"FeeMarket": "0xD1182CddB414FfC00eF2Ce18299A1E12e1a552BE",
"FeeMarketProxy": "0xcA927Df15afb7629b79dA4713a871190315c7409",
"BeaconLightClient": "0xA2D2d90D03b0876A4883FB6C95b3c6dBAEb24dEF",
"ExecutionLayer": "0x4214611Be6cA4E337b37e192abF076F715Af4CaE",
"BeaconLCMandatoryReward": "0xFB371c8B99ba0b239E66E0a66bB6296b00dCD09f",
"EthereumStorageVerifier": "0x1e0D6Ba9D7Ddd3f9bc121c51FA051E7826f12b9f",
"OutboundLane": "0xcA3749C8C3aF04278D596a3fBe461481B6aa1b01",
"InboundLane": "0xf1B8a9F8436800499DB8186f2da2fb3e78Ff7c2B",
"LaneMessageCommitter": "0x56746a8099a7e6D962802A23e01FeDdc1282cDAe"
"ChainMessageCommitter": "0x1829ee0c5E556D50cb4c11791777afd7fF00019a",
"ethereum": {
"FeeMarket": "0x171A87e3969fC82c8d25A0866316FCc6378B5c10",
"FeeMarketProxy": "0x9bd2F907B33E25126CD4e4342a75dE8F8eff76Bf",
"BeaconLightClient": "0x0b51a80A37dD1629FcE060BBec6D9fcDB7eFcCfd",
"EthereumSerialLaneVerifier": "0x1cBFc823cDC05488536A6CA5a6E6aa8883D279a1",
"SerialOutboundLane": "0x7e10D91862E7477C0FedE95D291f7101AE1Aec4d",
"SerialInboundLane": "0x1cE84Cc75847374Ae41B4c1070d5B42A06BB42E7",
"LaneMessageCommitter": "0xb1a9585B0739F6ad91d8647699420d7284B71C10"
}
}
12 changes: 12 additions & 0 deletions contracts/bridge/bin/addr/prod/ethereum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"DEPLOYER": "0xa4FA5429544B225985F8438F2E013A9CCE7102f2",
"BridgeProxyAdmin": "0xBd1a110ec476b4775c43905000288881367B1a88",
"darwinia": {
"SimpleFeeMarket": "0xb1966847e333e19d7c0990173dA705B7A99C9BCe",
"FeeMarketProxy": "0xC71593F6Cb1642DD95bd1330f7c0a59d9f66Db97",
"POSALightClient": "0x2802E5fa6251B1D0Be2aE57cD1e17422B5B35839",
"DarwiniaMessageVerifier": "0x1829ee0c5E556D50cb4c11791777afd7fF00019a",
"SerialOutboundLane": "0x171A87e3969fC82c8d25A0866316FCc6378B5c10",
"SerialInboundLane": "0x9bd2F907B33E25126CD4e4342a75dE8F8eff76Bf"
}
}
12 changes: 0 additions & 12 deletions contracts/bridge/bin/addr/prod/ethlive.json

This file was deleted.

76 changes: 76 additions & 0 deletions contracts/bridge/bin/auth-checker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash

set -eo pipefail

GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

ok() {
printf '%b\n' "${GREEN}✓ OK${NC}"
}

notok() {
printf '%b\n' "${RED}❌NOT OK${NC}"
}

check() {
printf "CFG: %s -> %s -> " "${1}" "${2}"
if [[ $(toLower "${!2}") == $(toLower "${!2}") ]]; then
ok
else
notok
fi
}

ADMIN_SLOT="0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103"
check_admin() {
local CHECK
CHECK=$(seth storage "${!1}" "$ADMIN_SLOT" --chain $SOURCE_CHAIN)
CHECK=$(seth --abi-decode "f()(address)" "$CHECK")

printf "ADM: %s -> %s -> " "${1}" "${2}"
if [[ $(toLower "${!2}") == $(toLower "${CHECK}") ]]; then
ok
else
notok
fi
}

IMPLEMENTATION_SLOT="0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc"
check_imp() {
local CHECK
CHECK=$(seth storage "${!1}" "$IMPLEMENTATION_SLOT" --chain $SOURCE_CHAIN)
CHECK=$(seth --abi-decode "f()(address)" "$CHECK")

printf "IMP: %s -> %s -> " "${1}" "${2}"
if [[ $(toLower "${!2}") == $(toLower "${CHECK}") ]]; then
ok
else
notok
fi
}

check_owner() {
local CHECK
CHECK=$(seth call "${!1}" 'owner()(address)' --chain $SOURCE_CHAIN)

printf "OWN: %s -> %s -> " "${1}" "${2}"
if [[ $(toLower "${!2}") == $(toLower "${CHECK}") ]]; then
ok
else
notok
fi
}

check_setter() {
local CHECK
CHECK=$(seth call "${!1}" 'setter()(address)' --chain $SOURCE_CHAIN)

printf "SET: %s -> %s -> " "${1}" "${2}"
if [[ $(toLower "${!2}") == $(toLower "${CHECK}") ]]; then
ok
else
notok
fi
}
89 changes: 62 additions & 27 deletions contracts/bridge/bin/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,31 @@ set -eo pipefail
. $(dirname $0)/vrf.sh
. $(dirname $0)/eta-gas.sh

send() {
set -e
echo "seth send $*"

ETH_NONCE=$(nonce "$SETH_CHAIN")
if [[ $SETH_ASYNC = yes ]]; then
ETH_NONCE="$ETH_NONCE" seth send "$@"
else
seth send "$@"
fi
inc "$SOURCE_CHAIN"
echo ""
}

# Call as `ETH_FROM=0x... SOURCE_CHAIN=<chain> deploy ContractName arg1 arg2 arg3`
# (or omit the env vars if you have already set them)
deploy() {
set -e

NAME=$1
ARGS=${@:2}

# find file path
CONTRACT_PATH=$(find ./$SRC_DIR -name $NAME.f.sol)
CONTRACT_PATH=${CONTRACT_PATH:2}
# find file path
CONTRACT_PATH=$(find ./$SRC_DIR -name $NAME.f.sol)
CONTRACT_PATH=${CONTRACT_PATH:2}

# select the filename and the contract in it
PATTERN=".contracts[\"$CONTRACT_PATH\"].$NAME"
Expand All @@ -28,18 +44,31 @@ deploy() {
# get the bytecode from the compiled file
BYTECODE=0x$(jq -r "$PATTERN.evm.bytecode.object" $OUT_DIR/dapp.sol.json)

# get nonce
ETH_NONCE=$(nonce "$SOURCE_CHAIN")

# estimate gas
GAS=$(seth estimate --create "$BYTECODE" "$SIG" $ARGS --chain "$SOURCE_CHAIN" --from "$ETH_FROM")
# GAS=$(seth estimate --create "$BYTECODE" "$SIG" $ARGS --chain "$SOURCE_CHAIN" --from "$ETH_FROM")
GAS=6000000

# deploy
ADDRESS=$(dapp create "$NAME" $ARGS -- --gas "$GAS" --chain "$SOURCE_CHAIN" --from "$ETH_FROM")
if [[ $SETH_ASYNC = yes ]]; then
TX=$(ETH_NONCE="$ETH_NONCE" dapp create "$NAME" $ARGS -- --gas "$GAS" --chain "$SOURCE_CHAIN" --from "$ETH_FROM")
log "$NAME txhash:" $TX
ADDRESS=$(dapp address "$ETH_FROM" "$ETH_NONCE")
else
ADDRESS=$(ETH_NONCE="$ETH_NONCE" dapp create "$NAME" $ARGS -- --gas "$GAS" --chain "$SOURCE_CHAIN" --from "$ETH_FROM")
fi

# increase nonce
inc "$SOURCE_CHAIN"

# save the addrs to the json
# TODO: It'd be nice if we could evolve this into a minimal versioning system
# e.g. via commit / chainid etc.
save_contract "$NAME" "$ADDRESS"

log "$NAME deployed at" $ADDRESS
log "$NAME deployed at:" $ADDRESS

echo "$ADDRESS"
}
Expand All @@ -48,7 +77,12 @@ upgrade() {
local admin; admin=$1
local newImp; newImp=$2
local proxy; proxy=$3

# get nonce
ETH_NONCE=$(nonce "$SOURCE_CHAIN")
seth send "$admin" "upgrade(address,address)" "$proxy" "$newImp" --chain "$SOURCE_CHAIN" --from "$ETH_FROM"
# increase nonce
inc "$SOURCE_CHAIN"
if test $(seth call "$admin" "getProxyImplementation(address)(address)" "$proxy" --chain "$SOURCE_CHAIN" --from "$ETH_FROM") != "$newImp"; then
(log "check migration failed."; exit 1;)
fi
Expand Down Expand Up @@ -76,44 +110,45 @@ deploy_v2() {
# get the bytecode from the compiled file
BYTECODE=0x$(jq -r "$PATTERN.evm.bytecode.object" $OUT_DIR/dapp.sol.json)

# get nonce
ETH_NONCE=$(nonce "$SOURCE_CHAIN")

# estimate gas
GAS=$(seth estimate --from "$ETH_FROM" --create "$BYTECODE" "$FUNCSIG$ARGS" --chain "$SOURCE_CHAIN")
GAS=$(seth estimate --from "$ETH_FROM" --create "$BYTECODE" "$FUNCSIG$ARGS" --chain "$SOURCE_CHAIN" --nonce "$ETH_NONCE")

# deploy
ADDRESS=$(set -x; seth send --from "$ETH_FROM" --create "$BYTECODE" "$FUNCSIG$ARGS" -- --gas "$GAS" --chain "$SOURCE_CHAIN")
if [[ $SETH_ASYNC = yes ]]; then
TX=$(set -x; seth send --from "$ETH_FROM" --create "$BYTECODE" "$FUNCSIG$ARGS" -- --gas "$GAS" --chain "$SOURCE_CHAIN" --nonce "$ETH_NONCE")
log "$NAME txhash:" $TX
ADDRESS=$(dapp address "$ETH_FROM" "$ETH_NONCE")
else
ADDRESS=$(set -x; seth send --from "$ETH_FROM" --create "$BYTECODE" "$FUNCSIG$ARGS" -- --gas "$GAS" --chain "$SOURCE_CHAIN" --nonce "$ETH_NONCE")
fi

# increase nonce
inc "$SOURCE_CHAIN"

# save the addrs to the json
# TODO: It'd be nice if we could evolve this into a minimal versioning system
# e.g. via commit / chainid etc.
save_contract "$NAME" "$ADDRESS"

log "$NAME deployed at" $ADDRESS
log "$NAME deployed at:" $ADDRESS

echo "$ADDRESS"
}

# Call as `save_contract ContractName 0xYourAddress` to store the contract name
# & address to the addresses json file
save_contract() {
# create an empty json if it does not exist
if [[ ! -e $ADDRESSES_FILE ]]; then
echo "{}" >"$ADDRESSES_FILE"
fi
# create an empty json if it does not exist
if [[ ! -e $ADDRESSES_FILE ]]; then
echo "{}" >"$ADDRESSES_FILE"
fi
if [[ -z ${TARGET_CHAIN} ]]; then
result=$(cat "$ADDRESSES_FILE" | jq -r ". + {\"$1\": \"$2\"}")
result=$(cat "$ADDRESSES_FILE" | jq -r ". + {\"$1\": \"$2\"}")
else
result=$(cat "$ADDRESSES_FILE" | jq -r ".\"$TARGET_CHAIN\" += {\"$1\": \"$2\" }")
result=$(cat "$ADDRESSES_FILE" | jq -r ".\"$TARGET_CHAIN\" += {\"$1\": \"$2\" }")
fi
printf %s "$result" >"$ADDRESSES_FILE"
}

gen_lane_id() {
python3 -c "print(
hex(
($1 << 64) +
($2 << 96) +
($3 << 128) +
($4 << 160)
)
)"
printf %s "$result" >"$ADDRESSES_FILE"
}
7 changes: 7 additions & 0 deletions contracts/bridge/bin/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -eo pipefail

export MODE=${1?}

. $(dirname $0)/deploy/${MODE}/check.sh
24 changes: 12 additions & 12 deletions contracts/bridge/bin/color.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ p() {
GREEN='\033[0;32m'
NC='\033[0m' # No Color
log() {
printf '%b\n' "${GREEN}${*}${NC}" >&2
echo ""
printf '%b\n' "${GREEN}${*}${NC}" >&2
echo ""
}

# Coloured output helpers
if command -v tput >/dev/null 2>&1; then
if [ $(($(tput colors 2>/dev/null))) -ge 8 ]; then
# Enable colors
TPUT_RESET="$(tput sgr 0)"
TPUT_YELLOW="$(tput setaf 3)"
TPUT_RED="$(tput setaf 1)"
TPUT_BLUE="$(tput setaf 4)"
TPUT_GREEN="$(tput setaf 2)"
TPUT_WHITE="$(tput setaf 7)"
TPUT_BOLD="$(tput bold)"
fi
if [ $(($(tput colors 2>/dev/null))) -ge 8 ]; then
# Enable colors
TPUT_RESET="$(tput sgr 0)"
TPUT_YELLOW="$(tput setaf 3)"
TPUT_RED="$(tput setaf 1)"
TPUT_BLUE="$(tput setaf 4)"
TPUT_GREEN="$(tput setaf 2)"
TPUT_WHITE="$(tput setaf 7)"
TPUT_BOLD="$(tput bold)"
fi
fi
16 changes: 8 additions & 8 deletions contracts/bridge/bin/conf/prod/darwinia.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"this_chain_pos": 0
},
"FeeMarket": {
"vault": "0xBd1a110ec476b4775c43905000288881367B1a88",
"vault": "0xB29DA7C1b1514AB342afbE6AB915252Ad3f87E4d",
"collateral_perorder": "6000000000000000000000",
"assigned_relayers_number": "1",
"slash_time": "10800",
Expand All @@ -57,13 +57,13 @@
},
"LightClient": {
"bls_precompile": "0x0000000000000000000000000000000000000800",
"slot": "5433408",
"proposer_index": "338940",
"parent_root": "0xf7c0374ad89d9a28f6708bd7b02af59a7a2ed2463a4ef191aa55cdf6cf8001b2",
"state_root": "0x9840d388c38172332553e9445e7fd64185aba5212026d22dce5efccf41d5663d",
"body_root": "0x4b6cc5f729ae6a9d57f6b912d655467627ce4d057f10a1d0a8ad5f68c5c1a2e9",
"current_sync_committee_hash": "0x4bcc8065b1462577a9971110aaa3ea5630ce3e6bc0ecb53e54777ce7d4a5e816",
"genesis_validators_root": "0x043db0d9a83813551ee2f33450d23797757d430911a9320530ad8a0eabc43efb",
"slot": "6299648",
"proposer_index": "229152",
"parent_root": "0xa4c337a4cbf5a19d7f67afa9a7156793bf02c9b22f71652c9a38659a398b2827",
"state_root": "0xd7e39cafbab9f5c18365b98275e0d6002d3e6e7411798d7ac6facf8df54416a8",
"body_root": "0xeeddf25887ced12ed2683947455281f0caded03c4f27d65c9389819216029846",
"current_sync_committee_hash": "0xbb8d1db5911ea3336e5bb84a315cfdf3bc976450dd53839e4b750c41222f763c",
"genesis_validators_root": "0x4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95",
"mandatory_reward": "30000000000000000000"
}
}
Loading

0 comments on commit 5ba4cd3

Please sign in to comment.