@@ -116,6 +116,7 @@ struct Linear {
116116#[ derive( Debug ) ]
117117struct ModexpPricer {
118118 divisor : u64 ,
119+ new_formula : bool ,
119120}
120121
121122impl Pricer for Linear {
@@ -194,7 +195,13 @@ impl Pricer for ModexpPricer {
194195
195196 let adjusted_exp_len = Self :: adjusted_exp_len ( exp_len, exp_low) ;
196197
197- let ( gas, overflow) = Self :: mult_complexity ( m) . overflowing_mul ( max ( adjusted_exp_len, 1 ) ) ;
198+ let complexity_formula = if self . new_formula {
199+ Self :: mult_complexity
200+ } else {
201+ Self :: mult_complexity_new
202+ } ;
203+
204+ let ( gas, overflow) = ( complexity_formula) ( m) . overflowing_mul ( max ( adjusted_exp_len, 1 ) ) ;
198205 if overflow {
199206 return U256 :: max_value ( ) ;
200207 }
@@ -219,6 +226,10 @@ impl ModexpPricer {
219226 x => ( x * x) / 16 + 480 * x - 199_680 ,
220227 }
221228 }
229+
230+ fn mult_complexity_new ( x : u64 ) -> u64 {
231+ ( ( x / 64 ) + if x % 64 == 0 { 0 } else { 1 } ) ^ 2
232+ }
222233}
223234
224235/// Bls12 pairing price
@@ -407,7 +418,19 @@ impl From<ethjson::spec::builtin::Pricing> for Pricing {
407418 10
408419 } else {
409420 exp. divisor
410- }
421+ } ,
422+ new_formula : false ,
423+ } )
424+ }
425+ ethjson:: spec:: builtin:: Pricing :: Modexp2 ( exp) => {
426+ Pricing :: Modexp ( ModexpPricer {
427+ divisor : if exp. divisor == 0 {
428+ warn ! ( target: "builtin" , "Zero modexp divisor specified. Falling back to default: 10." ) ;
429+ 10
430+ } else {
431+ exp. divisor
432+ } ,
433+ new_formula : true ,
411434 } )
412435 }
413436 ethjson:: spec:: builtin:: Pricing :: AltBn128Pairing ( pricer) => {
@@ -1360,7 +1383,7 @@ mod tests {
13601383 #[ test]
13611384 fn modexp ( ) {
13621385 let f = Builtin {
1363- pricer : btreemap ! [ 0 => Pricing :: Modexp ( ModexpPricer { divisor: 20 } ) ] ,
1386+ pricer : btreemap ! [ 0 => Pricing :: Modexp ( ModexpPricer { divisor: 20 , new_formula : false } ) ] ,
13641387 native : EthereumBuiltin :: from_str ( "modexp" ) . unwrap ( ) ,
13651388 } ;
13661389
0 commit comments