@@ -51,6 +51,7 @@ use proof_of_sql::{
51
51
} ,
52
52
sql:: { parse:: QueryExpr , proof:: VerifiableQueryResult } ,
53
53
} ;
54
+ use rand:: { rngs:: StdRng , SeedableRng } ;
54
55
use std:: path:: PathBuf ;
55
56
mod utils;
56
57
use utils:: {
@@ -118,7 +119,7 @@ impl Query {
118
119
#[ derive( Parser ) ]
119
120
#[ command( about, long_about = None ) ]
120
121
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`)
122
123
#[ arg( short, long, value_enum, env, default_value = "all" ) ]
123
124
scheme : CommitmentScheme ,
124
125
@@ -134,6 +135,10 @@ struct Cli {
134
135
#[ arg( short, long, value_enum, env, default_value = "all" ) ]
135
136
query : Query ,
136
137
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
+
137
142
/// Path to the Blitzar handle used for `DynamicDory`.
138
143
#[ arg( short, long, env) ]
139
144
blitzar_handle_path : Option < PathBuf > ,
@@ -145,6 +150,20 @@ struct Cli {
145
150
/// Path to the Perpetual Powers of Tau file used for `HyperKZG`.
146
151
#[ arg( short, long, env) ]
147
152
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
+ }
148
167
}
149
168
150
169
/// # Panics
@@ -156,7 +175,7 @@ struct Cli {
156
175
/// - The creation of the `VerifiableQueryResult` fails due to invalid proof expressions.
157
176
fn bench_inner_product_proof ( cli : & Cli , queries : & [ QueryEntry ] ) {
158
177
let mut accessor: BenchmarkAccessor < ' _ , RistrettoPoint > = BenchmarkAccessor :: default ( ) ;
159
- let mut rng = rand :: thread_rng ( ) ;
178
+ let mut rng = get_rng ( cli ) ;
160
179
let alloc = Bump :: new ( ) ;
161
180
162
181
for ( _title, query, columns) in queries {
@@ -182,35 +201,82 @@ fn bench_inner_product_proof(cli: &Cli, queries: &[QueryEntry]) {
182
201
///
183
202
/// Will panic if:
184
203
/// - 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:
185
242
/// - The columns generated from `generate_random_columns` lead to a failure in `insert_table`.
186
243
/// - The query string cannot be parsed into a `QueryExpr`.
187
244
/// - The creation of the `VerifiableQueryResult` fails due to invalid proof expressions.
188
245
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 ) ;
194
251
195
252
let mut accessor: BenchmarkAccessor < ' _ , DoryCommitment > = BenchmarkAccessor :: default ( ) ;
196
- let mut rng = rand :: thread_rng ( ) ;
253
+ let mut rng = get_rng ( cli ) ;
197
254
let alloc = Bump :: new ( ) ;
198
255
199
256
for ( _title, query, columns) in queries {
200
257
accessor. insert_table (
201
258
"bench.table" . parse ( ) . unwrap ( ) ,
202
259
& generate_random_columns ( & alloc, & mut rng, columns, cli. table_size ) ,
203
- & prover_setup ,
260
+ & prover_public_setup ,
204
261
) ;
205
262
let query_expr =
206
263
QueryExpr :: try_new ( query. parse ( ) . unwrap ( ) , "bench" . into ( ) , & accessor) . unwrap ( ) ;
207
264
208
265
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 ( ) ;
212
273
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
+ )
214
280
. unwrap ( ) ;
215
281
}
216
282
}
@@ -219,36 +285,16 @@ fn bench_dory(cli: &Cli, queries: &[QueryEntry]) {
219
285
/// # Panics
220
286
///
221
287
/// Will panic if:
222
- /// - The table reference cannot be parsed from the string.
223
288
/// - The columns generated from `generate_random_columns` lead to a failure in `insert_table`.
224
289
/// - The query string cannot be parsed into a `QueryExpr`.
225
290
/// - The creation of the `VerifiableQueryResult` fails due to invalid proof expressions.
226
291
/// - If the public parameters file or the Blitzar handle file path is not valid.
227
292
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) ;
249
295
250
296
let mut accessor: BenchmarkAccessor < ' _ , DynamicDoryCommitment > = BenchmarkAccessor :: default ( ) ;
251
- let mut rng = rand :: thread_rng ( ) ;
297
+ let mut rng = get_rng ( cli ) ;
252
298
let alloc = Bump :: new ( ) ;
253
299
254
300
for ( _title, query, columns) in queries {
@@ -305,7 +351,7 @@ fn bench_hyperkzg(cli: &Cli, queries: &[QueryEntry]) {
305
351
} ;
306
352
307
353
let mut accessor: BenchmarkAccessor < ' _ , HyperKZGCommitment > = BenchmarkAccessor :: default ( ) ;
308
- let mut rng = rand :: thread_rng ( ) ;
354
+ let mut rng = get_rng ( cli ) ;
309
355
let alloc = Bump :: new ( ) ;
310
356
311
357
for ( _title, query, columns) in queries {
0 commit comments