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(utils/client): add secp256r1 cycle tracking #324

Merged
merged 1 commit into from
Jan 14, 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
Binary file modified elf/aggregation-elf
Binary file not shown.
Binary file modified elf/range-elf
Binary file not shown.
1 change: 1 addition & 0 deletions scripts/utils/bin/cost_estimator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ fn aggregate_execution_stats(
aggregate_stats.bn_mul_cycles += stats.bn_mul_cycles;
aggregate_stats.kzg_eval_cycles += stats.kzg_eval_cycles;
aggregate_stats.ec_recover_cycles += stats.ec_recover_cycles;
aggregate_stats.p256_verify_cycles += stats.p256_verify_cycles;
}

// For statistics that are per-block or per-transaction, we take the average over the entire
Expand Down
3 changes: 3 additions & 0 deletions utils/client/src/precompiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pub(crate) const ANNOTATED_KZG_EVAL: PrecompileWithAddress = create_annotated_pr
);
pub(crate) const ANNOTATED_EC_RECOVER: PrecompileWithAddress =
create_annotated_precompile!(revm::precompile::secp256k1::ECRECOVER, "ec-recover");
pub(crate) const ANNOTATED_P256_VERIFY: PrecompileWithAddress =
create_annotated_precompile!(revm::precompile::secp256r1::P256VERIFY, "p256-verify");

// Source: https://github.com/anton-rs/kona/blob/main/bin/client/src/fault/handler/mod.rs#L20-L42
pub fn zkvm_handle_register<F, H>(handler: &mut EvmHandler<'_, (), &mut State<&mut TrieDB<F, H>>>)
Expand All @@ -68,6 +70,7 @@ where
ANNOTATED_BN_PAIR,
ANNOTATED_KZG_EVAL,
ANNOTATED_EC_RECOVER,
ANNOTATED_P256_VERIFY,
];
ctx_precompiles.extend(override_precompiles);

Expand Down
8 changes: 7 additions & 1 deletion utils/host/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub struct ExecutionStats {
pub bn_mul_cycles: u64,
pub kzg_eval_cycles: u64,
pub ec_recover_cycles: u64,
pub p256_verify_cycles: u64,
}

/// Write a statistic to the formatter.
Expand Down Expand Up @@ -101,6 +102,7 @@ impl fmt::Display for ExecutionStats {
write_stat(f, "BN Mul Cycles", self.bn_mul_cycles)?;
write_stat(f, "KZG Eval Cycles", self.kzg_eval_cycles)?;
write_stat(f, "EC Recover Cycles", self.ec_recover_cycles)?;
write_stat(f, "P256 Verify Cycles", self.p256_verify_cycles)?;
writeln!(
f,
"+--------------------------------+---------------------------+"
Expand Down Expand Up @@ -140,6 +142,7 @@ impl ExecutionStats {
bn_pair_cycles: get_cycles("precompile-bn-pair"),
kzg_eval_cycles: get_cycles("precompile-kzg-eval"),
ec_recover_cycles: get_cycles("precompile-ec-recover"),
p256_verify_cycles: get_cycles("precompile-p256-verify"),
nb_transactions,
eth_gas_used: block_data.iter().map(|b| b.gas_used).sum(),
l1_fees: block_data.iter().map(|b| b.total_l1_fees).sum(),
Expand Down Expand Up @@ -219,7 +222,8 @@ impl fmt::Display for MarkdownExecutionStats {
write_stat(f, "BN Add Cycles", self.0.bn_add_cycles)?;
write_stat(f, "BN Mul Cycles", self.0.bn_mul_cycles)?;
write_stat(f, "KZG Eval Cycles", self.0.kzg_eval_cycles)?;
write_stat(f, "EC Recover Cycles", self.0.ec_recover_cycles)
write_stat(f, "EC Recover Cycles", self.0.ec_recover_cycles)?;
write_stat(f, "P256 Verify Cycles", self.0.p256_verify_cycles)
}
}

Expand All @@ -244,6 +248,7 @@ pub struct SpanBatchStats {
pub bn_pair_cycles: u64,
pub kzg_eval_cycles: u64,
pub ec_recover_cycles: u64,
pub p256_verify_cycles: u64,
}

impl fmt::Display for SpanBatchStats {
Expand Down Expand Up @@ -280,6 +285,7 @@ impl fmt::Display for SpanBatchStats {
write_stat(f, "BN Pair Cycles", self.bn_pair_cycles)?;
write_stat(f, "KZG Eval Cycles", self.kzg_eval_cycles)?;
write_stat(f, "EC Recover Cycles", self.ec_recover_cycles)?;
write_stat(f, "P256 Verify Cycles", self.p256_verify_cycles)?;
writeln!(
f,
"+-------------------------------+---------------------------+"
Expand Down
Loading