Skip to content

feat(l2): config eth client through .toml #2510

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 36 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
71787dd
add elasticity multiplier to producer config
tomip01 Apr 21, 2025
1a50997
add fields to deserializer eth config
tomip01 Apr 21, 2025
b44d940
use fields in eth client
tomip01 Apr 21, 2025
3b9446a
create eth client with configs
tomip01 Apr 21, 2025
ff75cc5
remove unused import
tomip01 Apr 21, 2025
a0f6bec
add elasticity multiplier to param
tomip01 Apr 21, 2025
5823772
fix typo
tomip01 Apr 22, 2025
8b7a6b8
use simple creation
tomip01 Apr 22, 2025
0cf7f8d
use elasticity multiplier for validating blocks
tomip01 Apr 22, 2025
abdb88e
read env var in every place instead of constant
tomip01 Apr 22, 2025
c050059
add elasticity multiplier to param in validate block
tomip01 Apr 22, 2025
b2650c4
add env var in both .toml
tomip01 Apr 23, 2025
807d609
correct elasticity multiplier
tomip01 Apr 23, 2025
6f54850
add elasticity multiplier in sp1 main
tomip01 Apr 23, 2025
1c7cf78
use unwrap
tomip01 Apr 23, 2025
46d8787
use unwrap again
tomip01 Apr 23, 2025
e5e8c00
add elasticity multiplier to ProgramInput
tomip01 Apr 23, 2025
3c933cc
Merge branch 'main' into l2/add-configs-toml
tomip01 Apr 23, 2025
54671f1
use block proposer for env config in test_data_io
tomip01 Apr 23, 2025
6fa3146
fix pico and try fix on perf_zkvm
tomip01 Apr 23, 2025
ad50744
use fix value for test
tomip01 Apr 23, 2025
abbd9c6
Merge branch 'main' into l2/add-configs-toml
tomip01 Apr 24, 2025
3ebb421
merge main
tomip01 Apr 24, 2025
b8847d6
Merge branch 'main' into l2/add-configs-toml
jrchatruc Apr 28, 2025
9fa898a
remove redundant elasticity multiplier
tomip01 Apr 29, 2025
a1ad3b7
improve docs
tomip01 Apr 29, 2025
0ebe3c8
add missing paramenters
tomip01 Apr 29, 2025
4eb367a
Merge branch 'main' into l2/add-configs-toml
tomip01 Apr 29, 2025
b4a463b
remove parsing from config prover client
tomip01 Apr 29, 2025
9708d99
This is an empty commit
tomip01 Apr 29, 2025
ca9f6c4
Merge branch 'main' into l2/add-configs-toml
tomip01 Apr 30, 2025
40346a0
Merge branch 'main' into l2/add-configs-toml
tomip01 Apr 30, 2025
3da963d
Merge branch 'main' into l2/add-configs-toml
tomip01 May 12, 2025
e17cf9c
merge main
tomip01 May 12, 2025
13e0e05
add options flags
tomip01 May 12, 2025
1169c22
Merge branch 'main' into l2/add-configs-toml
jrchatruc May 12, 2025
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
45 changes: 45 additions & 0 deletions cmd/ethrex/l2/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl From<SequencerOptions> for SequencerConfig {
block_producer: BlockProducerConfig {
block_time_ms: opts.proposer_opts.block_time_ms,
coinbase_address: opts.proposer_opts.coinbase_address,
elasticity_multiplier: opts.proposer_opts.elasticity_multiplier,
},
l1_committer: CommitterConfig {
on_chain_proposer_address: opts.committer_opts.on_chain_proposer_address,
Expand All @@ -63,6 +64,10 @@ impl From<SequencerOptions> for SequencerConfig {
},
eth: EthConfig {
rpc_url: opts.eth_opts.rpc_url,
max_number_of_retries: opts.eth_opts.max_number_of_retries,
backoff_factor: opts.eth_opts.backoff_factor,
min_retry_delay: opts.eth_opts.min_retry_delay,
max_retry_delay: opts.eth_opts.max_retry_delay,
maximum_allowed_max_fee_per_gas: opts.eth_opts.maximum_allowed_max_fee_per_gas,
maximum_allowed_max_fee_per_blob_gas: opts
.eth_opts
Expand Down Expand Up @@ -115,6 +120,38 @@ pub struct EthOptions {
help_heading = "Eth options"
)]
pub maximum_allowed_max_fee_per_blob_gas: u64,
#[arg(
long = "eth-max-number-of-retries",
default_value = "10",
value_name = "UINT64",
env = "ETHREX_MAX_NUMBER_OF_RETRIES",
help_heading = "Eth options"
)]
pub max_number_of_retries: u64,
#[arg(
long = "eth-backoff-factor",
default_value = "2",
value_name = "UINT64",
env = "ETHREX_BACKOFF_FACTOR",
help_heading = "Eth options"
)]
pub backoff_factor: u64,
#[arg(
long = "eth-min-retry-delay",
default_value = "96",
value_name = "UINT64",
env = "ETHREX_MIN_RETRY_DELAY",
help_heading = "Eth options"
)]
pub min_retry_delay: u64,
#[arg(
long = "eth-max-retry-delay",
default_value = "1800",
value_name = "UINT64",
env = "ETHREX_MAX_RETRY_DELAY",
help_heading = "Eth options"
)]
pub max_retry_delay: u64,
}

