From 8f8534ed693d49b977a181144406eba1b6f6faa7 Mon Sep 17 00:00:00 2001 From: Ratan Kaliani Date: Tue, 3 Sep 2024 15:51:47 -0700 Subject: [PATCH] docs --- book/cost-estimator.md | 38 +++++++++++++++-------- proposer/succinct/bin/cost_estimator.rs | 13 ++++---- utils/host/src/stats.rs | 41 +++++-------------------- 3 files changed, 40 insertions(+), 52 deletions(-) diff --git a/book/cost-estimator.md b/book/cost-estimator.md index 2b8b57c6..eafd6090 100644 --- a/book/cost-estimator.md +++ b/book/cost-estimator.md @@ -1,4 +1,4 @@ -# Cycle Counts [Cost Estimator] +# Cost Estimator We provide a convenient CLI tool to estimate the RISC-V cycle counts (and cost) for generating ZKPs for a range of blocks for a given rollup. @@ -26,9 +26,9 @@ This command will execute `op-succinct` as if it's in production. First, it will into smaller ranges optimized along the span batch boundaries. Then it will fetch the required data for generating the ZKP for each of these ranges, and execute the SP1 `span` program. Once each program finishes, it will collect the statistics and output the aggregate statistics for the entire block range. From this data, you can extrapolate the cycle count to a cost based on the cost per billion cycles. -## Example Block Range +## Example -On OP Sepolia, generating a proof from 15840000 to 15840050 (50 blocks) generates 4 span proofs, takes ~1.8B cycles and takes +On Optimism Sepolia, proving the block range 15840000 to 15840050 (50 blocks) generates 4 span proofs, takes ~1.8B cycles and ~2 minutes to execute. ```bash @@ -39,16 +39,28 @@ RUST_LOG=info just cost-estimator 15840000 15840050 +--------------------------------+---------------------------+ | Metric | Value | +--------------------------------+---------------------------+ -| Total Cycles | 1,502,329,547 | -| Block Execution Cycles | 1,009,112,508 | -| Total Blocks | 51 | -| Total Transactions | 202 | -| Cycles per Block | 19,786,519 | -| Cycles per Transaction | 4,995,606 | -| Transactions per Block | 3 | -| Total Gas Used | 52,647,751 | -| Gas Used per Block | 1,032,308 | -| Gas Used per Transaction | 260,632 | +| Batch Start | 16,240,000 | +| Batch End | 16,240,050 | +| Execution Duration (seconds) | 130 | +| Total Instruction Count | 1,776,092,063 | +| Oracle Verify Cycles | 237,150,812 | +| Derivation Cycles | 493,177,851 | +| Block Execution Cycles | 987,885,587 | +| Blob Verification Cycles | 84,995,660 | +| Total SP1 Gas | 2,203,604,618 | +| Number of Blocks | 51 | +| Number of Transactions | 160 | +| Ethereum Gas Used | 43,859,242 | +| Cycles per Block | 74,736,691 | +| Cycles per Transaction | 23,422,603 | +| Transactions per Block | 11 | +| Gas Used per Block | 3,509,360 | +| Gas Used per Transaction | 1,105,066 | +| BN Pair Cycles | 0 | +| BN Add Cycles | 0 | +| BN Mul Cycles | 0 | +| KZG Eval Cycles | 0 | +| EC Recover Cycles | 9,407,847 | +--------------------------------+---------------------------+ ``` diff --git a/proposer/succinct/bin/cost_estimator.rs b/proposer/succinct/bin/cost_estimator.rs index 2ec6b3af..3fef1899 100644 --- a/proposer/succinct/bin/cost_estimator.rs +++ b/proposer/succinct/bin/cost_estimator.rs @@ -252,11 +252,6 @@ fn aggregate_execution_stats(execution_stats: &[ExecutionStats]) -> ExecutionSta aggregate_stats.nb_blocks += stats.nb_blocks; aggregate_stats.nb_transactions += stats.nb_transactions; aggregate_stats.eth_gas_used += stats.eth_gas_used; - aggregate_stats.cycles_per_block += stats.cycles_per_block; - aggregate_stats.cycles_per_transaction += stats.cycles_per_transaction; - aggregate_stats.transactions_per_block += stats.transactions_per_block; - aggregate_stats.gas_used_per_block += stats.gas_used_per_block; - aggregate_stats.gas_used_per_transaction += stats.gas_used_per_transaction; aggregate_stats.bn_pair_cycles += stats.bn_pair_cycles; aggregate_stats.bn_add_cycles += stats.bn_add_cycles; aggregate_stats.bn_mul_cycles += stats.bn_mul_cycles; @@ -264,6 +259,12 @@ fn aggregate_execution_stats(execution_stats: &[ExecutionStats]) -> ExecutionSta aggregate_stats.ec_recover_cycles += stats.ec_recover_cycles; } + aggregate_stats.cycles_per_block = aggregate_stats.total_instruction_count / aggregate_stats.nb_blocks; + aggregate_stats.cycles_per_transaction = aggregate_stats.total_instruction_count / aggregate_stats.nb_transactions; + aggregate_stats.transactions_per_block = aggregate_stats.nb_transactions / aggregate_stats.nb_blocks; + aggregate_stats.gas_used_per_block = aggregate_stats.eth_gas_used / aggregate_stats.nb_blocks; + aggregate_stats.gas_used_per_transaction = aggregate_stats.eth_gas_used / aggregate_stats.nb_transactions; + aggregate_stats.batch_start = batch_start; aggregate_stats.batch_end = batch_end; @@ -300,7 +301,7 @@ async fn main() -> Result<()> { write_execution_stats_to_csv(&execution_stats, l2_chain_id, &args)?; let aggregate_execution_stats = aggregate_execution_stats(&execution_stats); - println!("Aggregate Execution Stats: {:?}", aggregate_execution_stats); + println!("Aggregate Execution Stats\n: {}", aggregate_execution_stats); Ok(()) } diff --git a/utils/host/src/stats.rs b/utils/host/src/stats.rs index 0b5d5dd4..136fc5ad 100644 --- a/utils/host/src/stats.rs +++ b/utils/host/src/stats.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; use sp1_sdk::{CostEstimator, ExecutionReport}; /// Statistics for the multi-block execution. -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize, Default)] pub struct ExecutionStats { pub batch_start: u64, pub batch_end: u64, @@ -32,35 +32,6 @@ pub struct ExecutionStats { pub ec_recover_cycles: u64, } -impl Default for ExecutionStats { - fn default() -> Self { - ExecutionStats { - batch_start: 0, - batch_end: 0, - execution_duration_sec: 0, - total_instruction_count: 0, - oracle_verify_instruction_count: 0, - derivation_instruction_count: 0, - block_execution_instruction_count: 0, - blob_verification_instruction_count: 0, - total_sp1_gas: 0, - nb_blocks: 0, - nb_transactions: 0, - eth_gas_used: 0, - cycles_per_block: 0, - cycles_per_transaction: 0, - transactions_per_block: 0, - gas_used_per_block: 0, - gas_used_per_transaction: 0, - bn_pair_cycles: 0, - bn_add_cycles: 0, - bn_mul_cycles: 0, - kzg_eval_cycles: 0, - ec_recover_cycles: 0, - } - } -} - /// Write a statistic to the formatter. fn write_stat(f: &mut fmt::Formatter<'_>, label: &str, value: u64) -> fmt::Result { writeln!(f, "| {:<30} | {:>25} |", label, value.to_formatted_string(&Locale::en)) @@ -132,8 +103,12 @@ pub async fn get_execution_stats( let kzg_eval_cycles: u64 = *report.cycle_tracker.get("precompile-kzg-eval").unwrap_or(&0); let ec_recover_cycles: u64 = *report.cycle_tracker.get("precompile-ec-recover").unwrap_or(&0); - let cycles_per_block = block_execution_instruction_count / nb_blocks; - let cycles_per_transaction = block_execution_instruction_count / nb_transactions; + let total_instruction_count = report.total_instruction_count(); + + // Cycles per block, transaction are computed with respect to the total instruction count. + let cycles_per_block = total_instruction_count / nb_blocks; + let cycles_per_transaction = total_instruction_count / nb_transactions; + let transactions_per_block = nb_transactions / nb_blocks; let gas_used_per_block = total_gas_used / nb_blocks; let gas_used_per_transaction = total_gas_used / nb_transactions; @@ -142,7 +117,7 @@ pub async fn get_execution_stats( batch_start: start, batch_end: end, execution_duration_sec: execution_duration.as_secs(), - total_instruction_count: report.total_instruction_count(), + total_instruction_count, derivation_instruction_count, oracle_verify_instruction_count, block_execution_instruction_count,