OP Stack L2 Chain
Sunrise’s Data Availability Layer supports Layer 2 blockchains created using OP Stack This is a guide to connecting an L2 chain created using OP Stack to Sunrise chain with Sunrise Data. Data Availability layer is supported in Sunrise v0.3.0 and later.
This version of the OP Stack requires the L1 EVM chain for operation. Use some kind of testnet or local chain.
How to set up OP Stack
Section titled “How to set up OP Stack”As an example, here is how to use OP Stack to create an L2 chain and run it on the Sunrise’s Data Availability Layer.
This guide uses the Ethereum Sepolia testnet to meet the OP Stack requirements, but a local EVM chain will also work.
sequenceDiagram autonumber L2 ->> Ethereum Sepolia: Send Tx (e.g. token transfer) Ethereum Sepolia --> L2: API & Tx Response L2 ->> Sunrise: Send Block Data and Save
Dependencies
Section titled “Dependencies”Dependencies and general installation instructions for Ubuntu 22.04.
-
node
Terminal window curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs -
Terminal window curl -fsSL https://get.pnpm.io/install.sh | sh - -
Terminal window curl -L https://foundry.paradigm.xyz | bash -
just
Terminal window wget -qO - 'https://proget.makedeb.org/debian-feeds/prebuilt-mpr.pub' | gpg --dearmor | sudo tee /usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg 1> /dev/nullecho "deb [arch=all,$(dpkg --print-architecture) signed-by=/usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg] https://proget.makedeb.org prebuilt-mpr $(lsb_release -cs)" | sudo tee /etc/apt/sources.list.d/prebuilt-mpr.listsudo apt updatesudo apt install just
Set up Optimism Rollup Testnet
Section titled “Set up Optimism Rollup Testnet”Optimism
Section titled “Optimism”-
Clone the optimism repo
Terminal window git clone https://github.com/ethereum-optimism/optimism.git -
Check out the correct branch
Terminal window cd optimismgit checkout v1.9.1
We have confirmed the operation with the latest version at the time of document update. If you use other versions, please check the differences.
-
Run the following to check you have all dependencies
Terminal window ./packages/contracts-bedrock/scripts/getting-started/versions.sh -
Build all packages associated with Optimism
Terminal window make op-node op-batcher op-proposerIf you are having issues with this step, make sure your versions match those in the optimism docs. Specifically, you may have to downgrade your go version.
-
Clone and build op-geth
Terminal window cd ~git clone https://github.com/ethereum-optimism/op-geth.gitcd op-gethmake geth
For more information on supported `op-geth, please check the Production Releases in the optimism repository.
-
Fill out environment variables
Terminal window cd ~/optimismcp .envrc.example .envrcRun the script to generate addresses with the following command in the optimism repo:
./packages/contracts-bedrock/scripts/getting-started/wallets.shThe output will look like the following which will you need to paste into the environment file as well:
Terminal window ################################################### Getting Started #################################################### Admin accountexport GS_ADMIN_ADDRESS=0x82eeB61600f290ce3F9400d345aAEcBe5faF7AEBexport GS_ADMIN_PRIVATE_KEY=0x7c726817d047ee62cbb060312fe2620ba5462495e34f7e8279ba22faa96bca20# Batcher accountexport GS_BATCHER_ADDRESS=0x7BECbC4C747922d92e4F917951D9D8c3Ada7eb60export GS_BATCHER_PRIVATE_KEY=0xc7dfaa7b8449f00480196377da50d29318b2397fd0296d0ab4f11d48ee3cf723# Proposer accountexport GS_PROPOSER_ADDRESS=0x773F4527fECc889d6DD3Cd7d044F4AC1Ad765a31export GS_PROPOSER_PRIVATE_KEY=0xed6029a5928e83c5d2a28d9574304bae9a825e19f7f18a50d34edc13b505afed# Sequencer accountexport GS_SEQUENCER_ADDRESS=0x2B43c41FCbabc5437A6E1B97F47cA085a4B16f61export GS_SEQUENCER_PRIVATE_KEY=0x0a7d4ce467fe4d00b8930215c98335e06c16db34cd501c8c3f3173015487662e################################################### Chain Information #################################################### L1 chain informationexport L1_CHAIN_ID=11155111export L1_BLOCK_TIME=12# L2 chain informationexport L2_CHAIN_ID=42069export L2_BLOCK_TIME=2################################################### op-node Configuration #################################################### The kind of RPC provider, used to inform optimal transactions receipts# fetching. Valid options: alchemy, quicknode, infura, parity, nethermind,# debug_geth, erigon, basic, any.export L1_RPC_KIND=infura################################################### Contract Deployment #################################################### RPC URL for the L1 network to interact withexport L1_RPC_URL=https://sepolia.infura.io/v3/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxAPI key for RPC URL can be found in Infura or other providers.
-
Fund the addresses with enough Sepolia ETH, the optimism docs recommend the following:
- Admin — 0.5 Sepolia ETH
- Proposer — 0.2 Sepolia ETH
- Batcher — 0.1 Sepolia ETH
Ref: Sepolia PoW Faucet
-
Load environment variables with direnv
direnv allowYou should see something similar to this after:Terminal window direnv: loading ~/optimism/.envrc direnv: export +DEPLOYMENT_CONTEXT +ETHERSCAN_API_KEY +GS_ADMIN_ADDRESS +GS_ADMIN_PRIVATE_KEY +GS_BATCHER_ADDRESS +GS_BATCHER_PRIVATE_KEY +GS_PROPOSER_ADDRESS +GS_PROPOSER_PRIVATE_KEY +GS_SEQUENCER_ADDRESS +GS_SEQUENCER_PRIVATE_KEY +IMPL_SALT +L1_RPC_KIND +L1_RPC_URL +PRIVATE_KEY +TENDERLY_PROJECT +TENDERLY_USERNAMEIf you do not see any output, try
nano ~/.zshrcnano ~/.bashrcAdd the following line depending on whether you use bash or zsh
Terminal window eval "$(direnv hook zsh)"Terminal window eval "$(direnv hook bash)"Save the changes with
source ~/.zshrcsource ~/.bashrc -
Configure the network
Terminal window cd ~/optimism/packages/contracts-bedrock./scripts/getting-started/config.shYou can view the config in the
deploy-config/getting-started.jsonfile Add the following at the bottom of the config generatedTerminal window nano deploy-config/getting-started.json..."preimageOracleMinProposalSize": 1800000,"preimageOracleChallengePeriod": 300,"useAltDA": true,"daCommitmentType": "GenericCommitment","daChallengeWindow": 160,"daResolveWindow": 160,"daBondSize": 1000000,"daResolverRefundPercentage": 0} -
Deploy the L1 contracts
Terminal window just installDEPLOYMENT_OUTFILE=deployments/artifact.json \DEPLOY_CONFIG_PATH=deploy-config/getting-started.json \forge script scripts/deploy/Deploy.s.sol:Deploy \--broadcast --private-key $GS_ADMIN_PRIVATE_KEY \--rpc-url $L1_RPC_URL --slowL2 Allocs
Terminal window CONTRACT_ADDRESSES_PATH=deployments/artifact.json \DEPLOY_CONFIG_PATH=deploy-config/getting-started.json \STATE_DUMP_PATH=deploy-config/statedump.json \forge script scripts/L2Genesis.s.sol:L2Genesis \--sig 'runWithStateDump()' \--chain 42069Use your L2 chain id in
--chain.If you see a nondescript error that includes
EvmError: RevertandScript failedthen you likely need to change theIMPL_SALTenvironment variable. This variable determines the addresses of various smart contracts that are deployed via CREATE2(opens in a new tab). If the sameIMPL_SALTis used to deploy the same contracts twice, the second deployment will fail. You can generate a newIMPL_SALTby runningdirenv allowanywhere in the Optimism Monorepo. -
Generate the L2 config files
Terminal window cd ~/optimism/op-node./bin/op-node genesis l2 \--deploy-config ../packages/contracts-bedrock/deploy-config/getting-started.json \--l1-deployments ../packages/contracts-bedrock/deployments/artifact.json \--outfile.l2 genesis.json \--outfile.rollup rollup.json \--l1-rpc $L1_RPC_URL \--l2-allocs ../packages/contracts-bedrock/deploy-config/statedump.jsonCheck the end of the generated
rollup.json"alt_da": {"da_challenge_contract_address": "0x0000000000000000000000000000000000000000","da_commitment_type": "GenericCommitment","da_challenge_window": 160,"da_resolve_window": 160} -
Create an authentication key
Terminal window openssl rand -hex 32 > jwt.txt -
Copy genesis files into op-geth directory
Terminal window cp genesis.json ~/op-gethcp jwt.txt ~/op-geth -
Initialize
op-gethTerminal window cd ~/op-gethmkdir datadirmake gethbuild/bin/geth init --datadir=datadir genesis.json
Start L2
Section titled “Start L2”Before optimism start, set up sunrised & sunrise-data, etc.
-
Start
op-gethTerminal window ./build/bin/geth \--datadir ./datadir \--http \--http.corsdomain="*" \--http.vhosts="*" \--http.addr=0.0.0.0 \--http.port=9545 \--http.api=web3,debug,eth,txpool,net,engine \--ws \--ws.addr=0.0.0.0 \--ws.port=9546 \--ws.origins="*" \--ws.api=debug,eth,txpool,net,engine \--syncmode=full \--nodiscover \--maxpeers=0 \--networkid=42069 \--authrpc.vhosts="*" \--authrpc.addr=0.0.0.0 \--authrpc.port=9551 \--authrpc.jwtsecret=./jwt.txt \--rollup.disabletxpoolgossip=true -
Start
op-nodeTerminal window cd ~/optimism/op-node./bin/op-node \--l2=http://localhost:9551 \--l2.jwt-secret=./jwt.txt \--sequencer.enabled \--sequencer.l1-confs=5 \--verifier.l1-confs=4 \--rollup.config=./rollup.json \--rpc.addr=0.0.0.0 \--rpc.port=8547 \--p2p.disable \--rpc.enable-admin \--p2p.sequencer.key=$GS_SEQUENCER_PRIVATE_KEY \--l1=$L1_RPC_URL \--l1.rpckind=$L1_RPC_KIND \--altda.enabled=true \--altda.da-server=http://localhost:3100 \--altda.da-service=true \--l1.beacon.ignore=true—altda.da-server is your da-serer’s http URL
-
Start
op-batcherTerminal window cd ~/optimism/op-batcher./bin/op-batcher \--l2-eth-rpc=http://localhost:9545 \--rollup-rpc=http://localhost:8547 \--poll-interval=1s \--sub-safety-margin=6 \--num-confirmations=1 \--safe-abort-nonce-too-low-count=3 \--resubmission-timeout=30s \--rpc.addr=0.0.0.0 \--rpc.port=8548 \--rpc.enable-admin \--max-channel-duration=1 \--l1-eth-rpc=$L1_RPC_URL \--private-key=$GS_BATCHER_PRIVATE_KEY \--altda.enabled=true \--altda.da-service=true \--altda.da-server=http://localhost:3100 -
Start
op-proposerTerminal window cd ~/optimism/op-proposer./bin/op-proposer \--poll-interval=12s \--rpc.port=9560 \--rollup-rpc=http://localhost:8547 \--l2oo-address=$(cat ../packages/contracts-bedrock/deployments/42069-deploy.json | jq -r .L2OutputOracleProxy) \--private-key=$GS_PROPOSER_PRIVATE_KEY \--l1-eth-rpc=$L1_RPC_URL -
Work