Skip to content

Commit

Permalink
L2 genesis generation w/ predeploy (#240)
Browse files Browse the repository at this point in the history
Co-authored-by: Ujval Misra <[email protected]>
  • Loading branch information
LEAFERx and ujvl authored Nov 20, 2023
1 parent 77901ef commit afe93c7
Show file tree
Hide file tree
Showing 80 changed files with 7,504 additions and 2,869 deletions.
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: install sidecar clean geth-docker contracts
.PHONY: install sidecar clean geth-docker contracts ops

SIDECAR_DIR = services/sidecar
SIDECAR_BIN_SRC = ./cmd/sidecar
Expand All @@ -16,12 +16,15 @@ GETH_BIN_TARGET = ./build/bin/geth
MAGI_DIR = services/cl_clients/magi
MAGI_BIN_TARGET = services/cl_clients/magi/target/debug/magi

OPS_DIR = ops
OPS_BINDINGS_DIR = $(OPS_DIR)/bindings

# TODO add clef back in when moving to services/el_clients/go-ethereum
#CLEF_SRC = $(SIDECAR_DIR)/cmd/clef/
#CLEF_TARGET = $(SIDECAR_BIN)/clef
# install: sidecar $(GETH_TARGET) $(CLEF_TARGET)

install: geth magi sidecar
install: geth magi sidecar ops
geth: $(GETH_BIN_TARGET)
magi: $(MAGI_BIN_TARGET)
sidecar: bindings $(shell find $(SIDECAR_DIR) -type f -name "*.go")
Expand All @@ -33,6 +36,11 @@ bindings: $(CONTRACTS_TARGET)
cd $(SIDECAR_DIR) && go generate ./...
touch $(SIDECAR_BINDINGS_TARGET)

ops: ops-bindings

ops-bindings: $(CONTRACTS_TARGET)
GOFLAGS="-buildvcs=false" make -C $(OPS_BINDINGS_DIR)

contracts: $(CONTRACTS_TARGET) # for back-compat

# Removes:
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ See <a href="./docs/system.md">system.md</a> for a system overview and <a href="
### Build from source

Install the following dependencies:
- [`Rust`](https://www.rust-lang.org/)
- [`Golang`](https://go.dev/)
- [`Node.js v16`](https://nodejs.org/en/)
- [`pnpm`](https://pnpm.io/installation#using-corepack)
- [`foundry`](https://book.getfoundry.sh/getting-started/installation)
Expand All @@ -27,20 +29,19 @@ pnpm install && make
```
Note: the commands that follow below assume you are in the project root directory.

### Running a devnet with Docker
### Quick-start with Docker

The simplest way to run a local devent is using the provided docker-compose.
The simplest way to run a local L2 devent is to use the provided docker-compose.
```sh
mkdir workspace
cp -a config/local_docker/. workspace/ # copy all config files

docker compose -f docker/docker-compose-test.yml build
docker compose -f docker/docker-compose-test.yml up
```

### Running a local devnet

This section will walk you through how to set up a local devnet containing an L2 sequencer running over a local L1 network.
This section will walk you through how to set up a local L2 devnet (containing an L2 sequencer and validator), running over a local L1 network.

**Configure network**

Expand All @@ -51,13 +52,15 @@ cp -a config/local_devnet/. workspace/ # copy all config files
```

**Start L1**

Run the below script to initialize a new local L1 chain.
```sh
cd workspace
../sbin/start_l1.sh -d # Terminal 1
../sbin/start_l1.sh -c -d # Terminal 1
```

**Start an L2 node**

Deploy the L1 contracts on the newly started chain, and spin up all services required to run an L2 node.
```sh
../sbin/start_sp_geth.sh # Terminal 2
Expand All @@ -68,7 +71,7 @@ Deploy the L1 contracts on the newly started chain, and spin up all services req
At this point, you'll have two chains started with the following parameters
- L2: chain ID `13527`, with a sequencer exposed on ports `4011` (http) and `4012` (ws).
- L1: chain ID `31337`, on port `8545` (ws).
To re-run the network from clean state, run `../sbin/deploy_l1_contracts.sh -c && ../sbin/start_sp_geth.sh -c`.
To re-run the network from clean state, make sure to use the `-c` flag: `../sbin/deploy_l1_contracts.sh -c && ../sbin/start_sp_geth.sh -c`.

## For users
To learn more, see [`specular.network`](https://specular.network/).
34 changes: 20 additions & 14 deletions config/example/.genesis.env
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
# This dotenv contains the env variables for:
# 1. generating a new genesis from a base via `sbin/create_genesis.sh`.
# 2. contract deployment, e.g. via `sbin/start_l1.sh`.
# 1. genesis generation: via `sbin/create_genesis.sh`.
# 2. contract deployment: via `sbin/start_l1.sh` and/or `sbin/deploy_l1_contracts.sh`.
# This file is optional; it is only necessary for new deployments
# (i.e. where the genesis isn't already generated and the
# contracts must be deployed).
# (i.e. where the genesis isn't already generated and the contracts must be deployed).

# Path to the base (source) genesis. Optional.
# Required only if you want to run `sbin/create_genesis.sh`.
BASE_GENESIS_PATH=./base_genesis.json
# Path to the genesis config.
# Required for genesis generation.
# This config is used to generate the genesis JSON at the configured $GENESIS_PATH.
GENESIS_CFG_PATH=./genesis_config.json
# Path to the actual (target) genesis.
# Required for genesis generation and contract deployment.
# Does not need to exist at configuration-time.
GENESIS_PATH=./genesis.json
# Path to the base rollup config. Optional.
# Required only if you want to run `sbin/create_genesis.sh`.
# Path to the base rollup config.
# Required for genesis generation.
BASE_ROLLUP_CFG_PATH=./base_sp_rollup.json
# Path to the actual (target) rollup config.
# Does not need to exist at configuration-time.
# File does not need to exist at configuration-time (it will be generated).
# Required for genesis generation and contract deployment.
# Note: file name must start with "sp_" to support Magi.
ROLLUP_CFG_PATH=./sp_rollup.json
# Path to the exported genesis hash file
# File does not need to exist at configuration-time (it will be generated).
# Required for genesis generation.
GENESIS_EXPORTED_HASH_PATH=./genesis_hash.json
# L1 network parameters.
# What network to deploy to (using hardhat). Optional.
# Required only by `sbin/deploy_l1_contracts.sh`.
# What network to deploy to (using hardhat).
# Required for contract deployment.
L1_NETWORK=localhost
# What software stack to use to run the L1 network. Optional.
# Required only by `sbin/start_l1.sh`. Options: [geth|hardhat]
# Required for contract deployment. Options: [geth|hardhat]
L1_STACK=geth
# L1 endpoint.
# Required only by `sbin/start_l1.sh` and `sbin/create_genesis.sh`
# Required for contract deployment.
# Note: if L1_STACK=hardhat, use host 127.0.0.1 (local) or 0.0.0.0 (docker)
L1_ENDPOINT=ws://172.17.0.1:8545
10 changes: 6 additions & 4 deletions config/example/.sidecar.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
ROLLUP_CFG_PATH=sp_rollup.json
# Rollup contract address (address on L1)
ROLLUP_ADDR=0x0000000000000000000000000000000000000000
# L1 oracle contract address (address on L2)
L1_ORACLE_ADDR=0x0000000000000000000000000000000000000000
# L1 RPC URL
L1_ENDPOINT=http://172.17.0.1:8545
# L2 RPC URL
Expand All @@ -17,10 +15,14 @@ CLEF_ENDPOINT=
# disseminator configuration
# The following parameters are only required if DISSEMINATOR=true
DISSEMINATOR=true
DISSEMINATOR_PRIVATE_KEY=
# Path to file containing disseminator private key (in plain).
# Note: this can be the same as the sequencer (as in the example here),
# or a different key altogether, depending on how the protocol has been configured.
DISSEMINATOR_PK_PATH=sequencer_pk.txt
DISSEMINATOR_SUB_SAFETY_MARGIN=8
DISSEMINATOR_TARGET_BATCH_SIZE=1024
# validator configuration
# The following parameters are only required if VALIDATOR=true
VALIDATOR=true
VALIDATOR_PRIVATE_KEY=
# Path to file containing validator private key (in plain).
VALIDATOR_PRIVATE_KEY=validator_pk.txt
1 change: 1 addition & 0 deletions config/example/.sp_magi.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ DEVNET=true
# Local sequencer flags. If SEQUENCER is true, SEQUENCER_MAX_SAFE_LAG is required.
SEQUENCER=true
SEQUENCER_MAX_SAFE_LAG=0
SEQUENCER_PK_FILE=./sequencer_pk.txt
24 changes: 24 additions & 0 deletions config/example/base_sp_rollup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"genesis": {
"l1": {
"hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"number": 0
},
"l2": {
"hash": "0x85d973858306241634c3a5ecbe114a0754be9d25da523cdd7e1968a09e419a32",
"number": 0
},
"system_config": {
"batcherAddr": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"overhead": "0x0000000000000000000000000000000000000000000000000000000000000000",
"scalar": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": 30000000
}
},
"block_time": 2,
"max_sequencer_drift": 600,
"seq_window_size": 3600,
"l1_chain_id": 31337,
"l2_chain_id": 13527,
"batch_inbox_address": "0x2E983A1Ba5e8b38AAAeC4B440B9dDcFBf72E15d1"
}
24 changes: 24 additions & 0 deletions config/example/genesis_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"l2ChainID": 13527,
"l2GenesisBlockNonce": "0x0",
"l2GenesisBlockGasLimit": "0x0",
"l2GenesisBlockDifficulty": "0x0",
"l2GenesisBlockNumber": "0x0",
"l2GenesisBlockGasUsed": "0x0",
"l2GenesisBlockBaseFeePerGas": "0x0",
"l2GenesisBlockExtraData": "0x",
"l2PredeployOwner": "0x000000000000000000000000000000000000dEaD",
"l1PortalAddress": "0x000000000000000000000000000000000000dEaD",
"l1StandardBridgeAddress": "0x000000000000000000000000000000000000dEaD",
"alloc": {
"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266": {
"balance": "10000000000000000000"
},
"0x70997970c51812dc3a010c7d01b50e0d17dc79c8": {
"balance": "10000000000000000000"
},
"0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc": {
"balance": "10000000000000000000"
}
}
}
1 change: 1 addition & 0 deletions config/example/sequencer_pk.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
1 change: 1 addition & 0 deletions config/example/validator_pk.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
3 changes: 2 additions & 1 deletion config/local_devnet/.genesis.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
BASE_GENESIS_PATH=./base_genesis.json
GENESIS_CFG_PATH=./genesis_config.json
GENESIS_PATH=./genesis.json
BASE_ROLLUP_CFG_PATH=./base_sp_rollup.json
ROLLUP_CFG_PATH=./sp_rollup.json
GENESIS_EXPORTED_HASH_PATH=./genesis_hash.json

L1_NETWORK=localhost
L1_STACK=geth
Expand Down
5 changes: 2 additions & 3 deletions config/local_devnet/.sidecar.env
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
ROLLUP_CFG_PATH=sp_rollup.json
ROLLUP_ADDR=0xF6168876932289D073567f347121A267095f3DD6
L1_ORACLE_ADDR=0x2E983A1Ba5e8b38AAAeC4B440B9dDcFBf72E15d1
L1_ENDPOINT=ws://127.0.0.1:8545
L2_ENDPOINT=ws://127.0.0.1:4012

DISSEMINATOR=true
DISSEMINATOR_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
DISSEMINATOR_PK_PATH=sequencer_pk.txt
DISSEMINATOR_SUB_SAFETY_MARGIN=8
DISSEMINATOR_TARGET_BATCH_SIZE=1024
VALIDATOR=true
VALIDATOR_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
VALIDATOR_PK_PATH=validator_pk.txt
1 change: 1 addition & 0 deletions config/local_devnet/.sp_magi.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ DEVNET=true
# Local sequencer flags
SEQUENCER=true
SEQUENCER_MAX_SAFE_LAG=0
SEQUENCER_PK_FILE=./sequencer_pk.txt
67 changes: 0 additions & 67 deletions config/local_devnet/base_genesis.json

This file was deleted.

24 changes: 24 additions & 0 deletions config/local_devnet/genesis_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"l2ChainID": 13527,
"l2GenesisBlockNonce": "0x0",
"l2GenesisBlockGasLimit": "0x0",
"l2GenesisBlockDifficulty": "0x0",
"l2GenesisBlockNumber": "0x0",
"l2GenesisBlockGasUsed": "0x0",
"l2GenesisBlockBaseFeePerGas": "0x0",
"l2GenesisBlockExtraData": "0x",
"l2PredeployOwner": "0x000000000000000000000000000000000000dEaD",
"l1PortalAddress": "0x000000000000000000000000000000000000dEaD",
"l1StandardBridgeAddress": "0x000000000000000000000000000000000000dEaD",
"alloc": {
"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266": {
"balance": "10000000000000000000"
},
"0x70997970c51812dc3a010c7d01b50e0d17dc79c8": {
"balance": "10000000000000000000"
},
"0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc": {
"balance": "10000000000000000000"
}
}
}
1 change: 1 addition & 0 deletions config/local_devnet/sequencer_pk.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
1 change: 1 addition & 0 deletions config/local_devnet/validator_pk.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
3 changes: 2 additions & 1 deletion config/local_docker/.genesis.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
BASE_GENESIS_PATH=./base_genesis.json
GENESIS_CFG_PATH=./genesis_config.json
GENESIS_PATH=./genesis.json
BASE_ROLLUP_CFG_PATH=./base_sp_rollup.json
ROLLUP_CFG_PATH=./sp_rollup.json
GENESIS_EXPORTED_HASH_PATH=./genesis_hash.json

L1_NETWORK=localhost
L1_ENDPOINT=ws://0.0.0.0:8545
Expand Down
4 changes: 2 additions & 2 deletions config/local_docker/.sidecar.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ L1_ENDPOINT=ws://l1-geth:8545
L2_ENDPOINT=http://sp-geth:4011

DISSEMINATOR=true
DISSEMINATOR_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
DISSEMINATOR_PK_PATH=sequencer_pk.txt
DISSEMINATOR_SUB_SAFETY_MARGIN=8
DISSEMINATOR_TARGET_BATCH_SIZE=1024
VALIDATOR=true
VALIDATOR_PRIVATE_KEY=0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
VALIDATOR_PRIVATE_KEY=validator_pk.txt
1 change: 1 addition & 0 deletions config/local_docker/.sp_magi.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ DEVNET=true
# Local sequencer flags
SEQUENCER=true
SEQUENCER_MAX_SAFE_LAG=0
SEQUENCER_PK_FILE=./sequencer_pk.txt
Loading

0 comments on commit afe93c7

Please sign in to comment.