Skip to content

Saffron/benches: use get_srs_test from kimchi #3208

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 14 additions & 16 deletions saffron/benches/read_proof_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,18 @@
use ark_ff::{One, UniformRand, Zero};
use ark_poly::{univariate::DensePolynomial, Evaluations};
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
use kimchi::{circuits::domains::EvaluationDomains, groupmap::GroupMap};
use kimchi::{
circuits::domains::EvaluationDomains, groupmap::GroupMap, precomputed_srs::get_srs_test,
};
use mina_curves::pasta::{Fp, Vesta};
use once_cell::sync::Lazy;
use poly_commitment::{commitment::CommitmentCurve, ipa::SRS, SRS as _};
use poly_commitment::{commitment::CommitmentCurve, SRS as _};
use rand::rngs::OsRng;
use saffron::{
env,
read_proof::{prove, verify},
ScalarField, SRS_SIZE,
};

// Set up static resources to avoid re-computation during benchmarks
static SRS: Lazy<SRS<Vesta>> = Lazy::new(|| {
if let Ok(srs) = std::env::var("SRS_FILEPATH") {
env::get_srs_from_cache(srs)
} else {
SRS::create(SRS_SIZE)
}
});

static DOMAIN: Lazy<EvaluationDomains<ScalarField>> =
Lazy::new(|| EvaluationDomains::<ScalarField>::create(SRS_SIZE).unwrap());

Expand All @@ -37,10 +29,12 @@ fn generate_test_data(
// Generate data with specified size
let data: Vec<ScalarField> = (0..size).map(|_| Fp::rand(&mut rng)).collect();

let srs = get_srs_test();

// Create data commitment
let data_poly: DensePolynomial<ScalarField> =
Evaluations::from_vec_and_domain(data.clone(), DOMAIN.d1).interpolate();
let data_comm: Vesta = SRS.commit_non_hiding(&data_poly, 1).chunks[0];
let data_comm: Vesta = srs.commit_non_hiding(&data_poly, 1).chunks[0];

// Generate query (about 10% of positions will be queried)
let query: Vec<ScalarField> = (0..size)
Expand All @@ -62,14 +56,16 @@ fn generate_test_data(
fn bench_read_proof_prove(c: &mut Criterion) {
let (data, query, answer, data_comm) = generate_test_data(SRS_SIZE);

let srs = get_srs_test();

let description = format!("prove size {}", SRS_SIZE);
c.bench_function(description.as_str(), |b| {
b.iter_batched(
|| OsRng,
|mut rng| {
black_box(prove(
*DOMAIN,
&SRS,
&srs,
&GROUP_MAP,
&mut rng,
data.as_slice(),
Expand All @@ -86,11 +82,13 @@ fn bench_read_proof_prove(c: &mut Criterion) {
fn bench_read_proof_verify(c: &mut Criterion) {
let (data, query, answer, data_comm) = generate_test_data(SRS_SIZE);

let srs = get_srs_test();

// Create proof first
let mut rng = OsRng;
let proof = prove(
*DOMAIN,
&SRS,
&srs,
&GROUP_MAP,
&mut rng,
data.as_slice(),
Expand All @@ -105,7 +103,7 @@ fn bench_read_proof_verify(c: &mut Criterion) {
|| OsRng,
|mut rng| {
black_box(verify(
*DOMAIN, &SRS, &GROUP_MAP, &mut rng, &data_comm, &proof,
*DOMAIN, &srs, &GROUP_MAP, &mut rng, &data_comm, &proof,
))
},
BatchSize::SmallInput,
Expand Down
Loading