Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion benchmark-risc0-cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ echo
echo "📊 Benchmark results saved to:"
echo " target/criterion/index.html"
echo
echo "✅ Benchmark complete!"
echo "✅ Benchmark complete!"
4 changes: 2 additions & 2 deletions benchmark-risc0-cuda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ else
fi

# Set environment variables for optimal RISC0 performance
export RUST_LOG=info
export RUST_LOG=warn
export RISC0_PROVER=local # Use local prover
export RISC0_GPU_SPLIT_FACTOR=1 # Use single GPU if available

Expand All @@ -41,4 +41,4 @@ echo
echo "📊 Benchmark results saved to:"
echo " target/criterion/index.html"
echo
echo "✅ Benchmark complete!"
echo "✅ Benchmark complete!"
2 changes: 1 addition & 1 deletion benchmark-sp1-cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ echo
echo "📊 Benchmark results saved to:"
echo " target/criterion/index.html"
echo
echo "✅ Benchmark complete!"
echo "✅ Benchmark complete!"
2 changes: 1 addition & 1 deletion benchmark-sp1-cuda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ echo
# Set environment variables for SP1 CUDA proving
export SP1_PROVER=cuda
export CUDA_VISIBLE_DEVICES=0
export RUST_LOG=info
export RUST_LOG=warn
export SP1_CUDA=1
export RUSTFLAGS="-C target-cpu=native -C target-feature=+avx2"

Expand Down
1 change: 1 addition & 0 deletions crates/core/src/code.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2025 Irreducible Inc.

//! Encoding related stuff.

use bitvec::prelude::*;
Expand Down
43 changes: 11 additions & 32 deletions crates/risc0/host/benches/xmss_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use methods::{XMSS_AGGREGATE_ELF, XMSS_AGGREGATE_ID};
use risc0_zkvm::{
ExecutorEnv, ExecutorImpl, ProverOpts, Session, VerifierContext, get_prover_server,
};
use std::time::{Duration, Instant};

