Skip to content
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

feat: L1 Fee Scalar calculation #183

Merged
merged 17 commits into from
Oct 25, 2024
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ op-alloy-genesis = { version = "0.4.0", default-features = false, features = [
op-alloy-protocol = { version = "0.4.0", default-features = false }
op-alloy-rpc-types = { version = "0.4.0", default-features = false }
op-alloy-rpc-types-engine = { version = "0.4.0", default-features = false }
op-alloy-network = { version = "0.4.0", default-features = false }

# sp1
sp1-lib = { version = "3.0.0-rc3", features = ["verify"] }
Expand Down
8 changes: 4 additions & 4 deletions configs/10/rollup.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"l2_time": 1686068903,
"system_config": {
"batcherAddr": "0x6887246668a3b87F54DeB3b94Ba47a6f63F32985",
"batcherAddr": "0x6887246668a3b87f54deb3b94ba47a6f63f32985",
"overhead": "0xbc",
"scalar": "0xa6fe0",
"gasLimit": 30000000,
Expand Down Expand Up @@ -41,8 +41,8 @@
"ecotone_time": 1710374401,
"fjord_time": 1720627201,
"granite_time": 1726070401,
"batch_inbox_address": "0xFF00000000000000000000000000000000000010",
"deposit_contract_address": "0xbEb5Fc579115071764c7423A4f12eDde41f106Ed",
"l1_system_config_address": "0x229047fed2591dbec1eF1118d64F7aF3dB9EB290",
"batch_inbox_address": "0xff00000000000000000000000000000000000010",
"deposit_contract_address": "0xbeb5fc579115071764c7423a4f12edde41f106ed",
"l1_system_config_address": "0x229047fed2591dbec1ef1118d64f7af3db9eb290",
"protocol_versions_address": "0x0000000000000000000000000000000000000000"
}
8 changes: 4 additions & 4 deletions configs/11155420/rollup.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"l2_time": 1691802540,
"system_config": {
"batcherAddr": "0x8F23BB38F531600e5d8FDDaAEC41F13FaB46E98c",
"batcherAddr": "0x8f23bb38f531600e5d8fddaaec41f13fab46e98c",
"overhead": "0xbc",
"scalar": "0xa6fe0",
"gasLimit": 30000000,
Expand Down Expand Up @@ -42,7 +42,7 @@
"fjord_time": 1716998400,
"granite_time": 1723478400,
"batch_inbox_address": "0xff00000000000000000000000000000011155420",
"deposit_contract_address": "0x16Fc5058F25648194471939df75CF27A2fdC48BC",
"l1_system_config_address": "0x034edD2A225f7f429A63E0f1D2084B9E0A93b538",
"protocol_versions_address": "0x79ADD5713B383DAa0a138d3C4780C7A1804a8090"
"deposit_contract_address": "0x16fc5058f25648194471939df75cf27a2fdc48bc",
"l1_system_config_address": "0x034edd2a225f7f429a63e0f1d2084b9e0a93b538",
"protocol_versions_address": "0x79add5713b383daa0a138d3c4780c7a1804a8090"
}
48 changes: 48 additions & 0 deletions configs/8453/rollup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"genesis": {
"l1": {
"number": 17481768,
"hash": "0x5c13d307623a926cd31415036c8b7fa14572f9dac64528e857a470511fc30771"
},
"l2": {
"number": 0,
"hash": "0xf712aa9241cc24369b143cf6dce85f0902a9731e70d66818a3a5845b296c73dd"
},
"l2_time": 1686789347,
"system_config": {
"batcherAddr": "0x5050f69a9786f081509234f1a7f4684b5e5b76c9",
"overhead": "0xbc",
"scalar": "0xa6fe0",
"gasLimit": 30000000,
"baseFeeScalar": null,
"blobBaseFeeScalar": null,
"eip1559Denominator": null,
"eip1559Elasticity": null
}
},
"block_time": 2,
"max_sequencer_drift": 600,
"seq_window_size": 3600,
"channel_timeout": 300,
"granite_channel_timeout": 50,
"l1_chain_id": 1,
"l2_chain_id": 8453,
"base_fee_params": {
"max_change_denominator": "0x32",
"elasticity_multiplier": "0x6"
},
"canyon_base_fee_params": {
"max_change_denominator": "0xfa",
"elasticity_multiplier": "0x6"
},
"regolith_time": 0,
"canyon_time": 1704992401,
"delta_time": 1708560000,
"ecotone_time": 1710374401,
"fjord_time": 1720627201,
"granite_time": 1726070401,
"batch_inbox_address": "0xff00000000000000000000000000000000008453",
"deposit_contract_address": "0x49048044d57e1c92a77f79988d21fa8faf74e97e",
"l1_system_config_address": "0x73a79fab69143498ed3712e519a88a918e1f4072",
"protocol_versions_address": "0x0000000000000000000000000000000000000000"
}
20 changes: 20 additions & 0 deletions scripts/fees/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "op-succinct-fees"
version = "0.1.0"
license.workspace = true
edition.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true

[[bin]]
name = "l1-fee-scalar"
path = "bin/l1_fee_scalar.rs"

[dependencies]
op-succinct-host-utils = { workspace = true }
clap = { workspace = true }
anyhow = { workspace = true }
tokio = { workspace = true }
dotenv = { workspace = true }
alloy-primitives = { workspace = true }
56 changes: 56 additions & 0 deletions scripts/fees/bin/l1_fee_scalar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use std::time::Instant;

use alloy_primitives::U256;
use anyhow::Result;
use clap::Parser;
use op_succinct_fees::aggregate_fee_data;
use op_succinct_host_utils::fetcher::OPSuccinctDataFetcher;

#[derive(Parser)]
struct Args {
#[clap(long)]
start: u64,
#[clap(long)]
end: u64,
#[clap(long, default_value = None)]
l1_fee_scalar: Option<U256>,
#[clap(long, default_value = ".env")]
env_file: String,
}

#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();
dotenv::from_filename(args.env_file).ok();
let fetcher = OPSuccinctDataFetcher::default();

let start_time = Instant::now();
let (fee_data, modified_fee_data) = tokio::join!(
fetcher.get_l2_fee_data_range(args.start, args.end),
fetcher.get_l2_fee_data_with_modified_l1_fee_scalar(
args.start,
args.end,
args.l1_fee_scalar
)
);
let duration = start_time.elapsed();
println!("Done getting fee data. Time taken: {:?}", duration);

let fee_data = fee_data?;
let modified_fee_data = modified_fee_data?;

let total_aggregate_fee_data = aggregate_fee_data(fee_data)?;
let modified_total_aggregate_fee_data = aggregate_fee_data(modified_fee_data)?;

println!("{modified_total_aggregate_fee_data}");
println!("{total_aggregate_fee_data}");

assert_eq!(
total_aggregate_fee_data.total_l1_fee,
modified_total_aggregate_fee_data.total_l1_fee
);

println!("Success!");

Ok(())
}
41 changes: 41 additions & 0 deletions scripts/fees/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::fmt;

