Skip to content

refactor(l2): separated configs for prover_client and sequencer #2269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Mar 26, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci_l2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ jobs:
- name: Run L2 integration test
run: |
cd crates/l2
cp config_example.toml config.toml
cp configs/config_example.toml configs/config.toml
make ci_test
8 changes: 6 additions & 2 deletions cmd/ethrex/initializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ use tracing_subscriber::{filter::Directive, EnvFilter, FmtSubscriber};
#[cfg(feature = "l2")]
use crate::cli::L2Options;
#[cfg(feature = "l2")]
use ::{ethrex_common::Address, ethrex_l2::utils::config::read_env_file, secp256k1::SecretKey};
use ::{
ethrex_common::Address,
ethrex_l2::utils::config::{read_env_file_by_config, ConfigMode},
secp256k1::SecretKey,
};

#[cfg(feature = "based")]
use crate::cli::BasedOptions;
Expand Down Expand Up @@ -378,7 +382,7 @@ pub fn get_sponsor_pk(opts: &L2Options) -> SecretKey {

warn!("Sponsor private key not provided. Trying to read from the .env file.");

if let Err(e) = read_env_file() {
if let Err(e) = read_env_file_by_config(ConfigMode::Sequencer) {
panic!("Failed to read .env file: {e}");
}
let pk = std::env::var("L1_WATCHER_L2_PROPOSER_PRIVATE_KEY").unwrap_or_default();
Expand Down
8 changes: 6 additions & 2 deletions crates/l2/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.env
config.toml
.env*

# Ignore all config files that doesn't end with _example.toml
/configs
!*_example.toml

solc_out
32 changes: 26 additions & 6 deletions crates/l2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ ethrex_METRICS_OVERRIDES_L1_DOCKER_COMPOSE_PATH=$(ethrex_PATH)/crates/blockchain
ethrex_METRICS_OVERRIDES_L2_DOCKER_COMPOSE_PATH=$(ethrex_PATH)/crates/blockchain/metrics/docker-compose-metrics-l2.overrides.yaml
CI_ETHREX_WORKDIR := /usr/local/bin

ethrex_L2_CONFIGS_PATH=$(shell pwd)/configs
ethrex_L2_SEQUENCER_CONFIG_FILE=config.toml
ethrex_L2_PROVER_CLIENT_CONFIG_FILE=prover_client_config.toml
ethrex_L2_CONTRACTS_PATH=./contracts
L1_RPC_URL=http://localhost:8545
L1_PRIVATE_KEY=0x385c546456b6a603a1cfcaa9ec9494ba4832da08dd6bcf4de9a71e4a01b74924
Expand All @@ -68,6 +71,8 @@ L2_AUTH_PORT=8552
# Matches the ports used by the blockchain/metrics dir
L2_PROMETHEUS_METRICS_PORT = 3702

PROVER_ENV_FILE ?= ".env.prover"

# Local L1
init-local-l1: ## 🚀 Initializes an L1 Lambda ethrex Client with Docker (Used with make init)
docker compose -f ${ethrex_DEV_DOCKER_COMPOSE_PATH} -f ${ethrex_METRICS_OVERRIDES_L1_DOCKER_COMPOSE_PATH} up -d
Expand Down Expand Up @@ -111,14 +116,23 @@ clean-contract-deps: ## 🧹 Cleans the dependencies for the L1 contracts.
restart-contract-deps: clean-contract-deps ## 🔄 Restarts the dependencies for the L1 contracts.

deploy-l1: ## 📜 Deploys the L1 contracts
DEPLOYER_CONTRACTS_PATH=contracts CONFIG_FILE=config.toml cargo run --release --bin ethrex_l2_l1_deployer --manifest-path ${ethrex_L2_CONTRACTS_PATH}/Cargo.toml -- --deposit_rich
DEPLOYER_CONTRACTS_PATH=contracts \
CONFIGS_PATH=${ethrex_L2_CONFIGS_PATH} \
SEQUENCER_CONFIG_FILE=${ethrex_L2_SEQUENCER_CONFIG_FILE} \
cargo run --release --bin ethrex_l2_l1_deployer --manifest-path ${ethrex_L2_CONTRACTS_PATH}/Cargo.toml -- --deposit_rich

## Same as deploy-l1 but does not do deposits for rich accounts since that doesn't make sense for deployments to devnets/testnets i.e Sepolia
deploy-l1-testnet: ## 📜 Deploys the L1 contracts
DEPLOYER_CONTRACTS_PATH=contracts CONFIG_FILE=config.toml cargo run --release --bin ethrex_l2_l1_deployer --manifest-path ${ethrex_L2_CONTRACTS_PATH}/Cargo.toml
DEPLOYER_CONTRACTS_PATH=contracts \
CONFIGS_PATH=${ethrex_L2_CONFIGS_PATH} \
SEQUENCER_CONFIG_FILE=${ethrex_L2_SEQUENCER_CONFIG_FILE} \
cargo run --release --bin ethrex_l2_l1_deployer --manifest-path ${ethrex_L2_CONTRACTS_PATH}/Cargo.toml

update-system-contracts:
DEPLOYER_CONTRACTS_PATH=contracts CONFIG_FILE=config.toml cargo run --release --bin ethrex_l2_system_contracts_updater --manifest-path ${ethrex_L2_CONTRACTS_PATH}/Cargo.toml -- ${L2_GENESIS_FILE_PATH}
DEPLOYER_CONTRACTS_PATH=contracts \
CONFIGS_PATH=${ethrex_L2_CONFIGS_PATH} \
SEQUENCER_CONFIG_FILE=${ethrex_L2_SEQUENCER_CONFIG_FILE} \
cargo run --release --bin ethrex_l2_system_contracts_updater --manifest-path ${ethrex_L2_CONTRACTS_PATH}/Cargo.toml -- ${L2_GENESIS_FILE_PATH}

# L2
init-l2: init-metrics init-l2-no-metrics ## 🚀 Initializes an L2 Lambda ethrex Client with metrics
Expand Down Expand Up @@ -154,7 +168,7 @@ init-prover: ## 🚀 Initializes the Prover
@if [ -z "$$T" ]; then \
echo "Error: ProverType (T) is missing."; \
echo "Please provide it as an argument:"; \
echo "make init-prover T=<prover_type: (risc0, sp1)> <G=true>."; \
echo "make init-prover T=<prover_type: (risc0, sp1, pico, exec)> <G=true>."; \
echo "The prover can also be run with GPU (G)"; \
exit 1; \
fi; \
Expand All @@ -164,7 +178,13 @@ init-prover: ## 🚀 Initializes the Prover
else \
GPU=",gpu"; \
fi; \
cargo run --release --features "$$T$$GPU,l2" --manifest-path ./prover/Cargo.toml --bin ethrex_prover -- $$T

CONFIGS_PATH=${ethrex_L2_CONFIGS_PATH} \
PROVER_CLIENT_CONFIG_FILE=${ethrex_L2_PROVER_CLIENT_CONFIG_FILE} \
PROVER_ENV_FILE=${PROVER_ENV_FILE} \
cargo run --release --features "$$T$$GPU,l2" \
--manifest-path ./prover/Cargo.toml \
--bin ethrex_prover -- $$T

rm-db-l2: ## 🛑 Removes the DB used by the L2
cargo run --release --manifest-path ../../Cargo.toml --bin ethrex -- removedb --datadir ${ethrex_L2_DEV_LIBMDBX}
Expand Down Expand Up @@ -195,7 +215,7 @@ ci_test: ## 🚧 Runs the L2's integration test, used by the github's CI
cargo test state_reconstruct --release

test: ## 🚧 Runs the L2's integration test, run `make init` and in a new terminal make test
CONFIG_FILE=config.toml cargo test l2 --release -- --nocapture --test-threads=1 || (echo "The tests have failed.\n Is the L2 running? To start it, run:\n make rm-db-l1; make rm-db-l2; make restart" ; exit 1)
cargo test l2 --release -- --nocapture --test-threads=1 || (echo "The tests have failed.\n Is the L2 running? To start it, run:\n make rm-db-l1; make rm-db-l2; make restart" ; exit 1)


# Purge L2's state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ interval_ms = 5000
# 1 Gwei
arbitrary_base_blob_gas_price = 1000000000

[prover.client]
prover_server_endpoint = "localhost:3900"
interval_ms = 5000

[prover.server]
[prover_server]
# set it to 0.0.0.0 to allow connections from other machines
listen_ip = "127.0.0.1"
listen_port = 3900
# Not the same account as the [committer] l1 Account
Expand Down
8 changes: 8 additions & 0 deletions crates/l2/configs/prover_client_config_example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[prover_client]
prover_server_endpoint = "localhost:3900"
interval_ms = 5000
# mock, cpu, cuda
sp1_prover = "mock"
# 1 for dev_mode
# 0 for real_proofs
risc0_dev_mode = 1
38 changes: 14 additions & 24 deletions crates/l2/contracts/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use colored::Colorize;
use ethereum_types::{Address, H160, H256};
use ethrex_common::U256;
use ethrex_l2::utils::config::errors;
use ethrex_l2::utils::config::{read_env_as_lines, read_env_file, write_env_file};
use ethrex_l2::utils::config::{
read_env_as_lines_by_config, read_env_file_by_config, toml_parser::parse_configs,
write_env_file_by_config, ConfigMode,
};
use ethrex_l2::utils::test_data_io::read_genesis_file;
use ethrex_l2_sdk::calldata::{encode_calldata, Value};
use ethrex_l2_sdk::get_address_from_secret_key;
Expand Down Expand Up @@ -59,8 +62,8 @@ pub enum DeployError {
EthClientError(#[from] EthClientError),
#[error("Deployer decoding error: {0}")]
DecodingError(String),
#[error("Failed to interact with .env file, error: {0}")]
EnvFileError(#[from] errors::ConfigError),
#[error("Config error: {0}")]
ConfigError(#[from] errors::ConfigError),
#[error("Failed to encode calldata: {0}")]
CalldataEncodeError(#[from] CalldataEncodeError),
}
Expand All @@ -82,24 +85,10 @@ const BRIDGE_INITIALIZER_SIGNATURE: &str = "initialize(address)";

#[tokio::main]
async fn main() -> Result<(), DeployError> {
#[allow(clippy::expect_fun_call, clippy::expect_used)]
let toml_config = std::env::var("CONFIG_FILE").expect(
format!(
"CONFIG_FILE environment variable not defined. Expected in {}, line: {}
If running locally, a reasonable value would be CONFIG_FILE=config.toml",
file!(),
line!()
)
.as_str(),
);

match ethrex_l2::parse_toml::read_toml(toml_config) {
Ok(_) => (),
Err(err) => {
eprintln!("{}", err);
std::process::exit(1);
}
};
if let Err(e) = parse_configs(ConfigMode::Sequencer) {
eprintln!("{e}");
return Err(e.into());
}

let setup_result = setup()?;
download_contract_deps(&setup_result.contracts_path)?;
Expand Down Expand Up @@ -143,7 +132,8 @@ If running locally, a reasonable value would be CONFIG_FILE=config.toml",
}
}

let env_lines = read_env_as_lines().map_err(DeployError::EnvFileError)?;
let env_lines =
read_env_as_lines_by_config(ConfigMode::Sequencer).map_err(DeployError::ConfigError)?;

let mut wr_lines: Vec<String> = Vec::new();
let mut env_lines_iter = env_lines.into_iter();
Expand All @@ -168,12 +158,12 @@ If running locally, a reasonable value would be CONFIG_FILE=config.toml",
}
wr_lines.push(line);
}
write_env_file(wr_lines).map_err(DeployError::EnvFileError)?;
write_env_file_by_config(wr_lines, ConfigMode::Sequencer)?;
Ok(())
}

fn setup() -> Result<SetupResult, DeployError> {
read_env_file()?;
read_env_file_by_config(ConfigMode::Sequencer)?;

let eth_client = EthClient::new(&read_env_var("ETH_RPC_URL")?);

Expand Down
4 changes: 2 additions & 2 deletions crates/l2/contracts/system_contracts_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use bytes::Bytes;
use ethrex_common::types::Genesis;
use ethrex_common::types::GenesisAccount;
use ethrex_common::U256;
use ethrex_l2::utils::config::read_env_file;
use ethrex_l2::utils::config::{read_env_file_by_config, ConfigMode};
use ethrex_l2_sdk::COMMON_BRIDGE_L2_ADDRESS;
use utils::compile_contract;
use utils::ContractCompilationError;

fn main() -> Result<(), ContractCompilationError> {
read_env_file()?;
read_env_file_by_config(ConfigMode::Sequencer)?;
#[allow(clippy::expect_fun_call, clippy::expect_used)]
let contracts_path = Path::new(
&std::env::var("DEPLOYER_CONTRACTS_PATH").expect(
Expand Down
4 changes: 2 additions & 2 deletions crates/l2/docker-compose-l2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services:
volumes:
# NOTE: CI_ETHREX_WORKDIR is defined in crates/l2/Makefile
- ./contracts:${CI_ETHREX_WORKDIR}/contracts
- ./config.toml:${CI_ETHREX_WORKDIR}/config.toml
- ./configs/config.toml:${CI_ETHREX_WORKDIR}/configs/config.toml
- ./.env:${CI_ETHREX_WORKDIR}/.env
- ../../test_data/genesis-l1-dev.json:${CI_ETHREX_WORKDIR}/test_data/genesis-l1-dev.json
- ../../test_data/private_keys_l1.txt:${CI_ETHREX_WORKDIR}/test_data/private_keys_l1.txt
Expand All @@ -24,7 +24,7 @@ services:
# specified in the `volumes:` section
- DEPLOYER_CONTRACTS_PATH=${CI_ETHREX_WORKDIR}/contracts
- ENV_FILE=${CI_ETHREX_WORKDIR}/.env
- CONFIG_FILE=${CI_ETHREX_WORKDIR}/config.toml
- CONFIGS_PATH=${CI_ETHREX_WORKDIR}/configs
- GENESIS_L1_PATH=${CI_ETHREX_WORKDIR}/test_data/genesis-l1-dev.json
- PRIVATE_KEYS_PATH=${CI_ETHREX_WORKDIR}/test_data/private_keys_l1.txt
depends_on:
Expand Down
9 changes: 7 additions & 2 deletions crates/l2/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ For more detailed documentation on each part of the system:
1. `cd crates/l2`
2. `make rm-db-l2 && make down`
- It will remove any old database, if present, stored in your computer. The absolute path of libmdbx is defined by [data_dir](https://docs.rs/dirs/latest/dirs/fn.data_dir.html).
3. `cp config_example.toml config.toml` &rarr; check if you want to change any config.
3. `cp configs/config_example.toml configs/config.toml` &rarr; check if you want to change any config.
- The `salt_is_zero` can be set to:
- `false` &rarr; randomizes the SALT to allow multiple deployments with random addresses.
- `true` &rarr; uses SALT equal to `H256::zero()` to deploy to deterministic addresses.
- The `L1` has to be restarted to use the `salt_is_zero = true`.
- Set it to `false` if not using the CI or running a deterministic test.
4. `make init`
- Init the L1 in a docker container on port `8545`.
- Deploy the needed contracts for the L2 on the L1.
Expand All @@ -27,7 +32,7 @@ For more information on how to run the L2 node with the prover attached to it, t

## Configuration

Configuration is done through env vars. A detailed list is available in each part documentation.
Configuration consists of two steps, the parsing of a `.toml` config file and the creation and modification of a `.env` file, then each component reads the `.env` to load the environment variables. A detailed list is available in each part documentation.

## Testing

Expand Down
56 changes: 40 additions & 16 deletions crates/l2/docs/prover.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
- [What](#what)
- [Workflow](#workflow)
- [How](#how)
- [Quick Test](#quick-test)
- [Quick Test](#quick-test)
- [Dev Mode](#dev-mode)
- [Run the whole system with the prover](#run-the-whole-system-with-the-prover)
- [Run the whole system with the prover - In one Machine](#run-the-whole-system-with-the-prover---in-one-machine)
- [GPU mode](#gpu-mode)
- [Proving Process Test](#proving-process-test)
- [Run the whole system with a GPU Prover](#run-the-whole-system-with-a-gpu-prover)
Expand Down Expand Up @@ -84,18 +84,22 @@ make init-prover T="prover_type (pico,risc0,sp1,exec) G=true"

select the "exec" backend whenever it's not desired to generate proofs, like in a CI environment.

#### Run the whole system with the prover
#### Run the whole system with the prover - In one Machine

> [!NOTE]
> Used for development purposes.

1. `cd crates/l2`
2. `make rm-db-l2 && make down`
- It will remove any old database, if present, stored in your computer. The absolute path of libmdbx is defined by [data_dir](https://docs.rs/dirs/latest/dirs/fn.data_dir.html).
3. `cp config_example.toml config.toml` &rarr; check if you want to change any config.
4. `make init`
3. `cp configs/config_example.toml configs/config.toml` &rarr; check if you want to change any config.
4. `cp configs/prover_client_config_example.toml configs/prover_client_config.toml` &rarr; check if you want to change any config.
5. `make init`
- Make sure you have the `solc` compiler installed in your system.
- Init the L1 in a docker container on port `8545`.
- Deploy the needed contracts for the L2 on the L1.
- Start the L2 locally on port `1729`.
5. In a new terminal &rarr; `make init-prover T=(risc0 or sp1)`.
6. In a new terminal &rarr; `make init-prover T=(sp1,risc0,pico,exec)`.

After this initialization we should have the prover running in `dev_mode` &rarr; No real proofs.

Expand Down Expand Up @@ -137,30 +141,40 @@ Then run any of the targets:

Two servers are required: one for the `prover` and another for the `proposer`. If you run both components on the same machine, the `prover` may consume all available resources, leading to potential stuttering or performance issues for the `proposer`/`node`.

- The number 1 simbolizes a machine with GPU for the `prover_client`.
- The number 2 simbolizes a machine for the `sequencer`/L2 node itself.

1. `prover_client`/`zkvm` &rarr; prover with gpu, make sure to have all the required dependencies described at the beginning of [Gpu Mode](#gpu-mode) section.
1. `cd ethrex/crates/l2`
2. `cp config_example.toml config.toml` and change the `prover_server_endpoint` entry under the [prover.client] section with the ip of the other server.
2. `cp configs/prover_client_config_example.toml configs/prover_client_config.toml` and change the `prover_server_endpoint` with machine's `2` ip and make sure the port matches the one defined in machine 2.

The important variables are:

```sh
[prover.client]
prover_server_endpoint=<ip-address>:3000
[prover_client]
prover_server_endpoint=<ip-address>:3900
```

- `Finally`, to start the `prover_client`/`zkvm`, run:
- `make init-prover T=(risc0 or sp1) G=true`
- `make init-prover T=(sp1,risc0,pico,exec) G=true`

2. `prover_server`/`proposer` &rarr; this server just needs rust installed.
1. `cd ethrex/crates/l2`
2. `cp config_example.toml config.toml` and change the addresses and the following fields:
- [prover.server]
`listen_ip=0.0.0.0` &rarr; used to handle the tcp communication with the other server.
2. `cp configs/config_example.toml configs/config.toml` and change the addresses and the following fields:
- [prover_server]
- `listen_ip=0.0.0.0` &rarr; Used to handle TCP communication with other servers from any network interface.
- The `COMMITTER` and `PROVER_SERVER_VERIFIER` must be different accounts, the `DEPLOYER_ADDRESS` as well as the `L1_WATCHER` may be the same account used by the `COMMITTER`.
- [deployer]
- `salt_is_zero=false` &rarr; set to false to randomize the salt.
- `sp1_deploy_verifier = true` overwrites `sp1_contract_verifier`. Check if the contract is deployed in your preferred network or set to `true` to deploy it.
- `risc0_contract_verifier = 0xd9b0d07CeCd808a8172F21fA7C97992168f045CA` &rarr; risc0’s verifier contract deployed on Sepolia. (Check the if the contract is deployed in your preferred network). An analog variable called `sp1_contract_verifier` exists for SP1.
- `risc0_contract_verifier`
- Check the if the contract is present on your preferred network.
- `sp1_contract_verifier`
- It can be deployed.
- Check the if the contract is present on your preferred network.
- `pico_contract_verifier`
- It can be deployed.
- Check the if the contract is present on your preferred network.
- Set the [eth] `rpc_url` to any L1 endpoint.

> [!NOTE]
Expand All @@ -172,11 +186,21 @@ prover_server_endpoint=<ip-address>:3000

## Configuration

The following environment variables are available to configure the prover:
Configuration is done through environment variables. The easiest way to configure the ProverClient is by creating a `prover_client_config.toml` file and setting the variables there. Then, at start, it will read the file and set the variables.

The following environment variables are available to configure the Proposer consider looking at the provided [prover_client_config_example.toml](../configs/prover_client_config_example.toml):

The following environment variables are used by the ProverClient:

- `CONFIGS_PATH`: The path where the `PROVER_CLIENT_CONFIG_FILE` is located at.
- `PROVER_CLIENT_CONFIG_FILE`: The `.toml` that contains the config for the `prover_client`.
- `PROVER_ENV_FILE`: The name of the `.env` that has the parsed `.toml` configuration.
- `PROVER_CLIENT_PROVER_SERVER_ENDPOINT`: Prover Server's Endpoint used to connect the Client to the Server.

The following environment variables are used by the ProverServer:

- `PROVER_SERVER_LISTEN_IP`: IP used to start the Server.
- `PROVER_SERVER_LISTEN_PORT`: Port used to start the Server.
- `PROVER_CLIENT_PROVER_SERVER_ENDPOINT`: Prover Server's Endpoint used to connect the Client to the Server.
- `PROVER_SERVER_VERIFIER_ADDRESS`: The address of the account that sends the zkProofs on-chain and interacts with the `OnChainProposer` `verify()` function.
- `PROVER_SERVER_VERIFIER_PRIVATE_KEY`: The private key of the account that sends the zkProofs on-chain and interacts with the `OnChainProposer` `verify()` function.

Expand Down
Loading