Skip to content

Commit 59a77bc

Browse files
bench: add parameters for Dory setup and random seed to Jaeger benchmarks (#698)
# Rationale for this change A number of improvements were added that originated from suggestions made in PR #668. Additional parameters to make the tests repeatable and improve speed were added along with document improvements. # What changes are included in this PR? - A parameter is added to represent `max_nu` in the Dynamic Dory setup and `sigma` in the Dory setup. - The file loading for Dynamic Dory is refactored to be used by both Dynamic Dory and Dory setups. - An optional random seed is added as a cli argument to help with reproducible benches. # Are these changes tested? Yes
2 parents e4919fe + c9d192b commit 59a77bc

File tree

1 file changed

+83
-37
lines changed

1 file changed

+83
-37
lines changed

crates/proof-of-sql/benches/jaeger/bin/jaeger_benches.rs

+83-37
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use proof_of_sql::{
5151
},
5252
sql::{parse::QueryExpr, proof::VerifiableQueryResult},
5353
};
54+
use rand::{rngs::StdRng, SeedableRng};
5455
use std::path::PathBuf;
5556
mod utils;
5657
use utils::{
@@ -118,7 +119,7 @@ impl Query {
118119
#[derive(Parser)]
119120
#[command(about, long_about = None)]
120121
struct Cli {
121-
/// Commitment scheme (e.g. `hyper-kzg`, `ipa`, `dynamic-dory`, `dory`)
122+
/// Commitment scheme (e.g. `hyper-kzg`, `inner-product-proof`, `dynamic-dory`, `dory`)
122123
#[arg(short, long, value_enum, env, default_value = "all")]
123124
scheme: CommitmentScheme,
124125

@@ -134,6 +135,10 @@ struct Cli {
134135
#[arg(short, long, value_enum, env, default_value = "all")]
135136
query: Query,
136137

138+
/// `max_nu` used in the Dynamic Dory or `sigma` used in the Dory setup (default: `11`)
139+
#[arg(short, long, env, default_value_t = 11)]
140+
nu_sigma: usize,
141+
137142
/// Path to the Blitzar handle used for `DynamicDory`.
138143
#[arg(short, long, env)]
139144
blitzar_handle_path: Option<PathBuf>,
@@ -145,6 +150,20 @@ struct Cli {
145150
/// Path to the Perpetual Powers of Tau file used for `HyperKZG`.
146151
#[arg(short, long, env)]
147152
ppot_file_path: Option<PathBuf>,
153+
154+
/// Optional random seed for deterministic random number generation.
155+
#[arg(short, long, env)]
156+
rand_seed: Option<u64>,
157+
}
158+
159+
/// Gets a random number generator based on the CLI arguments.
160+
/// If a seed is provided, uses a seeded RNG, otherwise uses `thread_rng`.
161+
fn get_rng(cli: &Cli) -> StdRng {
162+
if let Some(seed) = cli.rand_seed {
163+
StdRng::seed_from_u64(seed)
164+
} else {
165+
StdRng::from_entropy()
166+
}
148167
}
149168

150169
/// # Panics
@@ -156,7 +175,7 @@ struct Cli {
156175
/// - The creation of the `VerifiableQueryResult` fails due to invalid proof expressions.
157176
fn bench_inner_product_proof(cli: &Cli, queries: &[QueryEntry]) {
158177
let mut accessor: BenchmarkAccessor<'_, RistrettoPoint> = BenchmarkAccessor::default();
159-
let mut rng = rand::thread_rng();
178+
let mut rng = get_rng(cli);
160179
let alloc = Bump::new();
161180

162181
for (_title, query, columns) in queries {
@@ -182,35 +201,82 @@ fn bench_inner_product_proof(cli: &Cli, queries: &[QueryEntry]) {
182201
///
183202
/// Will panic if:
184203
/// - The table reference cannot be parsed from the string.
204+
fn load_dory_public_parameters(cli: &Cli) -> PublicParameters {
205+
if let Some(dory_public_params_path) = &cli.dory_public_params_path {
206+
PublicParameters::load_from_file(std::path::Path::new(&dory_public_params_path))
207+
.expect("Failed to load Dory public parameters")
208+
} else {
209+
PublicParameters::test_rand(cli.nu_sigma, &mut test_rng())
210+
}
211+
}
212+
213+
/// # Panics
214+
///
215+
/// Will panic if:
216+
/// - The table reference cannot be parsed from the string.
217+
fn load_dory_setup<'a>(
218+
public_parameters: &'a PublicParameters,
219+
cli: &'a Cli,
220+
) -> (ProverSetup<'a>, VerifierSetup) {
221+
let (prover_setup, verifier_setup) = if let Some(blitzar_handle_path) = &cli.blitzar_handle_path
222+
{
223+
let handle =
224+
blitzar::compute::MsmHandle::new_from_file(blitzar_handle_path.to_str().unwrap());
225+
let prover_setup =
226+
ProverSetup::from_public_parameters_and_blitzar_handle(public_parameters, handle);
227+
let verifier_setup = VerifierSetup::from(public_parameters);
228+
229+
(prover_setup, verifier_setup)
230+
} else {
231+
let prover_setup = ProverSetup::from(public_parameters);
232+
let verifier_setup = VerifierSetup::from(public_parameters);
233+
(prover_setup, verifier_setup)
234+
};
235+
236+
(prover_setup, verifier_setup)
237+
}
238+
239+
/// # Panics
240+
///
241+
/// Will panic if:
185242
/// - The columns generated from `generate_random_columns` lead to a failure in `insert_table`.
186243
/// - The query string cannot be parsed into a `QueryExpr`.
187244
/// - The creation of the `VerifiableQueryResult` fails due to invalid proof expressions.
188245
fn bench_dory(cli: &Cli, queries: &[QueryEntry]) {
189-
let pp = PublicParameters::test_rand(10, &mut test_rng());
190-
let ps = ProverSetup::from(&pp);
191-
let prover_setup = DoryProverPublicSetup::new(&ps, 10);
192-
let vs = VerifierSetup::from(&pp);
193-
let verifier_setup = DoryVerifierPublicSetup::new(&vs, 10);
246+
let public_parameters = load_dory_public_parameters(cli);
247+
let (prover_setup, verifier_setup) = load_dory_setup(&public_parameters, cli);
248+
249+
let prover_public_setup = DoryProverPublicSetup::new(&prover_setup, cli.nu_sigma);
250+
let verifier_public_setup = DoryVerifierPublicSetup::new(&verifier_setup, cli.nu_sigma);
194251

195252
let mut accessor: BenchmarkAccessor<'_, DoryCommitment> = BenchmarkAccessor::default();
196-
let mut rng = rand::thread_rng();
253+
let mut rng = get_rng(cli);
197254
let alloc = Bump::new();
198255

199256
for (_title, query, columns) in queries {
200257
accessor.insert_table(
201258
"bench.table".parse().unwrap(),
202259
&generate_random_columns(&alloc, &mut rng, columns, cli.table_size),
203-
&prover_setup,
260+
&prover_public_setup,
204261
);
205262
let query_expr =
206263
QueryExpr::try_new(query.parse().unwrap(), "bench".into(), &accessor).unwrap();
207264

208265
for _ in 0..cli.iterations {
209-
let result: VerifiableQueryResult<DoryEvaluationProof> =
210-
VerifiableQueryResult::new(query_expr.proof_expr(), &accessor, &prover_setup, &[])
211-
.unwrap();
266+
let result: VerifiableQueryResult<DoryEvaluationProof> = VerifiableQueryResult::new(
267+
query_expr.proof_expr(),
268+
&accessor,
269+
&prover_public_setup,
270+
&[],
271+
)
272+
.unwrap();
212273
result
213-
.verify(query_expr.proof_expr(), &accessor, &verifier_setup, &[])
274+
.verify(
275+
query_expr.proof_expr(),
276+
&accessor,
277+
&verifier_public_setup,
278+
&[],
279+
)
214280
.unwrap();
215281
}
216282
}
@@ -219,36 +285,16 @@ fn bench_dory(cli: &Cli, queries: &[QueryEntry]) {
219285
/// # Panics
220286
///
221287
/// Will panic if:
222-
/// - The table reference cannot be parsed from the string.
223288
/// - The columns generated from `generate_random_columns` lead to a failure in `insert_table`.
224289
/// - The query string cannot be parsed into a `QueryExpr`.
225290
/// - The creation of the `VerifiableQueryResult` fails due to invalid proof expressions.
226291
/// - If the public parameters file or the Blitzar handle file path is not valid.
227292
fn bench_dynamic_dory(cli: &Cli, queries: &[QueryEntry]) {
228-
let public_parameters;
229-
let (prover_setup, verifier_setup) =
230-
if let (Some(blitzar_handle_path), Some(dory_public_params_path)) =
231-
(&cli.blitzar_handle_path, &cli.dory_public_params_path)
232-
{
233-
let handle =
234-
blitzar::compute::MsmHandle::new_from_file(blitzar_handle_path.to_str().unwrap());
235-
public_parameters =
236-
PublicParameters::load_from_file(std::path::Path::new(&dory_public_params_path))
237-
.expect("Failed to load Dory public parameters");
238-
let prover_setup =
239-
ProverSetup::from_public_parameters_and_blitzar_handle(&public_parameters, handle);
240-
let verifier_setup = VerifierSetup::from(&public_parameters);
241-
242-
(prover_setup, verifier_setup)
243-
} else {
244-
public_parameters = PublicParameters::test_rand(11, &mut test_rng());
245-
let prover = ProverSetup::from(&public_parameters);
246-
let verifier = VerifierSetup::from(&public_parameters);
247-
(prover, verifier)
248-
};
293+
let public_parameters = load_dory_public_parameters(cli);
294+
let (prover_setup, verifier_setup) = load_dory_setup(&public_parameters, cli);
249295

250296
let mut accessor: BenchmarkAccessor<'_, DynamicDoryCommitment> = BenchmarkAccessor::default();
251-
let mut rng = rand::thread_rng();
297+
let mut rng = get_rng(cli);
252298
let alloc = Bump::new();
253299

254300
for (_title, query, columns) in queries {
@@ -305,7 +351,7 @@ fn bench_hyperkzg(cli: &Cli, queries: &[QueryEntry]) {
305351
};
306352

307353
let mut accessor: BenchmarkAccessor<'_, HyperKZGCommitment> = BenchmarkAccessor::default();
308-
let mut rng = rand::thread_rng();
354+
let mut rng = get_rng(cli);
309355
let alloc = Bump::new();
310356

311357
for (_title, query, columns) in queries {

0 commit comments

Comments
 (0)