use alloy_primitives::U256;
use anyhow::Result;
use op_succinct_host_utils::fetcher::FeeData;

pub struct AggregateFeeData {
pub start: u64,
pub end: u64,
pub num_transactions: u64,
pub total_l1_fee: U256,
}

impl fmt::Display for AggregateFeeData {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let eth = self.total_l1_fee / U256::from(10).pow(U256::from(18));
let gwei = (self.total_l1_fee / U256::from(10).pow(U256::from(9)))
% U256::from(10).pow(U256::from(9));
write!(
f,
"Start: {}, End: {}, Aggregate: {} transactions, {}.{:09} ETH L1 fee",
self.start, self.end, self.num_transactions, eth, gwei
)
}
}

pub fn aggregate_fee_data(fee_data: Vec<FeeData>) -> Result<AggregateFeeData> {
let mut aggregate_fee_data = AggregateFeeData {
start: fee_data[0].block_number,
end: fee_data[fee_data.len() - 1].block_number,
num_transactions: 0,
total_l1_fee: U256::ZERO,
};

for data in fee_data {
aggregate_fee_data.num_transactions += 1;
aggregate_fee_data.total_l1_fee += data.l1_gas_cost;
}

Ok(aggregate_fee_data)
}
9 changes: 3 additions & 6 deletions scripts/prove/bin/agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use anyhow::Result;
use cargo_metadata::MetadataCommand;
use clap::Parser;
use op_succinct_client_utils::boot::BootInfoStruct;
use op_succinct_host_utils::{
fetcher::{OPSuccinctDataFetcher, RPCMode},
get_agg_proof_stdin,
};
use op_succinct_host_utils::{fetcher::OPSuccinctDataFetcher, get_agg_proof_stdin};
use sp1_sdk::{utils, HashableKey, ProverClient, SP1Proof, SP1ProofWithPublicValues};
use std::fs;

