diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a78e451c..fd2eb2a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,36 +2,40 @@ name: CI run-name: CI triggered from @${{ github.actor }} of ${{ github.head_ref }} on: - workflow_dispatch: - merge_group: - pull_request: - push: - branches: - - master - - develop - + workflow_dispatch: + merge_group: + pull_request: + push: + branches: + - master + - develop jobs: build_and_run: runs-on: ubuntu-8 + strategy: + matrix: + pos: [pos, no-pos] + l3node: [l3node, l3node-token-6, no-l3node] + tokenbridge: [tokenbridge, no-tokenbridge] steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: recursive + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - with: - driver-opts: network=host + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + driver-opts: network=host - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile') }} - restore-keys: ${{ runner.os }}-buildx- - - - name: Startup Nitro testnode - run: ${{ github.workspace }}/.github/workflows/testnode.bash + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile') }} + restore-keys: ${{ runner.os }}-buildx- + + - name: Startup Nitro testnode + run: ${{ github.workspace }}/.github/workflows/testnode.bash --init-force ${{ (matrix.l3node == 'l3node' && '--l3node') || (matrix.l3node == 'l3node-token-6' && '--l3node --l3-fee-token --l3-token-bridge --l3-fee-token-decimals 6') || '' }} ${{ matrix.tokenbridge == 'tokenbridge' && '--tokenbridge' || '--no-tokenbridge' }} --no-simple --detach ${{ matrix.pos == 'pos' && '--pos' || '' }} diff --git a/.github/workflows/testnode.bash b/.github/workflows/testnode.bash index 0e57e13d..be7e6961 100755 --- a/.github/workflows/testnode.bash +++ b/.github/workflows/testnode.bash @@ -5,24 +5,36 @@ # Start the test node and get PID, to terminate it once send-l2 is done. cd ${GITHUB_WORKSPACE} -# TODO once develop is merged into nitro-contract's master, remove the NITRO_CONTRACTS_BRANCH env var -./test-node.bash --init-force --l3node --no-simple --detach +./test-node.bash "$@" + +if [ $? -ne 0 ]; then + echo "test-node.bash failed" + docker compose logs --tail=1000 + exit 1 +fi + START=$(date +%s) L2_TRANSACTION_SUCCEEDED=false -L3_TRANSACTION_SUCCEEDED=false +# if we're not running an l3node then we just set l3 to success by default +L3_TRANSACTION_SUCCEEDED=true +for arg in "$@"; do + if [ "$arg" = "--l3node" ]; then + L3_TRANSACTION_SUCCEEDED=false + fi +done SUCCEEDED=false while true; do if [ "$L2_TRANSACTION_SUCCEEDED" = false ]; then - if ${GITHUB_WORKSPACE}/test-node.bash script send-l2 --ethamount 100 --to user_l2user --wait; then + if ${GITHUB_WORKSPACE}/test-node.bash script send-l2 --ethamount 2 --to user_l2user --wait; then echo "Sending l2 transaction succeeded" L2_TRANSACTION_SUCCEEDED=true fi fi if [ "$L3_TRANSACTION_SUCCEEDED" = false ]; then - if ${GITHUB_WORKSPACE}/test-node.bash script send-l3 --ethamount 100 --to user_l3user --wait; then + if ${GITHUB_WORKSPACE}/test-node.bash script send-l3 --ethamount 2 --to user_l3user --wait; then echo "Sending l3 transaction succeeded" L3_TRANSACTION_SUCCEEDED=true fi @@ -44,10 +56,10 @@ while true; do sleep 10 done -docker-compose stop +docker compose stop if [ "$SUCCEEDED" = false ]; then - docker-compose logs + docker compose logs exit 1 fi diff --git a/docker-compose.yaml b/docker-compose.yaml index 81deb6d1..f8facecc 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -47,7 +47,7 @@ services: - "127.0.0.1:6379:6379" geth: - image: ethereum/client-go:v1.10.23 + image: ethereum/client-go:latest ports: - "127.0.0.1:8545:8545" - "127.0.0.1:8551:8551" @@ -77,6 +77,7 @@ services: - --authrpc.jwtsecret=/config/jwt.hex - --nodiscover - --syncmode=full + - --state.scheme=hash - --dev - --dev.period=1 - --mine @@ -91,9 +92,13 @@ services: command: - testnet - generate-genesis + - --fork=deneb - --num-validators=64 + - --genesis-time-delay=15 - --output-ssz=/consensus/genesis.ssz - --chain-config-file=/config/prysm.yaml + - --geth-genesis-json-in=/config/geth_genesis.json + - --geth-genesis-json-out=/config/geth_genesis.json volumes: - "consensus:/consensus" - "config:/config" @@ -108,16 +113,17 @@ services: - --datadir=/consensus/beacondata - --rpc-port=5000 - --min-sync-peers=0 - - --interop-genesis-state=/consensus/genesis.ssz + - --genesis-state=/consensus/genesis.ssz - --interop-eth1data-votes - --bootstrap-node= - --chain-config-file=/config/prysm.yaml - --rpc-host=0.0.0.0 - --grpc-gateway-host=0.0.0.0 - - --chain-id=32382 + - --chain-id=1337 - --execution-endpoint=http://geth:8551 - --accept-terms-of-use - --jwt-secret=/config/jwt.hex + - --suggested-fee-recipient=0x000000000000000000000000000000000000dEaD depends_on: geth: condition: service_started diff --git a/rollupcreator/Dockerfile b/rollupcreator/Dockerfile index 5706b9cb..f6406dad 100644 --- a/rollupcreator/Dockerfile +++ b/rollupcreator/Dockerfile @@ -1,4 +1,4 @@ -FROM node:18.20.3-bullseye-slim +FROM node:18-bullseye-slim ARG NITRO_CONTRACTS_BRANCH=main RUN apt-get update && \ apt-get install -y git docker.io python3 build-essential curl jq diff --git a/scripts/Dockerfile b/scripts/Dockerfile index c5b7050c..ca2c677e 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16-bullseye-slim +FROM node:18-bullseye-slim WORKDIR /workspace COPY ./package.json ./yarn.lock ./ RUN yarn diff --git a/scripts/config.ts b/scripts/config.ts index a131fae9..3edb7a9b 100644 --- a/scripts/config.ts +++ b/scripts/config.ts @@ -13,16 +13,28 @@ PRESET_BASE: interop GENESIS_FORK_VERSION: 0x20000089 # Altair -ALTAIR_FORK_EPOCH: 1 +ALTAIR_FORK_EPOCH: 0 ALTAIR_FORK_VERSION: 0x20000090 # Merge -BELLATRIX_FORK_EPOCH: 2 +BELLATRIX_FORK_EPOCH: 0 BELLATRIX_FORK_VERSION: 0x20000091 TERMINAL_TOTAL_DIFFICULTY: 50 +# Capella +CAPELLA_FORK_EPOCH: 0 +CAPELLA_FORK_VERSION: 0x20000092 +MAX_WITHDRAWALS_PER_PAYLOAD: 16 + +# DENEB +DENEB_FORK_EPOCH: 0 +DENEB_FORK_VERSION: 0x20000093 + +# ELECTRA +ELECTRA_FORK_VERSION: 0x20000094 + # Time parameters -SECONDS_PER_SLOT: 12 +SECONDS_PER_SLOT: 2 SLOTS_PER_EPOCH: 6 # Deposit contract @@ -36,8 +48,7 @@ function writeGethGenesisConfig(argv: any) { { "config": { "ChainName": "l1_chain", - "chainId": 32382, - "consensus": "clique", + "chainId": 1337, "homesteadBlock": 0, "daoForkSupport": true, "eip150Block": 0, @@ -54,13 +65,12 @@ function writeGethGenesisConfig(argv: any) { "terminalBlockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "arrowGlacierBlock": 0, "grayGlacierBlock": 0, - "clique": { - "period": 5, - "epoch": 30000 - }, - "terminalTotalDifficulty": 50 + "shanghaiTime": 0, + "cancunTime": 1706778826, + "terminalTotalDifficulty": 0, + "terminalTotalDifficultyPassed": true }, - "difficulty": "1", + "difficulty": "0", "extradata": "0x00000000000000000000000000000000000000000000000000000000000000003f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E0B0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "nonce": "0x42", "timestamp": "0x0", diff --git a/scripts/consts.ts b/scripts/consts.ts index ff322260..edfcedd6 100644 --- a/scripts/consts.ts +++ b/scripts/consts.ts @@ -5,3 +5,5 @@ export const tokenbridgedatapath = "/tokenbridge-data"; // Not secure. Do not use for production purposes export const l1mnemonic = "indoor dish desk flag debris potato excuse depart ticket judge file exit"; + +export const ARB_OWNER = "0x0000000000000000000000000000000000000070"; \ No newline at end of file diff --git a/scripts/ethcommands.ts b/scripts/ethcommands.ts index 82eeadbc..ac85ed69 100644 --- a/scripts/ethcommands.ts +++ b/scripts/ethcommands.ts @@ -1,11 +1,12 @@ import { runStress } from "./stress"; -import { ContractFactory, ethers, Wallet } from "ethers"; +import { BigNumber, ContractFactory, ethers, Wallet } from "ethers"; import * as consts from "./consts"; import { namedAccount, namedAddress } from "./accounts"; import * as L1GatewayRouter from "@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/ethereum/gateway/L1GatewayRouter.sol/L1GatewayRouter.json"; -import * as ERC20PresetFixedSupplyArtifact from "@openzeppelin/contracts/build/contracts/ERC20PresetFixedSupply.json"; +import * as L1AtomicTokenBridgeCreator from "@arbitrum/token-bridge-contracts/build/contracts/contracts/tokenbridge/ethereum/L1AtomicTokenBridgeCreator.sol/L1AtomicTokenBridgeCreator.json"; import * as ERC20 from "@openzeppelin/contracts/build/contracts/ERC20.json"; import * as fs from "fs"; +import { ARB_OWNER } from "./consts"; const path = require("path"); async function sendTransaction(argv: any, threadId: number) { @@ -59,25 +60,49 @@ async function bridgeNativeToken(argv: any, parentChainUrl: string, chainUrl: st argv.to = "address_" + inboxAddr; - /// approve inbox to use fee token + // snapshot balance before deposit + const childProvider = new ethers.providers.WebSocketProvider(chainUrl); + const bridger = namedAccount(argv.from, argv.threadId).connect(childProvider) + const bridgerBalanceBefore = await bridger.getBalance() + + // get token contract const bridgerParentChain = namedAccount(argv.from, argv.threadId).connect(argv.provider) const nativeTokenContract = new ethers.Contract(token, ERC20.abi, bridgerParentChain) - await nativeTokenContract.approve(inboxAddr, ethers.utils.parseEther(argv.amount)) + + // scale deposit amount + const decimals = await nativeTokenContract.decimals() + const depositAmount = BigNumber.from(argv.amount).mul(BigNumber.from('10').pow(decimals)) + + /// approve inbox to use fee token + await nativeTokenContract.approve(inboxAddr, depositAmount) /// deposit fee token const iface = new ethers.utils.Interface(["function depositERC20(uint256 amount)"]) - argv.data = iface.encodeFunctionData("depositERC20", [ethers.utils.parseEther(argv.amount)]); + argv.data = iface.encodeFunctionData("depositERC20", [depositAmount]); await runStress(argv, sendTransaction); argv.provider.destroy(); if (argv.wait) { - const childProvider = new ethers.providers.WebSocketProvider(chainUrl); - const bridger = namedAccount(argv.from, argv.threadId).connect(childProvider) const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); + + // calculate amount being minted on child chain + let expectedMintedAmount = depositAmount + if(decimals < 18) { + // inflate up to 18 decimals + expectedMintedAmount = depositAmount.mul(BigNumber.from('10').pow(18 - decimals)) + } else if(decimals > 18) { + // deflate down to 18 decimals, rounding up + const quotient = BigNumber.from('10').pow(decimals - 18) + expectedMintedAmount = depositAmount.div(quotient) + if(expectedMintedAmount.mul(quotient).lt(depositAmount)) { + expectedMintedAmount = expectedMintedAmount.add(1) + } + } + while (true) { - const balance = await bridger.getBalance() - if (balance.gte(ethers.utils.parseEther(argv.amount))) { + const bridgerBalanceAfter = await bridger.getBalance() + if (bridgerBalanceAfter.sub(bridgerBalanceBefore).eq(expectedMintedAmount)) { return } await sleep(100) @@ -85,6 +110,34 @@ async function bridgeNativeToken(argv: any, parentChainUrl: string, chainUrl: st } } +async function deployERC20Contract(deployerWallet: Wallet, decimals: number): Promise { + //// Bytecode below is generated from this simple ERC20 token contract which uses custom number of decimals + + // pragma solidity 0.8.16; + // + // import {ERC20} from "lib/openzeppelin-contracts/contracts/token/ERC20/ERC20.sol"; + // + // contract TestToken is ERC20 { + // uint8 private immutable _decimals; + // + // constructor(uint8 decimals_, address mintTo) ERC20("testnode", "TN") { + // _decimals = decimals_; + // _mint(mintTo, 1_000_000_000 * 10 ** decimals_); + // } + // + // function decimals() public view virtual override returns (uint8) { + // return _decimals; + // } + // } + + const erc20TokenBytecode = "0x60a06040523480156200001157600080fd5b5060405162000d4938038062000d49833981016040819052620000349162000195565b60405180604001604052806008815260200167746573746e6f646560c01b815250604051806040016040528060028152602001612a2760f11b815250816003908162000081919062000288565b50600462000090828262000288565b50505060ff8216608052620000c281620000ac84600a62000469565b620000bc90633b9aca0062000481565b620000ca565b5050620004b9565b6001600160a01b038216620001255760405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f206164647265737300604482015260640160405180910390fd5b8060026000828254620001399190620004a3565b90915550506001600160a01b038216600081815260208181526040808320805486019055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b505050565b60008060408385031215620001a957600080fd5b825160ff81168114620001bb57600080fd5b60208401519092506001600160a01b0381168114620001d957600080fd5b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200020f57607f821691505b6020821081036200023057634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156200019057600081815260208120601f850160051c810160208610156200025f5750805b601f850160051c820191505b8181101562000280578281556001016200026b565b505050505050565b81516001600160401b03811115620002a457620002a4620001e4565b620002bc81620002b58454620001fa565b8462000236565b602080601f831160018114620002f45760008415620002db5750858301515b600019600386901b1c1916600185901b17855562000280565b600085815260208120601f198616915b82811015620003255788860151825594840194600190910190840162000304565b5085821015620003445787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b634e487b7160e01b600052601160045260246000fd5b600181815b80851115620003ab5781600019048211156200038f576200038f62000354565b808516156200039d57918102915b93841c93908002906200036f565b509250929050565b600082620003c45750600162000463565b81620003d35750600062000463565b8160018114620003ec5760028114620003f75762000417565b600191505062000463565b60ff8411156200040b576200040b62000354565b50506001821b62000463565b5060208310610133831016604e8410600b84101617156200043c575081810a62000463565b6200044883836200036a565b80600019048211156200045f576200045f62000354565b0290505b92915050565b60006200047a60ff841683620003b3565b9392505050565b60008160001904831182151516156200049e576200049e62000354565b500290565b8082018082111562000463576200046362000354565b608051610874620004d5600039600061011b01526108746000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80633950935111610071578063395093511461014557806370a082311461015857806395d89b4114610181578063a457c2d714610189578063a9059cbb1461019c578063dd62ed3e146101af57600080fd5b806306fdde03146100ae578063095ea7b3146100cc57806318160ddd146100ef57806323b872dd14610101578063313ce56714610114575b600080fd5b6100b66101c2565b6040516100c391906106be565b60405180910390f35b6100df6100da366004610728565b610254565b60405190151581526020016100c3565b6002545b6040519081526020016100c3565b6100df61010f366004610752565b61026e565b60405160ff7f00000000000000000000000000000000000000000000000000000000000000001681526020016100c3565b6100df610153366004610728565b610292565b6100f361016636600461078e565b6001600160a01b031660009081526020819052604090205490565b6100b66102b4565b6100df610197366004610728565b6102c3565b6100df6101aa366004610728565b610343565b6100f36101bd3660046107b0565b610351565b6060600380546101d1906107e3565b80601f01602080910402602001604051908101604052809291908181526020018280546101fd906107e3565b801561024a5780601f1061021f5761010080835404028352916020019161024a565b820191906000526020600020905b81548152906001019060200180831161022d57829003601f168201915b5050505050905090565b60003361026281858561037c565b60019150505b92915050565b60003361027c8582856104a0565b61028785858561051a565b506001949350505050565b6000336102628185856102a58383610351565b6102af919061081d565b61037c565b6060600480546101d1906107e3565b600033816102d18286610351565b9050838110156103365760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b60648201526084015b60405180910390fd5b610287828686840361037c565b60003361026281858561051a565b6001600160a01b03918216600090815260016020908152604080832093909416825291909152205490565b6001600160a01b0383166103de5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b606482015260840161032d565b6001600160a01b03821661043f5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b606482015260840161032d565b6001600160a01b0383811660008181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b60006104ac8484610351565b9050600019811461051457818110156105075760405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e6365000000604482015260640161032d565b610514848484840361037c565b50505050565b6001600160a01b03831661057e5760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b606482015260840161032d565b6001600160a01b0382166105e05760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b606482015260840161032d565b6001600160a01b038316600090815260208190526040902054818110156106585760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b606482015260840161032d565b6001600160a01b03848116600081815260208181526040808320878703905593871680835291849020805487019055925185815290927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a3610514565b600060208083528351808285015260005b818110156106eb578581018301518582016040015282016106cf565b506000604082860101526040601f19601f8301168501019250505092915050565b80356001600160a01b038116811461072357600080fd5b919050565b6000806040838503121561073b57600080fd5b6107448361070c565b946020939093013593505050565b60008060006060848603121561076757600080fd5b6107708461070c565b925061077e6020850161070c565b9150604084013590509250925092565b6000602082840312156107a057600080fd5b6107a98261070c565b9392505050565b600080604083850312156107c357600080fd5b6107cc8361070c565b91506107da6020840161070c565b90509250929050565b600181811c908216806107f757607f821691505b60208210810361081757634e487b7160e01b600052602260045260246000fd5b50919050565b8082018082111561026857634e487b7160e01b600052601160045260246000fdfea2646970667358221220257f3d763bae7b8c0189ed676531d85a1046e0bea68722f67c2616d46f01c02964736f6c63430008100033"; + const abi = ["constructor(uint8 decimals_, address mintTo)"]; + const tokenFactory = new ContractFactory(abi, erc20TokenBytecode, deployerWallet); + const token = await tokenFactory.deploy(decimals, deployerWallet.address); + await token.deployTransaction.wait(); + + return token.address; +} export const bridgeFundsCommand = { command: "bridge-funds", @@ -184,6 +237,56 @@ export const bridgeNativeTokenToL3Command = { }, }; +export const transferL3ChainOwnershipCommand = { + command: "transfer-l3-chain-ownership", + describe: "transfer L3 chain ownership to upgrade executor", + builder: { + creator: { + string: true, + describe: "address of the token bridge creator", + }, + wait: { + boolean: true, + describe: "wait till ownership is transferred", + default: false, + }, + }, + handler: async (argv: any) => { + // get inbox address from config file + const deploydata = JSON.parse( + fs + .readFileSync(path.join(consts.configpath, "l3deployment.json")) + .toString() + ); + const inboxAddr = ethers.utils.hexlify(deploydata.inbox); + + // get L3 upgrade executor address from token bridge creator + const l2provider = new ethers.providers.WebSocketProvider(argv.l2url); + const tokenBridgeCreator = new ethers.Contract(argv.creator, L1AtomicTokenBridgeCreator.abi, l2provider); + const [,,,,,,,l3UpgradeExecutorAddress,] = await tokenBridgeCreator.inboxToL2Deployment(inboxAddr); + + // set TX params + argv.provider = new ethers.providers.WebSocketProvider(argv.l3url); + argv.to = "address_" + ARB_OWNER; + argv.from = "l3owner"; + argv.ethamount = "0"; + + // add L3 UpgradeExecutor to chain owners + const arbOwnerIface = new ethers.utils.Interface([ + "function addChainOwner(address newOwner) external", + "function removeChainOwner(address ownerToRemove) external" + ]) + argv.data = arbOwnerIface.encodeFunctionData("addChainOwner", [l3UpgradeExecutorAddress]); + await runStress(argv, sendTransaction); + + // remove L3 owner from chain owners + argv.data = arbOwnerIface.encodeFunctionData("removeChainOwner", [namedAccount("l3owner").address]); + await runStress(argv, sendTransaction); + + argv.provider.destroy(); + } +}; + export const createERC20Command = { command: "create-erc20", describe: "creates simple ERC20 on L2", @@ -192,14 +295,15 @@ export const createERC20Command = { string: true, describe: "account (see general help)" }, - mintTo: { - string: true, - describe: "account (see general help)", - }, bridgeable: { boolean: true, describe: "if true, deploy on L1 and bridge to L2", }, + decimals: { + string: true, + describe: "number of decimals for token", + default: "18", + }, }, handler: async (argv: any) => { console.log("create-erc20"); @@ -220,20 +324,17 @@ export const createERC20Command = { l1provider ); - const tokenFactory = new ContractFactory( - ERC20PresetFixedSupplyArtifact.abi, - ERC20PresetFixedSupplyArtifact.bytecode, - deployerWallet - ); - const token = await tokenFactory.deploy("AppTestToken", "APP", ethers.utils.parseEther("1000000000"), deployerWallet.address); - await token.deployTransaction.wait(); + const tokenAddress = await deployERC20Contract(deployerWallet, argv.decimals); + const token = new ethers.Contract(tokenAddress, ERC20.abi, deployerWallet); console.log("Contract deployed at L1 address:", token.address); - await (await token.functions.transfer(namedAccount(argv.mintTo).address, ethers.utils.parseEther("100000000"))).wait(); const l1GatewayRouter = new ethers.Contract(l1l2tokenbridge.l2Network.tokenBridge.l1GatewayRouter, L1GatewayRouter.abi, deployerWallet); await (await token.functions.approve(l1l2tokenbridge.l2Network.tokenBridge.l1ERC20Gateway, ethers.constants.MaxUint256)).wait(); + const supply = await token.totalSupply(); + // transfer 90% of supply to l2 + const transferAmount = supply.mul(9).div(10); await (await l1GatewayRouter.functions.outboundTransfer( - token.address, namedAccount(argv.mintTo).address, ethers.utils.parseEther("100000000"), 100000000, 1000000000, "0x000000000000000000000000000000000000000000000000000fffffffffff0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000", { + token.address, deployerWallet.address, transferAmount, 100000000, 1000000000, "0x000000000000000000000000000000000000000000000000000fffffffffff0000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000", { value: ethers.utils.parseEther("1"), } )).wait(); @@ -264,16 +365,8 @@ export const createERC20Command = { ethers.utils.sha256(ethers.utils.toUtf8Bytes(argv.deployer)), argv.provider ); - - const contractFactory = new ContractFactory( - ERC20PresetFixedSupplyArtifact.abi, - ERC20PresetFixedSupplyArtifact.bytecode, - deployerWallet - ); - const contract = await contractFactory.deploy("AppTestToken", "APP", ethers.utils.parseEther("1000000000"), namedAccount(argv.mintTo).address); - await contract.deployTransaction.wait(); - - console.log("Contract deployed at address:", contract.address); + const tokenAddress = await deployERC20Contract(deployerWallet, argv.decimals); + console.log("Contract deployed at address:", tokenAddress); argv.provider.destroy(); }, @@ -306,8 +399,9 @@ export const transferERC20Command = { argv.provider = new ethers.providers.WebSocketProvider(argv.l2url); const account = namedAccount(argv.from).connect(argv.provider); const tokenContract = new ethers.Contract(argv.token, ERC20.abi, account); - const decimals = await tokenContract.decimals(); - await(await tokenContract.transfer(namedAccount(argv.to).address, ethers.utils.parseUnits(argv.amount, decimals))).wait(); + const tokenDecimals = await tokenContract.decimals(); + const amountToTransfer = BigNumber.from(argv.amount).mul(BigNumber.from('10').pow(tokenDecimals)); + await(await tokenContract.transfer(namedAccount(argv.to).address, amountToTransfer)).wait(); argv.provider.destroy(); }, }; @@ -431,3 +525,22 @@ export const sendRPCCommand = { await rpcProvider.send(argv.method, argv.params) } } + +export const waitForSyncCommand = { + command: "wait-for-sync", + describe: "wait for rpc to sync", + builder: { + url: { string: true, describe: "url to send rpc call", default: "http://sequencer:8547"}, + }, + handler: async (argv: any) => { + const rpcProvider = new ethers.providers.JsonRpcProvider(argv.url) + let syncStatus; + do { + syncStatus = await rpcProvider.send("eth_syncing", []) + if (syncStatus !== false) { + // Wait for a short interval before checking again + await new Promise(resolve => setTimeout(resolve, 5000)) + } + } while (syncStatus !== false) + }, +}; diff --git a/scripts/index.ts b/scripts/index.ts index 2fd189f6..69cfe156 100644 --- a/scripts/index.ts +++ b/scripts/index.ts @@ -19,6 +19,8 @@ import { sendL2Command, sendL3Command, sendRPCCommand, + waitForSyncCommand, + transferL3ChainOwnershipCommand, } from "./ethcommands"; async function main() { @@ -41,6 +43,7 @@ async function main() { .command(sendL2Command) .command(sendL3Command) .command(sendRPCCommand) + .command(transferL3ChainOwnershipCommand) .command(writeConfigCommand) .command(writeGethGenesisCommand) .command(writeL2ChainConfigCommand) @@ -51,6 +54,7 @@ async function main() { .command(printPrivateKeyCommand) .command(redisReadCommand) .command(redisInitCommand) + .command(waitForSyncCommand) .strict() .demandCommand(1, "a command must be specified") .epilogue(namedAccountHelpString) diff --git a/test-node.bash b/test-node.bash index 0e4b0e4c..12062b5a 100755 --- a/test-node.bash +++ b/test-node.bash @@ -2,10 +2,11 @@ set -eu -NITRO_NODE_VERSION=offchainlabs/nitro-node:v3.2.1-d81324d +NITRO_NODE_VERSION=offchainlabs/nitro-node:v3.2.1-d81324d-dev BLOCKSCOUT_VERSION=offchainlabs/blockscout:v1.1.0-0e716c8 -DEFAULT_NITRO_CONTRACTS_VERSION="v2.0.0" +# This commit matches v2.1.0 release of nitro-contracts, with additional support to set arb owner through upgrade executor +DEFAULT_NITRO_CONTRACTS_VERSION="99c07a7db2fcce75b751c5a2bd4936e898cda065" DEFAULT_TOKEN_BRIDGE_VERSION="v1.2.2" # Set default versions if not overriden by provided env vars @@ -44,6 +45,7 @@ consensusclient=false redundantsequencers=0 l3_custom_fee_token=false l3_token_bridge=false +l3_custom_fee_token_decimals=18 batchposters=1 devprivkey=b6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659 l1chainid=1337 @@ -184,7 +186,7 @@ while [[ $# -gt 0 ]]; do ;; --pos) consensusclient=true - l1chainid=32382 + l1chainid=1337 shift ;; --l3node) @@ -199,6 +201,19 @@ while [[ $# -gt 0 ]]; do l3_custom_fee_token=true shift ;; + --l3-fee-token-decimals) + if ! $l3_custom_fee_token; then + echo "Error: --l3-fee-token-decimals requires --l3-fee-token to be provided." + exit 1 + fi + l3_custom_fee_token_decimals=$2 + if [[ $l3_custom_fee_token_decimals -lt 0 || $l3_custom_fee_token_decimals -gt 36 ]]; then + echo "l3-fee-token-decimals must be in range [0,36], value: $l3_custom_fee_token_decimals." + exit 1 + fi + shift + shift + ;; --l3-token-bridge) if ! $l3node; then echo "Error: --l3-token-bridge requires --l3node to be provided." @@ -238,6 +253,7 @@ while [[ $# -gt 0 ]]; do echo --validate heavy computation, validating all blocks in WASM echo --l3node deploys an L3 node on top of the L2 echo --l3-fee-token L3 chain is set up to use custom fee token. Only valid if also '--l3node' is provided + echo --l3-fee-token-decimals Number of decimals to use for custom fee token. Only valid if also '--l3-fee-token' is provided echo --l3-token-bridge Deploy L2-L3 token bridge. Only valid if also '--l3node' is provided echo --batchposters batch posters [0-3] echo --redundantsequencers redundant sequencers [0-3] @@ -372,29 +388,32 @@ if $force_init; then docker compose run --entrypoint sh geth -c "chown -R 1000:1000 /keystore" docker compose run --entrypoint sh geth -c "chown -R 1000:1000 /config" - if $consensusclient; then - echo == Writing configs - docker compose run scripts write-geth-genesis-config + echo == Writing geth configs + docker compose run scripts write-geth-genesis-config - echo == Writing configs + if $consensusclient; then + echo == Writing prysm configs docker compose run scripts write-prysm-config - echo == Initializing go-ethereum genesis configuration - docker compose run geth init --datadir /datadir/ /config/geth_genesis.json - - echo == Starting geth - docker compose up --wait geth - echo == Creating prysm genesis - docker compose up create_beacon_chain_genesis + docker compose run create_beacon_chain_genesis + fi + echo == Initializing go-ethereum genesis configuration + docker compose run geth init --state.scheme hash --datadir /datadir/ /config/geth_genesis.json + + if $consensusclient; then echo == Running prysm docker compose up --wait prysm_beacon_chain docker compose up --wait prysm_validator - else - docker compose up --wait geth fi + echo == Starting geth + docker compose up --wait geth + + echo == Waiting for geth to sync + docker compose run scripts wait-for-sync --url http://geth:8545 + echo == Funding validator, sequencer and l2owner docker compose run scripts send-l1 --ethamount 1000 --to validator --wait docker compose run scripts send-l1 --ethamount 1000 --to sequencer --wait @@ -472,8 +491,9 @@ if $force_init; then EXTRA_L3_DEPLOY_FLAG="" if $l3_custom_fee_token; then echo == Deploying custom fee token - nativeTokenAddress=`docker compose run scripts create-erc20 --deployer user_fee_token_deployer --mintTo user_token_bridge_deployer --bridgeable $tokenbridge | tail -n 1 | awk '{ print $NF }'` - docker compose run scripts transfer-erc20 --token $nativeTokenAddress --amount 100 --from user_token_bridge_deployer --to l3owner + nativeTokenAddress=`docker compose run scripts create-erc20 --deployer user_fee_token_deployer --bridgeable $tokenbridge --decimals $l3_custom_fee_token_decimals | tail -n 1 | awk '{ print $NF }'` + docker compose run scripts transfer-erc20 --token $nativeTokenAddress --amount 10000 --from user_fee_token_deployer --to l3owner + docker compose run scripts transfer-erc20 --token $nativeTokenAddress --amount 10000 --from user_fee_token_deployer --to user_token_bridge_deployer EXTRA_L3_DEPLOY_FLAG="-e FEE_TOKEN_ADDRESS=$nativeTokenAddress" fi @@ -499,18 +519,22 @@ if $force_init; then fi docker compose run -e PARENT_WETH_OVERRIDE=$l2Weth -e ROLLUP_OWNER_KEY=$l3ownerkey -e ROLLUP_ADDRESS=$rollupAddress -e PARENT_RPC=http://sequencer:8547 -e PARENT_KEY=$deployer_key -e CHILD_RPC=http://l3node:3347 -e CHILD_KEY=$deployer_key tokenbridge deploy:local:token-bridge docker compose run --entrypoint sh tokenbridge -c "cat network.json && cp network.json l2l3_network.json" + + # set L3 UpgradeExecutor, deployed by token bridge creator in previous step, to be the L3 chain owner. L3owner (EOA) and alias of L2 UpgradeExectuor have the executor role on the L3 UpgradeExecutor + echo == Set L3 UpgradeExecutor to be chain owner + tokenBridgeCreator=`docker compose run --entrypoint sh tokenbridge -c "cat l2l3_network.json" | jq -r '.l1TokenBridgeCreator'` + docker compose run scripts transfer-l3-chain-ownership --creator $tokenBridgeCreator echo fi echo == Fund L3 accounts if $l3_custom_fee_token; then - docker compose run scripts bridge-native-token-to-l3 --amount 50000 --from user_token_bridge_deployer --wait - docker compose run scripts send-l3 --ethamount 500 --from user_token_bridge_deployer --wait - docker compose run scripts send-l3 --ethamount 500 --from user_token_bridge_deployer --to "key_0x$devprivkey" --wait + docker compose run scripts bridge-native-token-to-l3 --amount 5000 --from user_fee_token_deployer --wait + docker compose run scripts send-l3 --ethamount 100 --from user_fee_token_deployer --wait else docker compose run scripts bridge-to-l3 --ethamount 50000 --wait fi - docker compose run scripts send-l3 --ethamount 100 --to l3owner --wait + docker compose run scripts send-l3 --ethamount 10 --to l3owner --wait echo == Deploy CacheManager on L3 docker compose run -e CHILD_CHAIN_RPC="http://l3node:3347" -e CHAIN_OWNER_PRIVKEY=$l3ownerkey rollupcreator deploy-cachemanager-testnode diff --git a/tokenbridge/Dockerfile b/tokenbridge/Dockerfile index 3d8cbacb..dac06fbb 100644 --- a/tokenbridge/Dockerfile +++ b/tokenbridge/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16-bullseye-slim +FROM node:18-bullseye-slim ARG TOKEN_BRIDGE_BRANCH=main RUN apt-get update && \ apt-get install -y git docker.io python3 build-essential