File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -157,12 +157,14 @@ where
157
157
. map ( |( secret_key, message) | * message * secret_key)
158
158
. collect ( ) ;
159
159
160
- for i in 1 ..=two_pow_max {
161
- let num_points = 2_usize . pow ( i) ;
162
- let messages = & messages[ ..num_points] ;
163
- let keys = & public_keys[ ..num_points] ;
160
+ for i in 0 ..=two_pow_max {
161
+ let n = 2_usize . pow ( i) ; // the number of pairings on the left hand side
162
+ let k = n + 1 ; // the number of pairings in total
163
+ let messages: & [ ark_ec:: short_weierstrass:: Affine < ark_bls12_381:: g2:: Config > ] =
164
+ & messages[ ..n] ;
165
+ let keys = & public_keys[ ..n] ;
164
166
let aggregated_signature: G2Affine =
165
- signatures[ ..num_points ] . iter ( ) . sum :: < G2Projective > ( ) . into ( ) ;
167
+ signatures[ ..n ] . iter ( ) . sum :: < G2Projective > ( ) . into ( ) ;
166
168
167
169
let serialized_pubkeys: Vec < u8 > = keys
168
170
. iter ( )
@@ -187,7 +189,7 @@ where
187
189
. serialize_compressed ( & mut serialized_signature[ ..] )
188
190
. unwrap ( ) ;
189
191
190
- group. bench_function ( format ! ( "bls12_381_pairing_equality_{num_points }" ) , |b| {
192
+ group. bench_function ( format ! ( "bls12_381_pairing_equality_k={k }" ) , |b| {
191
193
b. iter ( || {
192
194
let is_valid = black_box ( bls12_381_pairing_equality (
193
195
& serialized_pubkeys,
Original file line number Diff line number Diff line change @@ -372,14 +372,19 @@ pub fn do_bls12_381_pairing_equality<
372
372
let r = read_region ( & memory, r_ptr, BLS12_381_G1_POINT_LEN ) ?;
373
373
let s = read_region ( & memory, s_ptr, BLS12_381_G2_POINT_LEN ) ?;
374
374
375
- let estimated_point_count = ( ps. len ( ) / BLS12_381_G1_POINT_LEN ) as u64 ;
375
+ // The values here are only correct if ps and qs can be divided by the point size.
376
+ // They are good enough for gas since we error in `bls12_381_pairing_equality` if the inputs are
377
+ // not properly formatted.
378
+ let estimated_n = ( ps. len ( ) / BLS12_381_G1_POINT_LEN ) as u64 ;
379
+ // The number of parings to compute (`n` on the left hand side and `k = n + 1` in total)
380
+ let estimated_k = estimated_n + 1 ;
376
381
377
382
let gas_info = GasInfo :: with_cost (
378
383
// Add one to the `estimated_point_count` since we do not include any pairs in the base
379
384
// benchmark, and we always need to add one for the `r` and `s` pair.
380
385
data. gas_config
381
386
. bls12_381_pairing_equality_cost
382
- . total_cost ( estimated_point_count + 1 ) ,
387
+ . total_cost ( estimated_k ) ,
383
388
) ;
384
389
process_gas_info ( data, & mut store, gas_info) ?;
385
390
You can’t perform that action at this time.
0 commit comments