Expand Down Expand Up @@ -67,10 +64,10 @@ async fn main() -> Result<()> {
let prover = ProverClient::new();
let fetcher = OPSuccinctDataFetcher::default();

let l2_chain_id = fetcher.get_chain_id(RPCMode::L2).await?;
let l2_chain_id = fetcher.get_l2_chain_id().await?;
let (proofs, boot_infos) = load_aggregation_proof_data(args.proofs, l2_chain_id);
let latest_checkpoint_head = fetcher
.get_header_by_number(RPCMode::L1, args.latest_checkpoint_head_nb)
.get_l1_header(args.latest_checkpoint_head_nb.into())
.await?
.hash_slow();
let headers = fetcher
Expand Down
6 changes: 3 additions & 3 deletions scripts/prove/bin/multi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use op_succinct_host_utils::{
fetcher::{CacheMode, OPSuccinctDataFetcher, RPCMode},
fetcher::{CacheMode, OPSuccinctDataFetcher},
get_proof_stdin,
stats::ExecutionStats,
witnessgen::WitnessGenExecutor,
Expand Down Expand Up @@ -91,7 +91,7 @@ async fn main() -> Result<()> {
// Create a proof directory for the chain ID if it doesn't exist.
let proof_dir = format!(
"data/{}/proofs",
data_fetcher.get_chain_id(RPCMode::L2).await.unwrap()
data_fetcher.get_l2_chain_id().await.unwrap()
);
if !std::path::Path::new(&proof_dir).exists() {
fs::create_dir_all(&proof_dir).unwrap();
Expand All @@ -108,7 +108,7 @@ async fn main() -> Result<()> {
.unwrap();
let execution_duration = start_time.elapsed();

let l2_chain_id = data_fetcher.get_chain_id(RPCMode::L2).await.unwrap();
let l2_chain_id = data_fetcher.get_l2_chain_id().await.unwrap();
let report_path = format!(
"execution-reports/multi/{}/{}-{}.csv",
l2_chain_id, args.start, args.end
Expand Down
9 changes: 3 additions & 6 deletions scripts/prove/bin/single.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use clap::Parser;
use op_succinct_host_utils::{
fetcher::{CacheMode, OPSuccinctDataFetcher, RPCMode},
fetcher::{CacheMode, OPSuccinctDataFetcher},
get_proof_stdin,
stats::ExecutionStats,
witnessgen::WitnessGenExecutor,
Expand Down Expand Up @@ -36,6 +36,7 @@ async fn main() -> Result<()> {
utils::setup_logger();

let data_fetcher = OPSuccinctDataFetcher::default();
let l2_chain_id = data_fetcher.get_l2_chain_id().await?;

let l2_safe_head = args.l2_block - 1;

Expand Down Expand Up @@ -71,10 +72,7 @@ async fn main() -> Result<()> {
let proof = prover.prove(&pk, sp1_stdin).plonk().run().unwrap();

// Create a proof directory for the chain ID if it doesn't exist.
let proof_dir = format!(
"data/{}/proofs",
data_fetcher.get_chain_id(RPCMode::L2).await.unwrap()
);
let proof_dir = format!("data/{}/proofs", l2_chain_id);
if !std::path::Path::new(&proof_dir).exists() {
std::fs::create_dir_all(&proof_dir)?;
}
Expand All @@ -86,7 +84,6 @@ async fn main() -> Result<()> {
let (_, report) = prover.execute(SINGLE_BLOCK_ELF, sp1_stdin).run().unwrap();
let execution_duration = start_time.elapsed();

let l2_chain_id = data_fetcher.get_chain_id(RPCMode::L2).await.unwrap();
let report_path = format!(
"execution-reports/single/{}/{}.csv",
l2_chain_id, args.l2_block
Expand Down
6 changes: 3 additions & 3 deletions scripts/utils/bin/cost_estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::Parser;
use kona_host::HostCli;
use log::info;
use op_succinct_host_utils::{
fetcher::{CacheMode, OPSuccinctDataFetcher, RPCMode},
fetcher::{CacheMode, OPSuccinctDataFetcher},
get_proof_stdin,
stats::ExecutionStats,
witnessgen::WitnessGenExecutor,
Expand Down Expand Up @@ -91,7 +91,7 @@ async fn run_native_data_generation(
data_fetcher: &OPSuccinctDataFetcher,
split_ranges: &[SpanBatchRange],
) -> Vec<BatchHostCli> {
const CONCURRENT_NATIVE_HOST_RUNNERS: usize = 20;
const CONCURRENT_NATIVE_HOST_RUNNERS: usize = 5;

// Split the entire range into chunks of size CONCURRENT_NATIVE_HOST_RUNNERS and process chunks
// serially. Generate witnesses within each chunk in parallel. This prevents the RPC from
Expand Down Expand Up @@ -294,7 +294,7 @@ async fn main() -> Result<()> {
let args = HostArgs::parse();
let data_fetcher = OPSuccinctDataFetcher::default();

let l2_chain_id = data_fetcher.get_chain_id(RPCMode::L2).await?;
let l2_chain_id = data_fetcher.get_l2_chain_id().await?;

let split_ranges = split_range(args.start, args.end, l2_chain_id);

Expand Down
Loading
Loading