Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test-pp-op/2-deploy-op-contracts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ deploy_transactor() {
FORGE_CMD="forge create --json --broadcast --legacy \
--rpc-url $L1_RPC_URL_IN_DOCKER \
--private-key $DEPLOYER_PRIVATE_KEY \
src/periphery/Transactor.sol:Transactor.0.8.30 \
src/periphery/Transactor.sol:Transactor \
--constructor-args $ADMIN_OWNER_ADDRESS"

echo "🔧 Executing Docker command..."
Expand Down
2 changes: 1 addition & 1 deletion test-pp-op/3-stop-erigon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cd $PWD_DIR
## Stop X Layer services
echo "DOCKER_COMPOSE_CMD: ${DOCKER_COMPOSE_CMD}"
${DOCKER_COMPOSE_CMD} stop xlayer-seq
#${DOCKER_COMPOSE_CMD} stop xlayer-rpc
${DOCKER_COMPOSE_CMD} stop xlayer-rpc
${DOCKER_COMPOSE_CMD} stop xlayer-bridge-service
${DOCKER_COMPOSE_CMD} stop xlayer-bridge-ui
${DOCKER_COMPOSE_CMD} stop xlayer-agg-sender
Expand Down
47 changes: 47 additions & 0 deletions test-pp-op/6-upgrade-ger-contract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package test_pp_op


set -e
set -x
source .env
source ./utils.sh

cast send $TIMELOCK_OVERRIDE_PROPOSER_ADDRESS --value 1ether --from $DEPLOYER_ADDRESS --private-key $DEPLOYER_PRIVATE_KEY --rpc-url $L2_SEQ_URL
cast send $TIMELOCK_OVERRIDE_EXECUTOR_ADDRESS --value 1ether --from $DEPLOYER_ADDRESS --private-key $DEPLOYER_PRIVATE_KEY --rpc-url $L2_SEQ_URL


cd $TMP_DIR/xlayer-contracts/

cd upgrade/upgradeToV2

echo "Creating upgrade_parameters.json..."
cat > upgrade_parameters.json << EOF
{
"timelockDelay": $TIME_LOCK_DELAY,
"timelockSalt": "",
"globalExitRootUpdater": "$ORACLE_ADDRESS",
"globalExitRootRemover": "$ORACLE_ADDRESS"
}
EOF

cp ../../deployment/v2/deploy_parameters.json ./deploy_parameters.json
cp ../../deployment/v2/deploy_output.json ./deploy_output.json

sed_inplace '1s/{/{\n "polygonZkEVMGlobalExitRootL2Address": "0xa40d5f56745a118d0906a34e69aec8c0db1cb8fa",/' deploy_output.json

cd ../../

hardhat_output=$(npm run upgradeL2GER:timelock:l2localhost)
echo "hardhat_output: $hardhat_output"

schedule_data=$(echo "$hardhat_output" | awk -F"'" '/scheduleData:/ {print $2}')
execute_data=$(echo "$hardhat_output" | awk -F"'" '/executeData:/ {print $2}')
echo "schedule_data: $schedule_data"
echo "execute_data: $execute_data"

cast send --rpc-url "$L2_SEQ_URL" -f $TIMELOCK_OVERRIDE_PROPOSER_ADDRESS --private-key "$TIMELOCK_OVERRIDE_PROPOSER_PRIVATE_KEY" "$TIME_LOCK_ADDRESS" "$schedule_data"

sleep $TIME_LOCK_DELAY
cast send --rpc-url "$L2_SEQ_URL" -f $TIMELOCK_OVERRIDE_EXECUTOR_ADDRESS --private-key "$TIMELOCK_OVERRIDE_EXECUTOR_PRIVATE_KEY" "$TIME_LOCK_ADDRESS" "$execute_data"
sleep 5
cast call --rpc-url "$L2_SEQ_URL" $GER_MANAGER_ADDRESS 'GER_SOVEREIGN_VERSION()(string)'
40 changes: 40 additions & 0 deletions test-pp-op/7-start-agg-bridge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
set -e
set -x
source .env
source tools.sh
source utils.sh

# fund the oracle
cast send -f $DEPLOYER_ADDRESS --private-key $DEPLOYER_PRIVATE_KEY --value 1ether $ORACLE_ADDRESS --rpc-url $L2_SEQ_URL

cd $PWD_DIR

sed_inplace 's/http:\/\/xlayer-rpc:8545/http:\/\/op-geth-seq:8545/' config/agglayer-config.toml
sed_inplace 's/http:\/\/xlayer-rpc:8545/http:\/\/op-geth-seq:8545/' config/aggkit.toml
sed_inplace '/\[BridgeL2Sync\]/a\
InitialBlockNum = '$FORK_BLOCK'
' config/aggkit.toml
sed_inplace 's/http:\/\/xlayer-rpc:8545/http:\/\/op-geth-seq:8545/' config/test.bridge.config.toml
sed_inplace 's/RequireSovereignChainSmcs = \[false\]/RequireSovereignChainSmcs = \[true\]/' config/test.bridge.config.toml
sed_inplace '/\[NetworkConfig\]/a\
L2GenBlockNumber = '$FORK_BLOCK'
' config/test.bridge.config.toml

while true; do
sleep 10
L2_BLOCK_HEIGHT=$(cast block-number --rpc-url $L2_SEQ_URL)
if [ "$L2_BLOCK_HEIGHT" -ge "$FORK_BLOCK" ]; then
echo "L2 block height $L2_BLOCK_HEIGHT has reached fork block $FORK_BLOCK"
sleep 10
break
fi
echo "Waiting for L2 block height to reach $FORK_BLOCK (current: $L2_BLOCK_HEIGHT)"
done

${DOCKER_COMPOSE_CMD} up -d xlayer-oracle
sleep 5
${DOCKER_COMPOSE_CMD} up -d xlayer-bridge-service
sleep 10
docker rm xlayer-bridge-ui
${DOCKER_COMPOSE_CMD} up -d xlayer-bridge-ui
${DOCKER_COMPOSE_CMD} up -d xlayer-agg-sender
171 changes: 171 additions & 0 deletions test-pp-op/8-test-agg-bridge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#!/bin/bash
set -e
set -x
source .env

BRIDGE_VALUE_BIG="1000000000000000000" # 1 ETH in wei
BRIDGE_VALUE_SMALL="100000000000000000" # 0.1 ETH in wei

# Get Global Exit Root Manager address
GER_MGR=$(cast call "$BRIDGE_ADDRESS" "globalExitRootManager()(address)" --rpc-url "$L1_RPC_URL")
L2GER_MGR1=$(cast call "$BRIDGE_ADDRESS" "globalExitRootManager()(address)" --rpc-url "$L2_SEQ_URL")
echo "GlobalExitRootManager Address:"
echo " L1 ==> $GER_MGR"
echo " L2 ==> $L2GER_MGR1"

# Get initial Global Exit Root
GER=$(cast call "$GER_MGR" "getLastGlobalExitRoot()" --rpc-url "$L1_RPC_URL")
echo "Initial GER on L1: $GER"

# =============================================================================
# Bridge from L1 to L2
# =============================================================================

# Check balance before bridging
L2_BALANCE_BEFORE_BRIDGE=$(cast call "$L2_WETH" "balanceOf(address)(uint256)" "$DEPLOYER_ADDRESS" --rpc-url "$L2_SEQ_URL" | awk '{print $1}')

cast send \
--legacy \
--rpc-url $L1_RPC_URL \
--private-key $DEPLOYER_PRIVATE_KEY \
--value $BRIDGE_VALUE_BIG \
$BRIDGE_ADDRESS \
'function bridgeAsset(uint32 destinationNetwork, address destinationAddress, uint256 amount, address token, bool forceUpdateGlobalExitRoot, bytes permitData) returns()' \
1 $DEPLOYER_ADDRESS $BRIDGE_VALUE_BIG $L1_ETH_ADDRESS true 0x

# Wait for GER update on L1
echo "Waiting for GER to be updated on L1..."
while true; do
GER_NEW=$(cast call "$GER_MGR" "getLastGlobalExitRoot()" --rpc-url "$L1_RPC_URL")
if [ "$GER_NEW" != "$GER" ]; then
GER=$GER_NEW
echo "GER updated to $GER on L1"
break
fi
sleep 10
done

# Wait for GER to sync to L2
echo "Waiting for GER to sync to L2..."
start_time=$(date +%s)
while true; do
timestamp=$(cast call "$L2GER_MGR1" "globalExitRootMap(bytes32)(uint256)" "$GER" --rpc-url "$L2_SEQ_URL")
if [ "$timestamp" != "0" ]; then
break
fi
sleep 15
done
end_time=$(date +%s)
total_elapsed=$((end_time - start_time))
echo "GER synced to L2, took $total_elapsed seconds"

# Wait for assets to be claimed automatically by sponsor
echo "Waiting for assets to be claimed by sponsor..."
start_time=$(date +%s)
while true; do
sleep 60
balance=$(cast call "$L2_WETH" "balanceOf(address)(uint256)" "$DEPLOYER_ADDRESS" --rpc-url "$L2_SEQ_URL" | awk '{print $1}')
balance=${balance:-0}
increment=$(echo "$balance - $L2_BALANCE_BEFORE_BRIDGE" | bc)
echo "Current balance on L2: $balance (increment: $increment)"
if [ "$increment" -gt 0 ]; then
echo "Assets successfully claimed on L2"
break
fi
done
end_time=$(date +%s)
total_elapsed=$((end_time - start_time))
echo "Balance on L2 is $balance, claim took $total_elapsed seconds"

# Check balance after bridging
L2_BALANCE_AFTER_BRIDGE=$(cast balance "$DEPLOYER_ADDRESS" --rpc-url "$L2_SEQ_URL")
echo "Balance on L2(ETH):"
echo " Before bridge = $L2_BALANCE_BEFORE_BRIDGE"
echo " After bridge = $L2_BALANCE_AFTER_BRIDGE"

# =============================================================================
# Bridge from L2 to L1
# =============================================================================
echo -e "\n========== Bridging Assets: L2 -> L1 BRIDGE_VALUE_SMALL =========="

# Approve token
echo "Approving token..."
cast send \
--legacy \
--rpc-url $L2_SEQ_URL \
--private-key $DEPLOYER_PRIVATE_KEY \
"$L2_WETH" \
"function approve(address spender, uint256 amount) returns (bool)" \
$BRIDGE_ADDRESS \
$BRIDGE_VALUE_BIG

# Initiate bridging transaction
TX_HASH=$(cast send \
--legacy \
--private-key $DEPLOYER_PRIVATE_KEY \
--rpc-url $L2_SEQ_URL \
--json \
$BRIDGE_ADDRESS \
'function bridgeAsset(uint32 destinationNetwork, address destinationAddress, uint256 amount, address token, bool forceUpdateGlobalExitRoot, bytes permitData) returns()' \
0 $DEPLOYER_ADDRESS $BRIDGE_VALUE_SMALL $L2_WETH true "0x" \
| jq -r ' .transactionHash')
echo "Bridge transaction hash: $TX_HASH"

# Wait for GER update on L1
echo "Waiting for GER to be updated on L1..."
start_time=$(date +%s)
while true; do
GER_NEW=$(cast call "$GER_MGR" "getLastGlobalExitRoot()" --rpc-url "$L1_RPC_URL")
if [ "$GER_NEW" != "$GER" ]; then
GER=$GER_NEW
break
fi
sleep 10
done
end_time=$(date +%s)
total_elapsed=$((end_time - start_time))
echo "GER updated to $GER on L1, took $total_elapsed seconds"

sleep 40
echo "Getting deposit count and network ID from bridge service..."
result=$(curl -s "$BRIDGE_SERVICE/bridges/$DEPLOYER_ADDRESS?limit=20000&offset=0" | \
jq -r '.deposits[] | select(.ready_for_claim == true and .claim_tx_hash == "" and .tx_hash=="'$TX_HASH'")')
DEPOSIT_CNT=$(echo "$result" | jq -r '.deposit_cnt')
NETWORK_ID=$(echo "$result" | jq -r '.network_id')
GLOBAL_INDEX=$(echo "$result" | jq -r '.global_index')
ORINGIN_NETWORK=$(echo "$result" | jq -r '.orig_net')
ORINGIN_ADDRESS=$(echo "$result" | jq -r '.orig_addr')
DESTINATION_NETWORK=$(echo "$result" | jq -r '.dest_net')
IN_AMOUNT=$(echo "$result" | jq -r '.amount')
METADATA=$(echo "$result" | jq -r '.metadata')
echo "Deposit Count: $DEPOSIT_CNT"
echo "Network ID: $NETWORK_ID"
echo "Global Index: $GLOBAL_INDEX"
echo "Origin Network: $ORINGIN_NETWORK"
echo "Origin Address: $ORINGIN_ADDRESS"
echo "Destination Network: $DESTINATION_NETWORK"
echo "In Amount: $IN_AMOUNT"
echo "Metadata: $METADATA"

proof=$(curl -s "$BRIDGE_SERVICE/merkle-proof?deposit_cnt=$DEPOSIT_CNT&net_id=$NETWORK_ID" | jq -r '.')
MERKLE_PROOF=$(echo "$proof" | jq -r -c '.proof | .merkle_proof' | tr -d '"')
ROLLUP_MERKLE_PROOF=$(echo "$proof" | jq -r -c '.proof | .rollup_merkle_proof' | tr -d '"')
MER=$(echo "$proof" | jq -r '.proof | .main_exit_root')
RER=$(echo "$proof" | jq -r '.proof | .rollup_exit_root')
echo "Merkle Proof: $MERKLE_PROOF"
echo "Rollup Merkle Proof: $ROLLUP_MERKLE_PROOF"
echo "Main Exit Root: $MER"
echo "Rollup Exit Root: $RER"

# Claim assets on L1
echo "Claiming assets on L1..."
L1_BALANCE_BEFORE_CLAIM=$(cast balance "$DEPLOYER_ADDRESS" --rpc-url "$L1_RPC_URL")
cmd="cast send --legacy --rpc-url $L1_RPC_URL --private-key $DEPLOYER_PRIVATE_KEY $BRIDGE_ADDRESS 'claimAsset(bytes32[32],bytes32[32],uint256,bytes32,bytes32,uint32,address,uint32,address,uint256,bytes)' $MERKLE_PROOF $ROLLUP_MERKLE_PROOF $GLOBAL_INDEX $MER $RER $ORINGIN_NETWORK $ORINGIN_ADDRESS $DESTINATION_NETWORK $DEPLOYER_ADDRESS $IN_AMOUNT $METADATA"

echo "Warning!!!!!!!!!! Claim asset on L1, Executing: $cmd"
eval "$cmd"

L1_BALANCE_AFTER_CLAIM=$(cast balance "$DEPLOYER_ADDRESS" --rpc-url "$L1_RPC_URL")
echo "Balance on L1:"
echo " Before claiming: $L1_BALANCE_BEFORE_CLAIM"
echo " After claiming: $L1_BALANCE_AFTER_CLAIM"
File renamed without changes.
1 change: 1 addition & 0 deletions test-pp-op/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ clean: stop
rm -rf config-op/196-*
rm -rf config-op/195-*
rm -rf config-op/1952-*
rm -rf config/genesis.json
rm -rf l1-geth/consensus/beacondata/
rm -rf l1-geth/consensus/genesis.ssz
rm -rf l1-geth/consensus/validatordata/
Expand Down
12 changes: 3 additions & 9 deletions test-pp-op/build_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,12 @@ fi
build_patched_zkevm_bridge_service_image() {
echo "build patched zkevm bridge service image"
PWD_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
rm -rf $PWD_DIR/tmp/zkevm-bridge-service
rm -rf $PWD_DIR/tmp/xlayer-bridge-service
mkdir -p $PWD_DIR/tmp
cd $PWD_DIR/tmp/
git clone -b v0.6.0-RC16 https://github.com/0xPolygon/zkevm-bridge-service.git
git clone -b add-patch https://github.com/okx/xlayer-bridge-service
# it has docker file
cd zkevm-bridge-service

# patch zkevm-bridge-service
git apply $PWD_DIR/patch/xlayer-bridge-service-0001-support-sync-L2-block-at-given-number.patch
git apply $PWD_DIR/patch/xlayer-bridge-service-0002-skip-reorg-check-after-regenesis.patch
git apply $PWD_DIR/patch/xlayer-bridge-service-0003-skip-syncing-blocks-before-regenesis.patch

cd xlayer-bridge-service
docker build --platform $ARCH -t $XLAYER_BRIDGE_SERVICE_IMAGE_TAG .
cd $PWD_DIR
}
Expand Down
Loading