/// Configuration parameters for benchmarking
struct BenchmarkConfig {
Expand Down Expand Up @@ -78,35 +77,15 @@ impl Job {
}

/// Execute witness generation phase
fn exec_compute(&self) -> (Session, Duration) {
fn exec_compute(&self) -> Session {
let env = ExecutorEnv::builder()
.write(&self.test_data)
.unwrap()
.build()
.unwrap();

let mut exec = ExecutorImpl::from_elf(env, &self.elf).unwrap();
let start = Instant::now();
let session = exec.run().unwrap();
let elapsed = start.elapsed();

(session, elapsed)
}

/// Execute proving phase
fn prove_session(
&self,
session: &Session,
prover_opts: ProverOpts,
) -> (risc0_zkvm::Receipt, Duration) {
let prover = get_prover_server(&prover_opts).unwrap();
let ctx = VerifierContext::default();

let start = Instant::now();
let receipt = prover.prove_session(&ctx, session).unwrap().receipt;
let elapsed = start.elapsed();

(receipt, elapsed)
exec.run().unwrap()
}
}

Expand All @@ -132,24 +111,25 @@ fn xmss_benchmarks(c: &mut Criterion) {
);
println!("════════════════════════════════════════════════\n");

let mut group = c.benchmark_group("xmss_signature");
// Setup prover and verifier context once for all benchmarks
let prover = get_prover_server(&ProverOpts::succinct()).unwrap();
let ctx = VerifierContext::default();

// Configure the benchmark group
group.sample_size(10);
group.measurement_time(Duration::from_secs(10));
let mut group = c.benchmark_group("xmss_signature");
group.sample_size(100);

let job = Job::new(config);

// Benchmark 1: Witness Generation
group.bench_function("witness_generation", |b| {
b.iter(|| {
let (session, _duration) = job.exec_compute();
let session = job.exec_compute();
black_box(session);
});
});

// Pre-compute session for proving/verification benchmarks
let (session, _) = job.exec_compute();
let session = job.exec_compute();

// Reset group configuration for proof generation
group.finish();
Expand All @@ -161,20 +141,19 @@ fn xmss_benchmarks(c: &mut Criterion) {
// Benchmark 2: Proof Generation (Succinct only)
group.bench_function("proof_generation", |b| {
b.iter(|| {
let (receipt, _duration) = job.prove_session(&session, ProverOpts::succinct());
let receipt = prover.prove_session(&ctx, &session).unwrap().receipt;
black_box(receipt);
});
});

// Generate succinct receipt for verification benchmark
let (receipt, _) = job.prove_session(&session, ProverOpts::succinct());
let receipt = prover.prove_session(&ctx, &session).unwrap().receipt;

group.finish();

// Create new group for verification benchmarks
let mut group = c.benchmark_group("xmss_signature_verification");
group.sample_size(100); // Many samples for quick operation
group.measurement_time(Duration::from_secs(5));

group.bench_function("proof_verification", |b| {
b.iter(|| {
Expand Down
55 changes: 16 additions & 39 deletions crates/sp1/host/benches/xmss_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use leansig_core::spec::{Spec, SPEC_1, SPEC_2};
use leansig_shared::{create_test_data, XmssTestData};
use sp1_sdk::{ProverClient, SP1ProofWithPublicValues, SP1Stdin};
use std::time::{Duration, Instant};
use sp1_sdk::{ProverClient, SP1Stdin};

const ELF: &[u8] = include_bytes!(
"../../../../target/elf-compilation/riscv32im-succinct-zkvm-elf/release/sp1-guest"
Expand Down Expand Up @@ -75,27 +74,11 @@ impl Job {
}

/// Execute witness generation phase (SP1 setup + stdin preparation)
fn exec_compute(&self) -> (SP1Stdin, Duration) {
let start = Instant::now();

fn exec_compute(&self) -> SP1Stdin {
let mut stdin = SP1Stdin::new();
stdin.write(&self.test_data);

let elapsed = start.elapsed();

(stdin, elapsed)
}

/// Execute proving phase
fn prove_stdin(&self, stdin: &SP1Stdin) -> (SP1ProofWithPublicValues, Duration) {
let client = ProverClient::from_env();
let (pk, _vk) = client.setup(ELF);

let start = Instant::now();
let proof = client.prove(&pk, stdin).run().unwrap();
let elapsed = start.elapsed();

(proof, elapsed)
stdin
}
}

Expand All @@ -121,60 +104,54 @@ fn xmss_benchmarks(c: &mut Criterion) {
);
println!("════════════════════════════════════════════════\n");

// Setup client and keys once for all benchmarks
let client = ProverClient::from_env();
let (pk, vk) = client.setup(ELF);

let mut group = c.benchmark_group("sp1_xmss_signature");

// Configure the benchmark group
group.sample_size(10);
group.measurement_time(Duration::from_secs(10));
group.sample_size(100);

let job = Job::new(config);

// Benchmark 1: Witness Generation (setup + stdin preparation)
group.bench_function("witness_generation", |b| {
b.iter(|| {
let (stdin, _duration) = job.exec_compute();
let stdin = job.exec_compute();
black_box(stdin);
});
});

// Pre-compute stdin for proving/verification benchmarks
let (stdin, _) = job.exec_compute();

// Reset group configuration for proof generation
group.finish();

// Create new group for proof generation benchmarks
let mut group = c.benchmark_group("sp1_xmss_signature_proving");
group.sample_size(10);

// Pre-compute stdin once - it gets cloned internally by SP1, not consumed
let mut stdin = SP1Stdin::new();
stdin.write(&job.test_data);

// Benchmark 2: Proof Generation
group.bench_function("proof_generation", |b| {
b.iter(|| {
// We need to recreate stdin for each iteration since it gets consumed
let mut fresh_stdin = SP1Stdin::new();
fresh_stdin.write(&job.test_data);

let (proof, _duration) = job.prove_stdin(&fresh_stdin);
let proof = client.prove(&pk, &stdin).run().unwrap();
black_box(proof);
});
});

// Generate proof for verification benchmark
let mut fresh_stdin = SP1Stdin::new();
fresh_stdin.write(&job.test_data);
let (proof, _) = job.prove_stdin(&fresh_stdin);
// Generate proof for verification benchmark (reuse the same stdin)
let proof = client.prove(&pk, &stdin).run().unwrap();

group.finish();

// Create new group for verification benchmarks
let mut group = c.benchmark_group("sp1_xmss_signature_verification");
group.sample_size(100); // Many samples for quick operation
group.measurement_time(Duration::from_secs(5));

group.bench_function("proof_verification", |b| {
let client = ProverClient::from_env();
let (_pk, vk) = client.setup(ELF);

b.iter(|| {
client.verify(&proof, &vk).unwrap();
});
Expand Down