Print full stats for PPE bench

This commit is contained in:
agureev 2026-06-16 21:31:33 +04:00
parent 7b099395d6
commit 28bfaa51d0
3 changed files with 39 additions and 19 deletions

View File

@ -6,7 +6,7 @@ use lee_core::{
account::AccountWithMetadata,
program::{ChainedCall, InstructionData, ProgramId, ProgramOutput},
};
use risc0_zkvm::{ExecutorEnv, InnerReceipt, ProverOpts, Receipt, default_prover};
use risc0_zkvm::{ExecutorEnv, InnerReceipt, ProverOpts, Receipt, SessionStats, default_prover};
use crate::{
error::{InvalidProgramBehaviorError, LeeError},
@ -70,7 +70,7 @@ pub fn execute_and_prove(
account_identities: Vec<InputAccountIdentity>,
program_with_dependencies: &ProgramWithDependencies,
) -> Result<(PrivacyPreservingCircuitOutput, Proof), LeeError> {
let (output, proof, _cycles) = execute_and_prove_with_cycles(
let (output, proof, _stats) = execute_and_prove_with_stats(
pre_states,
instruction_data,
account_identities,
@ -79,14 +79,14 @@ pub fn execute_and_prove(
Ok((output, proof))
}
/// Generates a proof and cycle count for the execution of a LEE program inside the privacy
/// Generates a proof and stats for the execution of a LEE program inside the privacy
/// preserving execution circuit.
pub fn execute_and_prove_with_cycles(
pub fn execute_and_prove_with_stats(
pre_states: Vec<AccountWithMetadata>,
instruction_data: InstructionData,
account_identities: Vec<InputAccountIdentity>,
program_with_dependencies: &ProgramWithDependencies,
) -> Result<(PrivacyPreservingCircuitOutput, Proof, u64), LeeError> {
) -> Result<(PrivacyPreservingCircuitOutput, Proof, SessionStats), LeeError> {
let ProgramWithDependencies {
program: initial_program,
dependencies,
@ -162,7 +162,7 @@ pub fn execute_and_prove_with_cycles(
.decode()
.map_err(|e| LeeError::CircuitOutputDeserializationError(e.to_string()))?;
Ok((circuit_output, proof, prove_info.stats.user_cycles))
Ok((circuit_output, proof, prove_info.stats))
}
fn execute_and_prove_program(

View File

@ -29,6 +29,10 @@ pub struct PpeBenchResult {
pub prove_wall_ms: Option<f64>,
/// Executor `user_cycles` of the privacy circuit.
pub user_cycles: Option<u64>,
/// `total_cycles` including padding.
pub total_cycles: Option<u64>,
/// Number of segments.
pub segments: Option<usize>,
/// borsh-serialized `InnerReceipt` length (`S_agg` in the fee model).
pub proof_bytes: Option<usize>,
pub error: Option<String>,
@ -66,16 +70,18 @@ pub fn print_table(results: &[PpeBenchResult]) {
.max("label".len());
println!(
"\n{:<lw$} {:>5} {:>20} {:>12} {:>12} {}",
"\n{:<lw$} {:>5} {:>20} {:>12} {:>12} {:>8} {:>12} {}",
"label",
"depth",
"prove_ms (s)",
"user_cycles",
"total_cycles",
"segments",
"proof_bytes",
"error",
lw = lw,
);
println!("{}", "-".repeat(lw + 72));
println!("{}", "-".repeat(lw + 92));
for r in results {
let p = r.prove_wall_ms.map_or_else(
|| "-".to_owned(),
@ -84,16 +90,22 @@ pub fn print_table(results: &[PpeBenchResult]) {
let c = r
.user_cycles
.map_or_else(|| "-".to_owned(), |n| n.to_string());
let tc = r
.total_cycles
.map_or_else(|| "-".to_owned(), |n| n.to_string());
let s = r.segments.map_or_else(|| "-".to_owned(), |n| n.to_string());
let b = r
.proof_bytes
.map_or_else(|| "-".to_owned(), |n| n.to_string());
let e = r.error.as_deref().unwrap_or("");
println!(
"{:<lw$} {:>5} {:>20} {:>12} {:>12} {}",
"{:<lw$} {:>5} {:>20} {:>12} {:>12} {:>8} {:>12} {}",
r.label,
r.chain_depth,
p,
c,
tc,
s,
b,
e,
lw = lw,

View File

@ -7,7 +7,7 @@ use std::{collections::HashMap, time::Instant};
use lee::{
privacy_preserving_transaction::circuit::{
ProgramWithDependencies, Proof, execute_and_prove_with_cycles,
ProgramWithDependencies, Proof, execute_and_prove_with_stats,
},
program::Program,
};
@ -17,7 +17,7 @@ use lee_core::{
account::{Account, AccountId, AccountWithMetadata},
program::ProgramId,
};
use risc0_zkvm::serde::to_vec;
use risc0_zkvm::{SessionStats, serde::to_vec};
use super::PpeBenchResult;
@ -37,14 +37,16 @@ pub fn run_auth_transfer_in_ppe(private: bool) -> PpeBenchResult {
};
let started = Instant::now();
match prove_auth_transfer_in_ppe(private) {
Ok((_out, proof, user_cycles)) => {
Ok((_out, proof, stats)) => {
let prove_ms = started.elapsed().as_secs_f64() * 1_000.0;
PpeBenchResult {
label,
chain_depth: 0,
prove_wall_ms: Some(prove_ms),
proof_bytes: Some(proof.into_inner().len()),
user_cycles: Some(user_cycles),
user_cycles: Some(stats.user_cycles),
total_cycles: Some(stats.total_cycles),
segments: Some(stats.segments),
error: None,
}
}
@ -54,6 +56,8 @@ pub fn run_auth_transfer_in_ppe(private: bool) -> PpeBenchResult {
prove_wall_ms: None,
proof_bytes: None,
user_cycles: None,
total_cycles: None,
segments: None,
error: Some(err.to_string()),
},
}
@ -63,7 +67,7 @@ pub fn run_auth_transfer_in_ppe(private: bool) -> PpeBenchResult {
/// `private` flag signals whether the receiver is a private account.
pub fn prove_auth_transfer_in_ppe(
private: bool,
) -> anyhow::Result<(PrivacyPreservingCircuitOutput, Proof, u64)> {
) -> anyhow::Result<(PrivacyPreservingCircuitOutput, Proof, SessionStats)> {
let pwd = ProgramWithDependencies::from(Program::new(AUTH_TRANSFER_ELF.to_vec())?);
// Sender must already be claimed by auth_transfer for its balance to be debited.
@ -104,7 +108,7 @@ pub fn prove_auth_transfer_in_ppe(
(recipient, InputAccountIdentity::Public)
};
Ok(execute_and_prove_with_cycles(
Ok(execute_and_prove_with_stats(
vec![sender, recipient],
instruction_data,
vec![InputAccountIdentity::Public, recipient_identity],
@ -116,14 +120,16 @@ pub fn run_chain_caller(depth: u32) -> PpeBenchResult {
let label = format!("chain_caller depth={depth}");
let started = Instant::now();
match prove_chain_caller(depth) {
Ok((_out, proof, user_cycles)) => {
Ok((_out, proof, stats)) => {
let prove_ms = started.elapsed().as_secs_f64() * 1_000.0;
PpeBenchResult {
label,
chain_depth: depth as usize,
prove_wall_ms: Some(prove_ms),
proof_bytes: Some(proof.into_inner().len()),
user_cycles: Some(user_cycles),
user_cycles: Some(stats.user_cycles),
total_cycles: Some(stats.total_cycles),
segments: Some(stats.segments),
error: None,
}
}
@ -133,6 +139,8 @@ pub fn run_chain_caller(depth: u32) -> PpeBenchResult {
prove_wall_ms: None,
proof_bytes: None,
user_cycles: None,
total_cycles: None,
segments: None,
error: Some(err.to_string()),
},
}
@ -140,7 +148,7 @@ pub fn run_chain_caller(depth: u32) -> PpeBenchResult {
fn prove_chain_caller(
num_chain_calls: u32,
) -> anyhow::Result<(PrivacyPreservingCircuitOutput, Proof, u64)> {
) -> anyhow::Result<(PrivacyPreservingCircuitOutput, Proof, SessionStats)> {
let chain_caller = Program::new(CHAIN_CALLER_ELF.to_vec())?;
let auth_transfer = Program::new(AUTH_TRANSFER_ELF.to_vec())?;
let mut deps = HashMap::new();
@ -177,7 +185,7 @@ fn prove_chain_caller(
let account_identities = vec![InputAccountIdentity::Public; pre_states.len()];
Ok(execute_and_prove_with_cycles(
Ok(execute_and_prove_with_stats(
pre_states,
instruction_data,
account_identities,