1+ use ark_ff:: Field ;
12use ark_std:: rand:: { rngs:: StdRng , SeedableRng } ;
23use criterion:: { black_box, criterion_group, criterion_main, Criterion } ;
34use polynomial_proving:: {
@@ -10,6 +11,47 @@ use util::{
1011 CODE_RATE ,
1112} ;
1213
14+ #[ cfg( feature = "rayon" ) ]
15+ const PARALLEL : & str = "(parallel)" ;
16+ #[ cfg( not( feature = "rayon" ) ) ]
17+ const PARALLEL : & str = "(single thread)" ;
18+
19+ trait FieldName {
20+ const FIELD_NAME : & str ;
21+ }
22+
23+ impl FieldName for sqisign:: level_i:: Fp2251 {
24+ const FIELD_NAME : & str = "5·2²⁴⁸-1 (SQIsign I)" ;
25+ }
26+ impl FieldName for sqisign:: level_iii:: Fp2383 {
27+ const FIELD_NAME : & str = "65·2³⁷⁶-1 (SQIsign III)" ;
28+ }
29+ impl FieldName for sqisign:: level_v:: Fp2505 {
30+ const FIELD_NAME : & str = "27·2⁵⁰⁰-1 (SQIsign V)" ;
31+ }
32+ impl FieldName for p434:: Fp2434 {
33+ const FIELD_NAME : & str = "2²¹⁶·3¹³⁷-1 (p434)" ;
34+ }
35+ impl FieldName for p503:: Fp2503 {
36+ const FIELD_NAME : & str = "2²⁵⁰·3¹⁵⁹-1 (p503)" ;
37+ }
38+ impl FieldName for p610:: Fp2610 {
39+ const FIELD_NAME : & str = "2³⁰⁵·3¹⁹²-1 (p610)" ;
40+ }
41+ impl FieldName for p751:: Fp2751 {
42+ const FIELD_NAME : & str = "2³⁷²·3²³⁹-1 (p751)" ;
43+ }
44+
45+ trait PublicKeyName {
46+ const NAME : & str ;
47+ }
48+ impl < F : Field > PublicKeyName for RadicalPublicKey < F > {
49+ const NAME : & str = "pk=(A, C)" ;
50+ }
51+ impl < F : Field > PublicKeyName for JInvariantPublicKey < F > {
52+ const NAME : & str = "pk=j" ;
53+ }
54+
1355fn test_prove_verify <
1456 const VARIABLE_COUNT : usize ,
1557 const PATH_LENGTH : usize ,
@@ -22,19 +64,27 @@ fn test_prove_verify<
2264 const COMMITMENT_SIZE : usize ,
2365 const Q_VARIABLE_COUNT : usize ,
2466 const FINAL_ROUND_EVALUATIONS : usize ,
25- F : FftField ,
26- PK : PublicKey < F > ,
67+ F : FftField + FieldName ,
68+ PK : PublicKey < F > + PublicKeyName ,
2769> (
2870 c : & mut Criterion ,
29- name : & str ,
3071) {
3172 // Generate the public and private key
3273 let compressed_private_key =
3374 CompressedPrivateKey :: < PATH_LENGTH_DIV_64 > :: rand ( StdRng :: from_entropy ( ) ) ;
3475 let ( public_key, private_key) = expand_keys ( & compressed_private_key) ;
3576 assert ! ( private_key. check( & public_key) ) ;
3677
37- let keygen_id = format ! ( "{name}: keygen ({} bits security)" , SECURITY_BITS ) ;
78+ let id_for_function = |func| format ! (
79+ "{}, e={}, λ={}, {}, {}: {func}" ,
80+ F :: FIELD_NAME ,
81+ PATH_LENGTH ,
82+ SECURITY_BITS ,
83+ PK :: NAME ,
84+ PARALLEL
85+ ) ;
86+
87+ let keygen_id = id_for_function ( "keygen" ) ;
3888 c. bench_function ( & keygen_id, |b| {
3989 b. iter ( || {
4090 let compressed_private_key =
@@ -49,10 +99,10 @@ fn test_prove_verify<
4999 SECURITY_BITS / CODE_RATE ,
50100 ) ;
51101
52- let proof_id = format ! ( "{name}: prove ({} bits security)" , SECURITY_BITS ) ;
53- let verify_id = format ! ( "{name}: verify ({} bits security)" , SECURITY_BITS ) ;
102+ let prove_id = id_for_function ( " prove" ) ;
103+ let verify_id = id_for_function ( " verify" ) ;
54104
55- c. bench_function ( & proof_id , |b| {
105+ c. bench_function ( & prove_id , |b| {
56106 b. iter ( || {
57107 prove :: <
58108 VARIABLE_COUNT ,
@@ -140,7 +190,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
140190 { CFG_SQISIGN_I . final_round_evaluations ( ) } ,
141191 sqisign:: level_i:: Fp2251 ,
142192 RadicalPublicKey < _ > ,
143- > ( c, "Fp2251 (SQISign I) (Radical Public Key)" ) ;
193+ > ( c) ;
144194 test_prove_verify :: <
145195 { CFG_SQISIGN_I . variable_count ( ) } ,
146196 { CFG_SQISIGN_I . path_length ( ) } ,
@@ -155,7 +205,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
155205 { CFG_SQISIGN_I . final_round_evaluations ( ) } ,
156206 sqisign:: level_i:: Fp2251 ,
157207 JInvariantPublicKey < _ > ,
158- > ( c, "Fp2251 (SQISign I) (J-invariant Public Key)" ) ;
208+ > ( c) ;
159209 }
160210 {
161211 const CFG_SQISIGN_III : RunForParamsConfig = RunForParamsConfig {
@@ -177,7 +227,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
177227 { CFG_SQISIGN_III . final_round_evaluations ( ) } ,
178228 sqisign:: level_iii:: Fp2383 ,
179229 RadicalPublicKey < _ > ,
180- > ( c, "Fp2383 (SQISign III) (Radical Public Key)" ) ;
230+ > ( c) ;
181231 test_prove_verify :: <
182232 { CFG_SQISIGN_III . variable_count ( ) } ,
183233 { CFG_SQISIGN_III . path_length ( ) } ,
@@ -192,7 +242,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
192242 { CFG_SQISIGN_III . final_round_evaluations ( ) } ,
193243 sqisign:: level_iii:: Fp2383 ,
194244 JInvariantPublicKey < _ > ,
195- > ( c, "Fp2383 (SQISign III) (J-invariant Public Key)" ) ;
245+ > ( c) ;
196246 }
197247 {
198248 const CFG_SQISIGN_V : RunForParamsConfig = RunForParamsConfig {
@@ -214,7 +264,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
214264 { CFG_SQISIGN_V . final_round_evaluations ( ) } ,
215265 sqisign:: level_v:: Fp2505 ,
216266 RadicalPublicKey < _ > ,
217- > ( c, "Fp2505 (SQISign V) (Radical Public Key)" ) ;
267+ > ( c) ;
218268 test_prove_verify :: <
219269 { CFG_SQISIGN_V . variable_count ( ) } ,
220270 { CFG_SQISIGN_V . path_length ( ) } ,
@@ -229,7 +279,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
229279 { CFG_SQISIGN_V . final_round_evaluations ( ) } ,
230280 sqisign:: level_v:: Fp2505 ,
231281 JInvariantPublicKey < _ > ,
232- > ( c, "Fp2505 (SQISign V) (J-invariant Public Key)" ) ;
282+ > ( c) ;
233283 }
234284 {
235285 const CFG_P434 : RunForParamsConfig = RunForParamsConfig {
@@ -251,7 +301,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
251301 { CFG_P434 . final_round_evaluations ( ) } ,
252302 p434:: Fp2434 ,
253303 RadicalPublicKey < _ > ,
254- > ( c, "Fp2434 (path length 1024, λ=128) (Radical Public Key)" ) ;
304+ > ( c) ;
255305 test_prove_verify :: <
256306 { CFG_P434 . variable_count ( ) } ,
257307 { CFG_P434 . path_length ( ) } ,
@@ -266,10 +316,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
266316 { CFG_P434 . final_round_evaluations ( ) } ,
267317 p434:: Fp2434 ,
268318 JInvariantPublicKey < _ > ,
269- > (
270- c,
271- "Fp2434 (path length 1024, λ=128) (J-Invariant Public Key)" ,
272- ) ;
319+ > ( c) ;
273320 }
274321 {
275322 const CFG_P503 : RunForParamsConfig = RunForParamsConfig {
@@ -291,7 +338,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
291338 { CFG_P503 . final_round_evaluations ( ) } ,
292339 p503:: Fp2503 ,
293340 RadicalPublicKey < _ > ,
294- > ( c, "Fp2503 (path length 1024, λ=128) (Radical Public Key)" ) ;
341+ > ( c) ;
295342 test_prove_verify :: <
296343 { CFG_P503 . variable_count ( ) } ,
297344 { CFG_P503 . path_length ( ) } ,
@@ -306,10 +353,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
306353 { CFG_P503 . final_round_evaluations ( ) } ,
307354 p503:: Fp2503 ,
308355 JInvariantPublicKey < _ > ,
309- > (
310- c,
311- "Fp2503 (path length 1024, λ=128) (J-Invariant Public Key)" ,
312- ) ;
356+ > ( c) ;
313357 }
314358 {
315359 const CFG_P610 : RunForParamsConfig = RunForParamsConfig {
@@ -331,7 +375,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
331375 { CFG_P610 . final_round_evaluations ( ) } ,
332376 p610:: Fp2610 ,
333377 RadicalPublicKey < _ > ,
334- > ( c, "Fp2610 (path length 1024, λ=192) (Radical Public Key)" ) ;
378+ > ( c) ;
335379 test_prove_verify :: <
336380 { CFG_P610 . variable_count ( ) } ,
337381 { CFG_P610 . path_length ( ) } ,
@@ -346,10 +390,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
346390 { CFG_P610 . final_round_evaluations ( ) } ,
347391 p610:: Fp2610 ,
348392 JInvariantPublicKey < _ > ,
349- > (
350- c,
351- "Fp2610 (path length 1024, λ=192) (J-Invariant Public Key)" ,
352- ) ;
393+ > ( c) ;
353394 }
354395 {
355396 const CFG_P751 : RunForParamsConfig = RunForParamsConfig {
@@ -371,7 +412,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
371412 { CFG_P751 . final_round_evaluations ( ) } ,
372413 p751:: Fp2751 ,
373414 RadicalPublicKey < _ > ,
374- > ( c, "Fp2751 (path length 2048, λ=256) (Radical Public Key)" ) ;
415+ > ( c) ;
375416 test_prove_verify :: <
376417 { CFG_P751 . variable_count ( ) } ,
377418 { CFG_P751 . path_length ( ) } ,
@@ -386,10 +427,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
386427 { CFG_P751 . final_round_evaluations ( ) } ,
387428 p751:: Fp2751 ,
388429 JInvariantPublicKey < _ > ,
389- > (
390- c,
391- "Fp2751 (path length 2048, λ=256) (J-Invariant Public Key)" ,
392- ) ;
430+ > ( c) ;
393431 }
394432}
395433
0 commit comments