@@ -7,6 +7,7 @@ use std::ops::Mul;
7
7
8
8
use anyhow:: Context ;
9
9
use fvm_shared:: clock:: ChainEpoch ;
10
+ #[ cfg( feature = "verify-signature" ) ]
10
11
use fvm_shared:: crypto:: signature:: SignatureType ;
11
12
use fvm_shared:: piece:: PieceInfo ;
12
13
use fvm_shared:: sector:: {
@@ -102,6 +103,7 @@ lazy_static! {
102
103
address_lookup: Gas :: new( 1_050_000 ) ,
103
104
address_assignment: Gas :: new( 1_000_000 ) ,
104
105
106
+ #[ cfg( feature = "verify-signature" ) ]
105
107
sig_cost: total_enum_map!{
106
108
SignatureType {
107
109
Secp256k1 => ScalingCost {
@@ -115,6 +117,11 @@ lazy_static! {
115
117
}
116
118
} ,
117
119
secp256k1_recover_cost: Gas :: new( 1637292 ) ,
120
+ bls_pairing_cost: Gas :: new( 8299302 ) ,
121
+ bls_hashing_cost: ScalingCost {
122
+ flat: Gas :: zero( ) ,
123
+ scale: Gas :: new( 7 ) ,
124
+ } ,
118
125
hashing_cost: total_enum_map! {
119
126
SupportedHashes {
120
127
Sha2_256 => ScalingCost {
@@ -399,11 +406,15 @@ pub struct PriceList {
399
406
pub ( crate ) actor_create_storage : Gas ,
400
407
401
408
/// Gas cost for verifying a cryptographic signature.
409
+ #[ cfg( feature = "verify-signature" ) ]
402
410
pub ( crate ) sig_cost : HashMap < SignatureType , ScalingCost > ,
403
411
404
412
/// Gas cost for recovering secp256k1 signer public key
405
413
pub ( crate ) secp256k1_recover_cost : Gas ,
406
414
415
+ pub ( crate ) bls_pairing_cost : Gas ,
416
+ pub ( crate ) bls_hashing_cost : ScalingCost ,
417
+
407
418
pub ( crate ) hashing_cost : HashMap < SupportedHashes , ScalingCost > ,
408
419
409
420
/// Gas cost for walking up the chain.
@@ -591,13 +602,36 @@ impl PriceList {
591
602
}
592
603
593
604
/// Returns gas required for signature verification.
605
+ #[ cfg( feature = "verify-signature" ) ]
594
606
#[ inline]
595
607
pub fn on_verify_signature ( & self , sig_type : SignatureType , data_len : usize ) -> GasCharge {
596
608
let cost = self . sig_cost [ & sig_type] ;
597
609
let gas = cost. apply ( data_len) ;
598
610
GasCharge :: new ( "OnVerifySignature" , gas, Zero :: zero ( ) )
599
611
}
600
612
613
+ /// Returns gas required for BLS aggregate signature verification.
614
+ #[ inline]
615
+ pub fn on_verify_aggregate_signature ( & self , num_sigs : usize , data_len : usize ) -> GasCharge {
616
+ // When `num_sigs` BLS signatures are aggregated into a single signature, the aggregate
617
+ // signature verifier must perform `num_sigs + 1` expensive pairing operations (one
618
+ // pairing on the aggregate signature, and one pairing for each signed plaintext's digest).
619
+ //
620
+ // Note that `bls_signatures` rearranges the textbook verifier equation (containing
621
+ // `num_sigs + 1` full pairings) into a more efficient equation containing `num_sigs + 1`
622
+ // Miller loops and one final exponentiation.
623
+ let num_pairings = num_sigs as u64 + 1 ;
624
+
625
+ let gas_pairings = self . bls_pairing_cost * num_pairings;
626
+ let gas_hashing = self . bls_hashing_cost . apply ( data_len) ;
627
+
628
+ GasCharge :: new (
629
+ "OnVerifyBlsAggregateSignature" ,
630
+ gas_pairings + gas_hashing,
631
+ Zero :: zero ( ) ,
632
+ )
633
+ }
634
+
601
635
/// Returns gas required for recovering signer pubkey from signature
602
636
#[ inline]
603
637
pub fn on_recover_secp_public_key ( & self ) -> GasCharge {
0 commit comments