Skip to content

Commit

Permalink
Merge pull request #61 from 0xPolygonZero/proof_timing
Browse files Browse the repository at this point in the history
Now logs time to generate proofs
  • Loading branch information
BGluth authored Apr 19, 2024
2 parents d1535f0 + 17535a9 commit ae915a2
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
4 changes: 4 additions & 0 deletions zero_bin/Cargo.lock

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

2 changes: 2 additions & 0 deletions zero_bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ serde_json = "1.0.107"
ethereum-types = "0.14.1"
thiserror = "1.0.50"
futures = "0.3.29"
rlp = "0.5.2"
keccak-hash = "0.10.0"

# zk-evm dependencies
plonky2 = "0.2.0"
Expand Down
4 changes: 4 additions & 0 deletions zero_bin/ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ serde = { workspace = true }
evm_arithmetization = { workspace = true, optional = true}
proof_gen = { workspace = true }
trace_decoder = { workspace = true }
tracing = { workspace = true }
rlp = { workspace = true }
ethereum-types = { workspace = true }
keccak-hash = { workspace = true }

common = { path = "../common" }

Expand Down
63 changes: 58 additions & 5 deletions zero_bin/ops/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::time::Instant;

use common::prover_state::p_state;
use keccak_hash::keccak;
use paladin::{
operation::{FatalError, FatalStrategy, Monoid, Operation, Result},
registry, RemoteExecute,
Expand All @@ -9,21 +12,47 @@ use proof_gen::{
};
use serde::{Deserialize, Serialize};
use trace_decoder::types::TxnProofGenIR;
use tracing::{event, info_span, Level};

registry!();

#[derive(Deserialize, Serialize, RemoteExecute)]
pub struct TxProof;

fn run_and_wrap_txn_proof_in_elapsed_span<F, O>(f: F, ident: String) -> Result<O>
where
F: Fn() -> Result<O>,
{
let _span = info_span!("proof generation", ident).entered();
let start = Instant::now();

let proof = f()?;

event!(
Level::INFO,
"txn proof {:.4} took {:?}",
ident,
start.elapsed()
);
Ok(proof)
}

#[cfg(not(feature = "test_only"))]
impl Operation for TxProof {
type Input = TxnProofGenIR;
type Output = proof_gen::proof_types::AggregatableProof;

fn execute(&self, input: Self::Input) -> Result<Self::Output> {
let proof = common::prover_state::p_manager()
.generate_txn_proof(input)
.map_err(|err| FatalError::from_anyhow(err, FatalStrategy::Terminate))?;
let txn_ident = Self::txn_ident(&input);

let proof = run_and_wrap_txn_proof_in_elapsed_span(
|| {
common::prover_state::p_manager()
.generate_txn_proof(input.clone())
.map_err(|err| FatalError::from_anyhow(err, FatalStrategy::Terminate).into())
},
txn_ident,
)?;

Ok(proof.into())
}
Expand All @@ -35,13 +64,37 @@ impl Operation for TxProof {
type Output = ();

fn execute(&self, input: Self::Input) -> Result<Self::Output> {
evm_arithmetization::prover::testing::simulate_execution::<proof_gen::types::Field>(input)
.map_err(|err| FatalError::from_anyhow(err, FatalStrategy::Terminate))?;
let txn_ident = Self::txn_ident(&input);

run_and_wrap_txn_proof_in_elapsed_span(
|| {
evm_arithmetization::prover::testing::simulate_execution::<proof_gen::types::Field>(
input.clone(),
)
.map_err(|err| FatalError::from_anyhow(err, FatalStrategy::Terminate).into())
},
txn_ident,
)?;

Ok(())
}
}

impl TxProof {
fn txn_ident(ir: &TxnProofGenIR) -> String {
let txn_hash_str = ir
.signed_txn
.as_ref()
.map(|txn| format!("{:x}", keccak(txn)))
.unwrap_or_else(|| "Dummy".to_string());

format!(
"b{} - {} ({})",
ir.block_metadata.block_number, ir.txn_number_before, txn_hash_str
)
}
}

#[derive(Deserialize, Serialize, RemoteExecute)]
pub struct AggProof;

Expand Down

0 comments on commit ae915a2

Please sign in to comment.