#[derive(Parser)]
Expand Down Expand Up @@ -187,6 +224,14 @@ pub struct ProposerOptions {
help_heading = "Proposer options"
)]
pub coinbase_address: Address,
#[arg(
long,
default_value = "2",
value_name = "UINT64",
env = "ETHREX_PROPOSER_ELASTICITY_MULTIPLIER",
help_heading = "Proposer options"
)]
pub elasticity_multiplier: u64,
}

#[derive(Parser)]
Expand Down
10 changes: 6 additions & 4 deletions crates/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use ethrex_common::types::{
validate_prague_header_fields, validate_pre_cancun_header_fields, Block, BlockHash,
BlockHeader, BlockNumber, ChainConfig, EIP4844Transaction, Receipt, Transaction,
};
use ethrex_common::types::{BlobsBundle, Fork};
use ethrex_common::types::{BlobsBundle, Fork, ELASTICITY_MULTIPLIER};

use ethrex_common::{Address, H256};
use mempool::Mempool;
Expand Down Expand Up @@ -75,7 +75,7 @@ impl Blockchain {
let chain_config = self.storage.get_chain_config()?;

// Validate the block pre-execution
validate_block(block, &parent_header, &chain_config)?;
validate_block(block, &parent_header, &chain_config, ELASTICITY_MULTIPLIER)?;

let mut vm = Evm::new(
self.evm_engine,
Expand All @@ -102,7 +102,7 @@ impl Blockchain {
vm: &mut Evm,
) -> Result<BlockExecutionResult, ChainError> {
// Validate the block pre-execution
validate_block(block, parent_header, chain_config)?;
validate_block(block, parent_header, chain_config, ELASTICITY_MULTIPLIER)?;

let execution_result = vm.execute_block(block)?;

Expand Down Expand Up @@ -560,9 +560,11 @@ pub fn validate_block(
block: &Block,
parent_header: &BlockHeader,
chain_config: &ChainConfig,
elasticity_multiplier: u64,
) -> Result<(), ChainError> {
// Verify initial header validity against parent
validate_block_header(&block.header, parent_header).map_err(InvalidBlockError::from)?;
validate_block_header(&block.header, parent_header, elasticity_multiplier)
.map_err(InvalidBlockError::from)?;

if chain_config.is_prague_activated(block.header.timestamp) {
validate_prague_header_fields(&block.header, parent_header, chain_config)
Expand Down
2 changes: 2 additions & 0 deletions crates/blockchain/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub struct BuildPayloadArgs {
pub withdrawals: Option<Vec<Withdrawal>>,
pub beacon_root: Option<H256>,
pub version: u8,
pub elasticity_multiplier: u64,
}

impl BuildPayloadArgs {
Expand Down Expand Up @@ -111,6 +112,7 @@ pub fn create_payload(args: &BuildPayloadArgs, storage: &Store) -> Result<Block,
parent_block.gas_limit,
parent_block.gas_used,
parent_block.base_fee_per_gas.unwrap_or_default(),
args.elasticity_multiplier,
),
withdrawals_root: chain_config
.is_shanghai_activated(args.timestamp)
Expand Down
3 changes: 2 additions & 1 deletion crates/blockchain/smoke_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod blockchain_integration_test {
};

use ethrex_common::{
types::{Block, BlockHeader},
types::{Block, BlockHeader, ELASTICITY_MULTIPLIER},
H160, H256,
};
use ethrex_storage::{EngineType, Store};
Expand Down Expand Up @@ -301,6 +301,7 @@ mod blockchain_integration_test {
withdrawals: Some(Vec::new()),
beacon_root: Some(H256::random()),
version: 1,
elasticity_multiplier: ELASTICITY_MULTIPLIER,
};

// Create blockchain
Expand Down
13 changes: 8 additions & 5 deletions crates/common/types/block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
ChainConfig, BASE_FEE_MAX_CHANGE_DENOMINATOR, ELASTICITY_MULTIPLIER,
GAS_LIMIT_ADJUSTMENT_FACTOR, GAS_LIMIT_MINIMUM, INITIAL_BASE_FEE,
ChainConfig, BASE_FEE_MAX_CHANGE_DENOMINATOR, GAS_LIMIT_ADJUSTMENT_FACTOR, GAS_LIMIT_MINIMUM,
INITIAL_BASE_FEE,
};
use crate::{
constants::{GAS_PER_BLOB, MIN_BASE_FEE_PER_BLOB_GAS},
Expand Down Expand Up @@ -432,14 +432,15 @@ pub fn calculate_base_fee_per_gas(
parent_gas_limit: u64,
parent_gas_used: u64,
parent_base_fee_per_gas: u64,
elasticity_multiplier: u64,
) -> Option<u64> {
// Check gas limit, if the check passes we can also rest assured that none of the
// following divisions will have zero as a divider
if !check_gas_limit(block_gas_limit, parent_gas_limit) {
return None;
}

let parent_gas_target = parent_gas_limit / ELASTICITY_MULTIPLIER;
let parent_gas_target = parent_gas_limit / elasticity_multiplier;

Some(match parent_gas_used.cmp(&parent_gas_target) {
Ordering::Equal => parent_base_fee_per_gas,
Expand Down Expand Up @@ -513,6 +514,7 @@ pub enum InvalidBlockHeaderError {
pub fn validate_block_header(
header: &BlockHeader,
parent_header: &BlockHeader,
elasticity_multiplier: u64,
) -> Result<(), InvalidBlockHeaderError> {
if header.gas_used > header.gas_limit {
return Err(InvalidBlockHeaderError::GasUsedGreaterThanGasLimit);
Expand All @@ -523,6 +525,7 @@ pub fn validate_block_header(
parent_header.gas_limit,
parent_header.gas_used,
parent_header.base_fee_per_gas.unwrap_or(INITIAL_BASE_FEE),
elasticity_multiplier,
) {
base_fee
} else {
Expand Down Expand Up @@ -669,7 +672,7 @@ pub fn calc_excess_blob_gas(
#[cfg(test)]
mod test {
use super::*;
use crate::types::EMPTY_KECCACK_HASH;
use crate::types::{ELASTICITY_MULTIPLIER, EMPTY_KECCACK_HASH};
use ethereum_types::H160;
use hex_literal::hex;
use std::str::FromStr;
Expand Down Expand Up @@ -787,7 +790,7 @@ mod test {
parent_beacon_block_root: Some(H256::zero()),
requests_hash: Some(*EMPTY_KECCACK_HASH),
};
assert!(validate_block_header(&block, &parent_block).is_ok())
assert!(validate_block_header(&block, &parent_block, ELASTICITY_MULTIPLIER).is_ok())
}

#[test]
Expand Down
36 changes: 36 additions & 0 deletions crates/l2/contracts/bin/deployer/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@ pub struct DeployerOptions {
help = "Private key corresponding of a funded account that will be used for L1 contract deployment.",
)]
pub private_key: SecretKey,
#[arg(
long,
default_value = "10",
value_name = "UINT64",
env = "ETHREX_ETH_MAX_NUMBER_OF_RETRIES",
help_heading = "Eth options"
)]
pub max_number_of_retries: u64,
#[arg(
long,
default_value = "2",
value_name = "UINT64",
env = "ETHREX_ETH_BACKOFF_FACTOR",
help_heading = "Eth options"
)]
pub backoff_factor: u64,
#[arg(
long,
default_value = "96",
value_name = "UINT64",
env = "ETHREX_ETH_MIN_RETRY_DELAY",
help_heading = "Eth options"
)]
pub min_retry_delay: u64,
#[arg(
long,
default_value = "1800",
value_name = "UINT64",
env = "ETHREX_ETH_MAX_RETRY_DELAY",
help_heading = "Eth options"
)]
pub max_retry_delay: u64,
#[arg(
long,
value_name = "PATH",
Expand Down Expand Up @@ -181,6 +213,10 @@ impl Default for DeployerOptions {
rpc_url: "http://localhost:8545".to_string(),
maximum_allowed_max_fee_per_gas: 10_000_000_000,
maximum_allowed_max_fee_per_blob_gas: 10_000_000_000,
max_number_of_retries: 10,
backoff_factor: 2,
min_retry_delay: 96,
max_retry_delay: 1800,
#[allow(clippy::unwrap_used)]
private_key: SecretKey::from_slice(
H256([
Expand Down
10 changes: 7 additions & 3 deletions crates/l2/contracts/bin/deployer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ const BRIDGE_INITIALIZER_SIGNATURE: &str = "initialize(address)";
async fn main() -> Result<(), DeployerError> {
let opts = DeployerOptions::parse();

let eth_client = EthClient::new_with_maximum_fees(
let eth_client = EthClient::new_with_config(
&opts.rpc_url,
opts.maximum_allowed_max_fee_per_gas,
opts.maximum_allowed_max_fee_per_blob_gas,
opts.max_number_of_retries,
opts.backoff_factor,
opts.min_retry_delay,
opts.max_retry_delay,
Some(opts.maximum_allowed_max_fee_per_gas),
Some(opts.maximum_allowed_max_fee_per_blob_gas),
);

download_contract_deps(&opts)?;
Expand Down
8 changes: 7 additions & 1 deletion crates/l2/prover/src/backends/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fn execution_program(input: ProgramInput) -> Result<ProgramOutput, Box<dyn std::
blocks,
parent_block_header,
mut db,
elasticity_multiplier,
} = input;

// Tries used for validating initial and final state root
Expand All @@ -63,7 +64,12 @@ fn execution_program(input: ProgramInput) -> Result<ProgramOutput, Box<dyn std::

for block in blocks {
// Validate the block
validate_block(&block, &parent_header, &db.chain_config)?;
validate_block(
&block,
&parent_header,
&db.chain_config,
elasticity_multiplier,
)?;

// Execute block
let mut vm = Evm::from_execution_db(db.clone());
Expand Down
3 changes: 2 additions & 1 deletion crates/l2/prover/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ impl Prover {
input: ProgramInput {
blocks: input.blocks,
parent_block_header: input.parent_block_header,
db: input.db
db: input.db,
elasticity_multiplier: input.elasticity_multiplier,
}
};
Ok(prover_data)
Expand Down
7 changes: 5 additions & 2 deletions crates/l2/prover/tests/perf_zkvm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(clippy::expect_used)]
#![allow(clippy::unwrap_used)]
use ethrex_blockchain::Blockchain;
use ethrex_common::types::Block;
use ethrex_common::types::{Block, ELASTICITY_MULTIPLIER};
use ethrex_prover_lib::execute;
use ethrex_storage::{EngineType, Store};
use ethrex_vm::Evm;
Expand All @@ -16,7 +16,6 @@ async fn test_performance_zkvm() {
let (input, block_to_prove) = setup().await;

let start = std::time::Instant::now();

// this is only executing because these tests run as a CI job and should be fast
// TODO: create a test for actual proving
execute(input).unwrap();
Expand Down Expand Up @@ -69,10 +68,14 @@ async fn setup() -> (ProgramInput, Block) {
.await
.unwrap();

// This is just a test, so we can use the default value for the elasticity multiplier.
let elasticity_multiplier = ELASTICITY_MULTIPLIER;

let input = ProgramInput {
blocks: vec![block_to_prove.clone()],
parent_block_header,
db,
elasticity_multiplier,
};
(input, block_to_prove.clone())
}
10 changes: 9 additions & 1 deletion crates/l2/prover/zkvm/interface/pico/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use pico_sdk::io::{commit, read_as};
use ethrex_blockchain::{validate_block, validate_gas_used};
use ethrex_common::Address;
use ethrex_storage::AccountUpdate;
use ethrex_vm::backends::revm::{db::EvmState, REVM};
use ethrex_vm::Evm;
use std::collections::HashMap;
use zkvm_interface::{
Expand All @@ -19,6 +20,7 @@ pub fn main() {
blocks,
parent_block_header,
mut db,
elasticity_multiplier,
} = read_as();
// Tries used for validating initial and final state root
let (mut state_trie, mut storage_tries) = db
Expand All @@ -41,7 +43,13 @@ pub fn main() {

for block in blocks {
// Validate the block
validate_block(&block, &parent_header, &db.chain_config).expect("invalid block");
validate_block(
&block,
&parent_header,
&db.chain_config,
elasticity_multiplier,
)
.expect("invalid block");

// Execute block
let mut vm = Evm::from_execution_db(db.clone());
Expand Down
9 changes: 8 additions & 1 deletion crates/l2/prover/zkvm/interface/sp1/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn main() {
blocks,
parent_block_header,
mut db,
elasticity_multiplier,
} = sp1_zkvm::io::read::<ProgramInput>();
// Tries used for validating initial and final state root
let (mut state_trie, mut storage_tries) = db
Expand All @@ -41,7 +42,13 @@ pub fn main() {

for block in blocks {
// Validate the block
validate_block(&block, &parent_header, &db.chain_config).expect("invalid block");
validate_block(
&block,
&parent_header,
&db.chain_config,
elasticity_multiplier,
)
.expect("invalid block");

// Execute block
let mut vm = Evm::from_execution_db(db.clone());
Expand Down
Loading
Loading