Skip to content

immutable/zkevm-bridge-contracts

Folders and files

NameName
Last commit message
Last commit date
Oct 24, 2023
Oct 25, 2023
Oct 16, 2023
Oct 3, 2023
Oct 25, 2023
Oct 25, 2023
Oct 25, 2023
Oct 24, 2023
Oct 23, 2023
Oct 3, 2023
Oct 3, 2023
Sep 26, 2023
Oct 3, 2023
Oct 25, 2023
Oct 3, 2023
Oct 23, 2023
Sep 26, 2023
Oct 16, 2023
Oct 3, 2023
Oct 23, 2023
Oct 23, 2023

Repository files navigation

Immutable zkEVM Bridge Contracts

(Work in progress doc)

zkevm-bridge-contracts is a repository of smart contracts for bridging in the Immutable zkEVM, a general-purpose permissionless L2 zero-knowledge rollup.

These contracts are used in the ERC20 and native ETH bridging functionality of the Immutable zkEVM.

The main development toolkit for this repository is Foundry Foundry consists of:

  • Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
  • Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
  • Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
  • Chisel: Fast, utilitarian, and verbose solidity REPL.

Usage

Install Dependencies

$ forge install

Build

$ forge build

Test

$ forge test

Format

$ forge fmt

Gas Snapshots

$ forge snapshot

Local Deployment

Pre-requisites

jq will need to be installed before running the scripts. This can be done with brew install jq on a mac, or see here for an online guide.

You will also need to run forge install to install dependencies.

Instructions

To set up the contracts on two separate local networks, we need to start running the local networks, then run ./deploy.sh, which will run all four Forge scripts to deploy and initialize the contracts.

  1. Set up the two local networks. e.g: anvil -p 8545 --chain-id 31337 and in another terminal: anvil -p 8546 --chain-id 31338 Note that we set the ports and chain IDs to be unique.

  2. Update environment variables with RPC URLs, chain IDs, and private keys. Using the networks set up in step 1, our .env file will include the following lines:

ROOT_RPC_URL="http://127.0.0.1:8545"
CHILD_RPC_URL="http://127.0.0.1:8546"
ROOT_CHAIN_ID="31337"
CHILD_CHAIN_ID="31338"
ROOT_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
CHILD_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

The private keys used are the default anvil keys.

  1. Fill other environment variables. The variables needed are:
ROOT_GATEWAY_ADDRESS=
CHILD_GATEWAY_ADDRESS=
ROOT_GAS_SERVICE_ADDRESS=
CHILD_GAS_SERVICE_ADDRESS=
ROOT_CHAIN_NAME="ROOT"
CHILD_CHAIN_NAME="CHILD"
ROOT_IMX_ADDRESS=
CHILD_ETH_ADDRESS=

where {ROOT,CHILD}_{GATEWAY,GAS_SERVICE}_ADDRESS refers to the gateway and gas service addresses used by Axelar.

We can just use dummy gateway/gas service addresses if we only want to test the deployment, and not bridging functionality. If wanting to use dummy addresses, any valid Ethereum address can be used here.

  1. Run the deploy script. deploy.sh

  2. Get contract addresses from addresses.json.

Remote Deployment

When deploying these contracts on remote networks (i.e. testnets or mainnets), the instructions are the same as above, but:

  • step 1 (deploying the networks) should be skipped.
  • in step 2:
    • The RPC URLs and Chain IDs should be set for the targetted networks.
    • The private keys should be for addresses with which the contracts are to be deployed.

Axelar Local Bridge

One-time setup
  1. install the dependencies
yarn install
  1. compile the smart contracts
forge build
Start & setup the local blockchains
  1. Start the local blockchains and local Axelar network
yarn start
  1. Set the following env vars in your .env file
ROOT_RPC_URL="http://localhost:8500/0"
CHILD_RPC_URL="http://localhost:8500/1"
ROOT_CHAIN_ID="2500"
CHILD_CHAIN_ID="2501"
  1. In a separate terminal window, deploy the smart contracts
./deploy.sh
  1. Copy the config file with the correct addresses
cp axelar-local-dev/chain-config/local.template.json axelar-local-dev/chain-config/local.json
  1. Run the script to execute the axelar-local-dev/examples/evm/call-contract/index.js file
yarn run execute evm/call-contract local Ethereum Polygon