From 0b880fa0ada0d1e674e4a391582386e5370a83f8 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Thu, 21 Dec 2023 03:05:19 -0800 Subject: [PATCH 1/7] test file changes --- geth-poa/util/test_bridge.sh | 48 ++++++++++++++++++++++----------- geth-poa/util/test_whitelist.sh | 44 ++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 15 deletions(-) create mode 100755 geth-poa/util/test_whitelist.sh diff --git a/geth-poa/util/test_bridge.sh b/geth-poa/util/test_bridge.sh index 144fe16f6b..2faa4b2b41 100755 --- a/geth-poa/util/test_bridge.sh +++ b/geth-poa/util/test_bridge.sh @@ -2,30 +2,41 @@ set -x set -e +read -p "Has the whitelist contract been deployed, updated with hypERC20 addr, and have router addresss been pasted into this file? (y/n): " answer +if [ "$answer" = "y" ]; then + echo "Continuing with bridging process..." +else + echo "Exiting..." + exit 1 +fi + # Test account, this must be funded on Sepolia # Address: 0xa43b806D2f09AE94dfa38bc00d6F75426D274540 # Private key: 0x8b21e3bc5c26d3327109d341d121fbfb7cb79c95fba5eb2f8c064f87332df7dd ADDRESS=0xa43b806D2f09AE94dfa38bc00d6F75426D274540 PRIVATE_KEY=0x8b21e3bc5c26d3327109d341d121fbfb7cb79c95fba5eb2f8c064f87332df7dd -# make print-warp-deploy prints these contract addrs -SEPOLIA_ROUTER=0x11dE1a80570f36E57b3F15dAb008DFEAA4F1bf05 -SIDECHAIN_ROUTER=0xf46a69166dB5C2a7ff97D50Fc46B5fb663CeD4c3 +# "make print-warp-deploy" prints these contract addrs +SEPOLIA_ROUTER=0xdFB826f7F5E8d4843f54792369F64eF633E5c4cF +SIDECHAIN_ROUTER=0x79Df08515c2b88daa9C407271844afFD31A4c979 -# Store initial sidechain ERC20 balance -SIDECHAIN_ERC20_BALANCE=$(cast call $SIDECHAIN_ROUTER "balanceOf(address)" $ADDRESS) +SEPOLIA_URL=https://ethereum-sepolia.publicnode.com +SIDECHAIN_URL=http://localhost:8545 + +# Store initial sidechain native balance +SIDECHAIN_BALANCE=$(cast balance --rpc-url $SIDECHAIN_URL $ADDRESS) # sepolia -> dest chain (account must be funded on sepolia) -cast call --rpc-url https://ethereum-sepolia.publicnode.com $SEPOLIA_ROUTER "quoteGasPayment(uint32)" "17864" +cast call --rpc-url $SEPOLIA_URL $SEPOLIA_ROUTER "quoteGasPayment(uint32)" "17864" # Above returns 1 wei, therefore ether value is 1 wei larger than value function argument -cast send --rpc-url https://ethereum-sepolia.publicnode.com --private-key $PRIVATE_KEY $SEPOLIA_ROUTER "transferRemote(uint32,bytes32,uint256)" "17864" "0x000000000000000000000000a43b806d2f09ae94dfa38bc00d6f75426d274540" "5000000000000000" --value 5000000000000001wei +cast send --rpc-url $SEPOLIA_URL --private-key $PRIVATE_KEY $SEPOLIA_ROUTER "transferRemote(uint32,bytes32,uint256)" "17864" "0x000000000000000000000000a43b806d2f09ae94dfa38bc00d6f75426d274540" "5000000000000000" --value 5000000000000001wei -# Block until ERC20 balance is incremented +# Block until native balance is incremented MAX_RETRIES=20 RETRY_COUNT=0 -while [ $(printf '%d' $(cast call $SIDECHAIN_ROUTER "balanceOf(address)" $ADDRESS)) -eq $(printf '%d' $SIDECHAIN_ERC20_BALANCE) ] +while [ $(printf '%d' $(cast balance --rpc-url $SIDECHAIN_URL $ADDRESS)) -eq $(printf '%d' $SIDECHAIN_ERC20_BALANCE) ] do - echo "Waiting for ERC20 balance to increment..." + echo "Waiting for native balance to increment..." sleep 5 RETRY_COUNT=$((RETRY_COUNT + 1)) @@ -37,22 +48,29 @@ do done # Store sepolia balance -SEPOLIA_BALANCE=$(cast balance --rpc-url https://ethereum-sepolia.publicnode.com $ADDRESS) +SEPOLIA_BALANCE=$(cast balance --rpc-url $SEPOLIA_URL $ADDRESS) # Send some sidechain ether from genesis funded account to pay for tx fees on sidechain -cast send --private-key 0xc065f4c9a6dda0785e2224f5af8e473614de1c029acf094f03d5830e2dd5b0ea $ADDRESS --value 0.1ether +cast send --rpc-url $SIDECHAIN_URL --private-key 0xc065f4c9a6dda0785e2224f5af8e473614de1c029acf094f03d5830e2dd5b0ea $ADDRESS --value 0.1ether sleep 5 # dest chain -> sepolia (account must be funded on dest chain) -cast call $SIDECHAIN_ROUTER "quoteGasPayment(uint32)" "11155111" +cast call --rpc-url $SIDECHAIN_URL $SIDECHAIN_ROUTER "quoteGasPayment(uint32)" "11155111" # Above returns 0 wei, therefore ether value is same as function argument -cast send --private-key $PRIVATE_KEY $SIDECHAIN_ROUTER "transferRemote(uint32,bytes32,uint256)" "11155111" "0x000000000000000000000000a43b806d2f09ae94dfa38bc00d6f75426d274540" "5000000000000000" --value 500000000000000wei +cast send \ + --rpc-url $SIDECHAIN_URL \ + --private-key $PRIVATE_KEY \ + $SIDECHAIN_ROUTER "transferRemote(uint32,bytes32,uint256)" \ + "11155111" \ + "0x000000000000000000000000a43b806d2f09ae94dfa38bc00d6f75426d274540" \ + "5000000000000000" \ + --value 500000000000000wei # Block until sepolia balance is incremented MAX_RETRIES=30 RETRY_COUNT=0 -while [ $(cast balance --rpc-url https://ethereum-sepolia.publicnode.com $ADDRESS) -eq $SEPOLIA_BALANCE ] +while [ $(cast balance --rpc-url $SEPOLIA_URL $ADDRESS) -eq $SEPOLIA_BALANCE ] do echo "Waiting for sepolia balance to increment..." sleep 5 diff --git a/geth-poa/util/test_whitelist.sh b/geth-poa/util/test_whitelist.sh new file mode 100755 index 0000000000..d9b00d47ae --- /dev/null +++ b/geth-poa/util/test_whitelist.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi +HYP_ERC20_ADDR="$1" + +# Make sure whitelist deployer is 0xBcA333b67fb805aB18B4Eb7aa5a0B09aB25E5ce2 to produce this addr +WHITELIST_ADDR=0xaE476470bfc00B8a0e8531133bE621e87a981ec8 +RPC_URL=http://localhost:8545 + +# Checks that contract deployed to expected address +DATA='{"jsonrpc":"2.0","method":"eth_getCode","params":["'$WHITELIST_ADDR'", "latest"],"id":1}' +RESPONSE=$(curl -s -X POST --data "$DATA" -H "Content-Type: application/json" $RPC_URL) +CODE=$(echo $RESPONSE | jq -r '.result') +if [ -z "$RESPONSE" ] || [ "$RESPONSE" == "null" ]; then + echo "Error: No response from JSON RPC at $RPC_URL" + exit 1 +fi +if [ "$CODE" != "0x" ]; then + echo "Contract deployed at $WHITELIST_ADDR" +else + echo "No contract deployed at $WHITELIST_ADDR! geth and hyperlane hardcodes will not work" + exit 0 +fi + +IS_WHITELISTED=$(cast call $WHITELIST_ADDR \ + "isWhitelisted(address)(bool)" $HYP_ERC20_ADDR \ + --rpc-url $RPC_URL) +if [ "$IS_WHITELISTED" == "false" ]; then + echo "Error: HYP_ERC20_ADDR $HYP_ERC20_ADDR not whitelisted" + exit 1 +fi +echo "HYP_ERC20_ADDR $HYP_ERC20_ADDR is whitelisted" + +OWNER=$(cast call $WHITELIST_ADDR \ + "owner()(address)" \ + --rpc-url $RPC_URL) +if [ "$OWNER" != "0xBcA333b67fb805aB18B4Eb7aa5a0B09aB25E5ce2" ]; then + echo "Error: Whitelist owner is not 0xBcA333b67fb805aB18B4Eb7aa5a0B09aB25E5ce2" + exit 1 +fi +echo "Whitelist owner is 0xBcA333b67fb805aB18B4Eb7aa5a0B09aB25E5ce2" \ No newline at end of file From 205a1b31d6c9701c5cf0b33e8fd9cd470b5475b0 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Thu, 21 Dec 2023 03:05:29 -0800 Subject: [PATCH 2/7] verbose precompile logging --- core/vm/contracts_with_ctx.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/vm/contracts_with_ctx.go b/core/vm/contracts_with_ctx.go index c1109c1ed0..9fd288edcc 100644 --- a/core/vm/contracts_with_ctx.go +++ b/core/vm/contracts_with_ctx.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/math" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" ) @@ -84,6 +85,7 @@ const whitelistCreate2Addr = "0x07e77fdc3DF92E58c9230eEFaABdBd92a8D0c2Af" func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) { if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { + log.Error("Error parsing transfer: caller not whitelisted") return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted") } @@ -92,7 +94,8 @@ func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) { var parsed bool value, parsed := math.ParseBig256(hexutil.Encode(input[32:64])) if !parsed { - return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[64:96])) + log.Error("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64])) + return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64])) } // Create native token out of thin air @@ -112,6 +115,7 @@ func (c *burn) RequiredGas(input []byte) uint64 { func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) { if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { + log.Error("Error parsing transfer: caller not whitelisted") return nil, fmt.Errorf("Error parsing transfer: caller not whitelisted") } @@ -120,10 +124,13 @@ func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) { var parsed bool value, parsed := math.ParseBig256(hexutil.Encode(input[32:64])) if !parsed { - return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[64:96])) + log.Error("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64])) + return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64])) } if !ctx.CanTransfer(ctx.evm.StateDB, burnFrom, value) { + log.Error("Error parsing transfer, address: " + burnFrom.Hex() + " has insufficient balance. " + + value.String() + " needed " + ctx.evm.StateDB.GetBalance(burnFrom).String() + " available") return nil, ErrInsufficientBalance } ctx.evm.StateDB.SubBalance(burnFrom, value) From 3e2ff2b1865a12bdc7311c5df9179c564b45bd3e Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Thu, 21 Dec 2023 03:45:47 -0800 Subject: [PATCH 3/7] rm canTransfer check along with nits --- core/vm/contracts_with_ctx.go | 8 +++----- geth-poa/hyperlane-deployer/chain-config.yml | 2 +- geth-poa/util/test_bridge.sh | 2 ++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/vm/contracts_with_ctx.go b/core/vm/contracts_with_ctx.go index 9fd288edcc..d2df8091f4 100644 --- a/core/vm/contracts_with_ctx.go +++ b/core/vm/contracts_with_ctx.go @@ -112,6 +112,9 @@ func (c *burn) RequiredGas(input []byte) uint64 { return 100 } +// Note ctx.CanTransfer method obtains an incorrect balance w.r.t "burnFrom" address, +// specifically during estimateGas. The CanTransfer check was therefore removed, +// and the calling contract is responsible for checking balance. func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) { if ctx.caller != common.HexToAddress(whitelistCreate2Addr) { @@ -128,11 +131,6 @@ func (c *burn) Run(input []byte, ctx *precompileContext) ([]byte, error) { return nil, fmt.Errorf("Error parsing transfer: unable to parse value from " + hexutil.Encode(input[32:64])) } - if !ctx.CanTransfer(ctx.evm.StateDB, burnFrom, value) { - log.Error("Error parsing transfer, address: " + burnFrom.Hex() + " has insufficient balance. " + - value.String() + " needed " + ctx.evm.StateDB.GetBalance(burnFrom).String() + " available") - return nil, ErrInsufficientBalance - } ctx.evm.StateDB.SubBalance(burnFrom, value) return input, nil diff --git a/geth-poa/hyperlane-deployer/chain-config.yml b/geth-poa/hyperlane-deployer/chain-config.yml index 8219b43d0d..829b9ab2df 100644 --- a/geth-poa/hyperlane-deployer/chain-config.yml +++ b/geth-poa/hyperlane-deployer/chain-config.yml @@ -38,4 +38,4 @@ mevcommitsettlement: # Partial override sepolia config for custom rpc sepolia: rpcUrls: - - http: https://1rpc.io/sepolia + - http: https://eth-sepolia.g.alchemy.com/v2/a0wg_g1X-Wz4IeVA-0SS3PsQhbyQNjc_ diff --git a/geth-poa/util/test_bridge.sh b/geth-poa/util/test_bridge.sh index 2faa4b2b41..8f379e2ba4 100755 --- a/geth-poa/util/test_bridge.sh +++ b/geth-poa/util/test_bridge.sh @@ -2,6 +2,8 @@ set -x set -e +# TODO: Stress test bridge back to sepolia, including not having enough balance on sidechain. + read -p "Has the whitelist contract been deployed, updated with hypERC20 addr, and have router addresss been pasted into this file? (y/n): " answer if [ "$answer" = "y" ]; then echo "Continuing with bridging process..." From e2d4d6416d8f5deeaf1c9c54026cac2516121301 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Thu, 21 Dec 2023 04:02:05 -0800 Subject: [PATCH 4/7] updates tests --- geth-poa/util/test_bridge.sh | 1 + geth-poa/util/test_whitelist.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/geth-poa/util/test_bridge.sh b/geth-poa/util/test_bridge.sh index 8f379e2ba4..6b607d276a 100755 --- a/geth-poa/util/test_bridge.sh +++ b/geth-poa/util/test_bridge.sh @@ -3,6 +3,7 @@ set -x set -e # TODO: Stress test bridge back to sepolia, including not having enough balance on sidechain. +# TODO: redeploy with new contract that checks balance at non-precompile level. read -p "Has the whitelist contract been deployed, updated with hypERC20 addr, and have router addresss been pasted into this file? (y/n): " answer if [ "$answer" = "y" ]; then diff --git a/geth-poa/util/test_whitelist.sh b/geth-poa/util/test_whitelist.sh index d9b00d47ae..78b30458ea 100755 --- a/geth-poa/util/test_whitelist.sh +++ b/geth-poa/util/test_whitelist.sh @@ -7,7 +7,7 @@ fi HYP_ERC20_ADDR="$1" # Make sure whitelist deployer is 0xBcA333b67fb805aB18B4Eb7aa5a0B09aB25E5ce2 to produce this addr -WHITELIST_ADDR=0xaE476470bfc00B8a0e8531133bE621e87a981ec8 +WHITELIST_ADDR=0xF06aC11D2151Dd56b3766Cfc350F42234a2D17f4 RPC_URL=http://localhost:8545 # Checks that contract deployed to expected address From 8b886d1ce73574f79ff721facd3b5d926e01202a Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Fri, 22 Dec 2023 04:09:31 -0800 Subject: [PATCH 5/7] whitelist addr updated for https://github.com/primevprotocol/contracts/pull/65 --- core/vm/contracts_with_ctx.go | 2 +- geth-poa/hyperlane-deployer/Dockerfile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/vm/contracts_with_ctx.go b/core/vm/contracts_with_ctx.go index d2df8091f4..cd5b7733cc 100644 --- a/core/vm/contracts_with_ctx.go +++ b/core/vm/contracts_with_ctx.go @@ -80,7 +80,7 @@ func (c *mint) RequiredGas(input []byte) uint64 { // Predetermined create2 address of whitelist contract with exclusive mint/burn privileges. // This address assumes deployer is 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266. -const whitelistCreate2Addr = "0x07e77fdc3DF92E58c9230eEFaABdBd92a8D0c2Af" +const whitelistCreate2Addr = "0x5D1415C0973034d162F5FEcF19B50dA057057e29" func (c *mint) Run(input []byte, ctx *precompileContext) ([]byte, error) { diff --git a/geth-poa/hyperlane-deployer/Dockerfile b/geth-poa/hyperlane-deployer/Dockerfile index c08fa17c88..8e8e2ac171 100644 --- a/geth-poa/hyperlane-deployer/Dockerfile +++ b/geth-poa/hyperlane-deployer/Dockerfile @@ -7,8 +7,8 @@ WORKDIR / RUN git clone https://github.com/primevprotocol/hyperlane-monorepo.git WORKDIR /hyperlane-monorepo # Hyperlane 3.5 release w/ merged primev changes -# https://github.com/primevprotocol/hyperlane-monorepo/commit/ce1fe3f05e915823ecc355e8d764f010b4b38fa9 -RUN git checkout ce1fe3f05e915823ecc355e8d764f010b4b38fa9 +# https://github.com/primevprotocol/hyperlane-monorepo/commit/1c8cdc9e57389024274242d28e032a2de535c2c7 +RUN git checkout 1c8cdc9e57389024274242d28e032a2de535c2c7 RUN yarn install RUN yarn build From af5c3dd68daa49a845e47c4b81dbc549177e7205 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Fri, 22 Dec 2023 04:32:47 -0800 Subject: [PATCH 6/7] fix test_whitelist --- geth-poa/util/test_whitelist.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/geth-poa/util/test_whitelist.sh b/geth-poa/util/test_whitelist.sh index 78b30458ea..7c7c060509 100755 --- a/geth-poa/util/test_whitelist.sh +++ b/geth-poa/util/test_whitelist.sh @@ -6,8 +6,8 @@ if [ -z "$1" ]; then fi HYP_ERC20_ADDR="$1" -# Make sure whitelist deployer is 0xBcA333b67fb805aB18B4Eb7aa5a0B09aB25E5ce2 to produce this addr -WHITELIST_ADDR=0xF06aC11D2151Dd56b3766Cfc350F42234a2D17f4 +WHITELIST_ADDR=0x5D1415C0973034d162F5FEcF19B50dA057057e29 +EXPECTED_OWNER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 RPC_URL=http://localhost:8545 # Checks that contract deployed to expected address @@ -37,8 +37,8 @@ echo "HYP_ERC20_ADDR $HYP_ERC20_ADDR is whitelisted" OWNER=$(cast call $WHITELIST_ADDR \ "owner()(address)" \ --rpc-url $RPC_URL) -if [ "$OWNER" != "0xBcA333b67fb805aB18B4Eb7aa5a0B09aB25E5ce2" ]; then - echo "Error: Whitelist owner is not 0xBcA333b67fb805aB18B4Eb7aa5a0B09aB25E5ce2" +if [ "$OWNER" != "$EXPECTED_OWNER" ]; then + echo "Error: Whitelist owner is not $EXPECTED_OWNER" exit 1 fi -echo "Whitelist owner is 0xBcA333b67fb805aB18B4Eb7aa5a0B09aB25E5ce2" \ No newline at end of file +echo "Whitelist owner is $EXPECTED_OWNER" From f82e235b75f6d397a2b56753e9adee2a6cb4baa6 Mon Sep 17 00:00:00 2001 From: Shawn <44221603+shaspitz@users.noreply.github.com> Date: Fri, 22 Dec 2023 04:52:23 -0800 Subject: [PATCH 7/7] fix bridge test --- geth-poa/util/test_bridge.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/geth-poa/util/test_bridge.sh b/geth-poa/util/test_bridge.sh index 6b607d276a..569f75bad0 100755 --- a/geth-poa/util/test_bridge.sh +++ b/geth-poa/util/test_bridge.sh @@ -3,7 +3,6 @@ set -x set -e # TODO: Stress test bridge back to sepolia, including not having enough balance on sidechain. -# TODO: redeploy with new contract that checks balance at non-precompile level. read -p "Has the whitelist contract been deployed, updated with hypERC20 addr, and have router addresss been pasted into this file? (y/n): " answer if [ "$answer" = "y" ]; then @@ -20,8 +19,8 @@ ADDRESS=0xa43b806D2f09AE94dfa38bc00d6F75426D274540 PRIVATE_KEY=0x8b21e3bc5c26d3327109d341d121fbfb7cb79c95fba5eb2f8c064f87332df7dd # "make print-warp-deploy" prints these contract addrs -SEPOLIA_ROUTER=0xdFB826f7F5E8d4843f54792369F64eF633E5c4cF -SIDECHAIN_ROUTER=0x79Df08515c2b88daa9C407271844afFD31A4c979 +SEPOLIA_ROUTER=0x2a3840332456e1C27ddd493f89fF33402450C537 +SIDECHAIN_ROUTER=0x707719517b112c9A3F571709e59Cfbaa28fCf873 SEPOLIA_URL=https://ethereum-sepolia.publicnode.com SIDECHAIN_URL=http://localhost:8545 @@ -37,7 +36,7 @@ cast send --rpc-url $SEPOLIA_URL --private-key $PRIVATE_KEY $SEPOLIA_ROUTER "tra # Block until native balance is incremented MAX_RETRIES=20 RETRY_COUNT=0 -while [ $(printf '%d' $(cast balance --rpc-url $SIDECHAIN_URL $ADDRESS)) -eq $(printf '%d' $SIDECHAIN_ERC20_BALANCE) ] +while [ $(printf '%d' $(cast balance --rpc-url $SIDECHAIN_URL $ADDRESS)) -eq $(printf '%d' $SIDECHAIN_BALANCE) ] do echo "Waiting for native balance to increment..." sleep 5