@@ -11,6 +11,8 @@ use ark_std::UniformRand;
1111use core:: iter;
1212use core:: time:: Duration ;
1313use criterion:: * ;
14+ use curdleproofs:: whisk:: g1_generator;
15+ use curdleproofs:: whisk:: rand_scalar;
1416use std:: ops:: Mul ;
1517
1618use curdleproofs:: curdleproofs:: { generate_crs, CurdleproofsProof } ;
@@ -26,87 +28,107 @@ fn apply_permutation_group(vec_a: Vec<G1Affine>, permutation: &Vec<u32>) -> Vec<
2628fn benchmark_shuffle ( c : & mut Criterion ) {
2729 let mut rng = StdRng :: seed_from_u64 ( 0u64 ) ;
2830
29- let N = 512 ;
31+ let N_VALUES = [ 16 , 32 , 64 , 128 ] ;
3032 let N_BLINDERS = 4 ;
31- let ell = N - N_BLINDERS ;
32-
33- // Construct the CRS
34- let crs = generate_crs ( ell) ;
35-
36- // Get witnesses: the permutation, the randomizer, and a bunch of blinders
37- let mut permutation: Vec < u32 > = ( 0 ..ell as u32 ) . collect ( ) ;
38- permutation. shuffle ( & mut rng) ;
39- let k = Fr :: rand ( & mut rng) ;
40- let vec_r_m = generate_blinders ( & mut rng, N_BLINDERS ) ;
41-
42- // Get shuffle inputs
43- let vec_R: Vec < G1Affine > = iter:: repeat_with ( || G1Projective :: rand ( & mut rng) . into_affine ( ) )
44- . take ( ell)
45- . collect ( ) ;
46- let vec_S: Vec < G1Affine > = iter:: repeat_with ( || G1Projective :: rand ( & mut rng) . into_affine ( ) )
47- . take ( ell)
48- . collect ( ) ;
49-
50- // Derive shuffled outputs
51- c. bench_function ( "shuffling" , |b| {
52- b. iter ( || {
53- let mut vec_T: Vec < G1Affine > = vec_R. iter ( ) . map ( |R | R . mul ( k) . into_affine ( ) ) . collect ( ) ;
54- let mut vec_U: Vec < G1Affine > = vec_S. iter ( ) . map ( |S | S . mul ( k) . into_affine ( ) ) . collect ( ) ;
55- vec_T = apply_permutation_group ( vec_T, & permutation) ;
56- vec_U = apply_permutation_group ( vec_U, & permutation) ;
57- } )
58- } ) ;
59-
60- let mut vec_T: Vec < G1Affine > = vec_R. iter ( ) . map ( |R | R . mul ( k) . into_affine ( ) ) . collect ( ) ;
61- let mut vec_U: Vec < G1Affine > = vec_S. iter ( ) . map ( |S | S . mul ( k) . into_affine ( ) ) . collect ( ) ;
62- vec_T = apply_permutation_group ( vec_T, & permutation) ;
63- vec_U = apply_permutation_group ( vec_U, & permutation) ;
64-
65- let range_as_fr: Vec < Fr > = ( 0 ..ell as u32 ) . into_iter ( ) . map ( |s| Fr :: from ( s) ) . collect ( ) ;
66- let sigma_ell = get_permutation ( & range_as_fr, & permutation) ;
67- let M = msm ( & crs. vec_G , & sigma_ell) + msm ( & crs. vec_H , & vec_r_m) ;
68-
69- c. bench_function ( "prover" , |b| {
70- b. iter ( || {
71- CurdleproofsProof :: new (
72- & crs,
73- vec_R. clone ( ) ,
74- vec_S. clone ( ) ,
75- vec_T. clone ( ) ,
76- vec_U. clone ( ) ,
77- M ,
78- permutation. clone ( ) ,
79- k,
80- vec_r_m. clone ( ) ,
81- & mut rng,
82- ) ;
83- } )
84- } ) ;
85-
86- let shuffle_proof = CurdleproofsProof :: new (
87- & crs,
88- vec_R. clone ( ) ,
89- vec_S. clone ( ) ,
90- vec_T. clone ( ) ,
91- vec_U. clone ( ) ,
92- M ,
93- permutation,
94- k,
95- vec_r_m,
96- & mut rng,
97- ) ;
98-
99- c. bench_function ( "verifier" , |b| {
100- b. iter ( || {
101- assert ! ( shuffle_proof
102- . verify( & crs, & vec_R, & vec_S, & vec_T, & vec_U, & M , & mut rng)
103- . is_ok( ) ) ;
104- } )
105- } ) ;
33+
34+ for N in N_VALUES {
35+ let ell = N - N_BLINDERS ;
36+
37+ // Construct the CRS
38+ let crs = generate_crs ( ell) ;
39+
40+ // Get witnesses: the permutation, the randomizer, and a bunch of blinders
41+ let mut permutation: Vec < u32 > = ( 0 ..ell as u32 ) . collect ( ) ;
42+ permutation. shuffle ( & mut rng) ;
43+ let k = Fr :: rand ( & mut rng) ;
44+ let vec_r_m = generate_blinders ( & mut rng, N_BLINDERS ) ;
45+
46+ // Get shuffle inputs
47+ let vec_R: Vec < G1Affine > = iter:: repeat_with ( || G1Projective :: rand ( & mut rng) . into_affine ( ) )
48+ . take ( ell)
49+ . collect ( ) ;
50+ let vec_S: Vec < G1Affine > = iter:: repeat_with ( || G1Projective :: rand ( & mut rng) . into_affine ( ) )
51+ . take ( ell)
52+ . collect ( ) ;
53+
54+ // Derive shuffled outputs
55+ c. bench_function ( & format ! ( "shuffling N={}" , N ) , |b| {
56+ b. iter ( || {
57+ let mut vec_T: Vec < G1Affine > =
58+ vec_R. iter ( ) . map ( |R | R . mul ( k) . into_affine ( ) ) . collect ( ) ;
59+ let mut vec_U: Vec < G1Affine > =
60+ vec_S. iter ( ) . map ( |S | S . mul ( k) . into_affine ( ) ) . collect ( ) ;
61+ vec_T = apply_permutation_group ( vec_T, & permutation) ;
62+ vec_U = apply_permutation_group ( vec_U, & permutation) ;
63+ } )
64+ } ) ;
65+
66+ let mut vec_T: Vec < G1Affine > = vec_R. iter ( ) . map ( |R | R . mul ( k) . into_affine ( ) ) . collect ( ) ;
67+ let mut vec_U: Vec < G1Affine > = vec_S. iter ( ) . map ( |S | S . mul ( k) . into_affine ( ) ) . collect ( ) ;
68+ vec_T = apply_permutation_group ( vec_T, & permutation) ;
69+ vec_U = apply_permutation_group ( vec_U, & permutation) ;
70+
71+ let range_as_fr: Vec < Fr > = ( 0 ..ell as u32 ) . into_iter ( ) . map ( |s| Fr :: from ( s) ) . collect ( ) ;
72+ let sigma_ell = get_permutation ( & range_as_fr, & permutation) ;
73+ let M = msm ( & crs. vec_G , & sigma_ell) + msm ( & crs. vec_H , & vec_r_m) ;
74+
75+ c. bench_function ( & format ! ( "prover N={}" , N ) , |b| {
76+ b. iter ( || {
77+ CurdleproofsProof :: new (
78+ & crs,
79+ vec_R. clone ( ) ,
80+ vec_S. clone ( ) ,
81+ vec_T. clone ( ) ,
82+ vec_U. clone ( ) ,
83+ M ,
84+ permutation. clone ( ) ,
85+ k,
86+ vec_r_m. clone ( ) ,
87+ & mut rng,
88+ ) ;
89+ } )
90+ } ) ;
91+
92+ let shuffle_proof = CurdleproofsProof :: new (
93+ & crs,
94+ vec_R. clone ( ) ,
95+ vec_S. clone ( ) ,
96+ vec_T. clone ( ) ,
97+ vec_U. clone ( ) ,
98+ M ,
99+ permutation,
100+ k,
101+ vec_r_m,
102+ & mut rng,
103+ ) ;
104+
105+ c. bench_function ( & format ! ( "verifier N={}" , N ) , |b| {
106+ b. iter ( || {
107+ assert ! ( shuffle_proof
108+ . verify( & crs, & vec_R, & vec_S, & vec_T, & vec_U, & M , & mut rng)
109+ . is_ok( ) ) ;
110+ } )
111+ } ) ;
112+ }
113+
114+ // Duty discovery benchmark
115+
116+ for N in [ 1 , 100 , 10000 ] {
117+ let k = rand_scalar ( & mut rng) ;
118+ let p = g1_generator ( ) ;
119+
120+ c. bench_function ( & format ! ( "G1 point multiplication N={}" , N ) , |b| {
121+ b. iter ( || {
122+ for _ in 0 ..N {
123+ let _ = p == p. mul ( k) ;
124+ }
125+ } )
126+ } ) ;
127+ }
106128}
107129
108130criterion_group ! { name = shuffle;
109- config = Criterion :: default ( ) . measurement_time( Duration :: from_secs( 60 ) ) ;
131+ config = Criterion :: default ( ) . measurement_time( Duration :: from_secs( 30 ) ) ;
110132 targets = benchmark_shuffle
111133}
112134
0 commit comments