2121use ark_bw6_761:: { Fq , Fr , G1Affine , G1Projective , G2Affine , G2Projective , BW6_761 } ;
2222use ark_ec:: { pairing:: Pairing , AffineRepr , CurveGroup , VariableBaseMSM } ;
2323use ark_ff:: { BigInteger768 , PrimeField , Zero } ;
24- use ark_std:: ops:: Mul ;
24+ use ark_std:: { ops:: Mul , vec :: Vec } ;
2525
2626// Frontier
2727use fp_evm:: {
@@ -30,8 +30,15 @@ use fp_evm::{
3030} ;
3131
3232/// Gas discount table for BW6-761 G1 and G2 multi exponentiation operations.
33- // TODO::to be estimated
34- const BW6761_MULTIEXP_DISCOUNT_TABLE : [ u16 ; 128 ] = [ 0u16 ; 128 ] ;
33+ const BW6761_MULTIEXP_DISCOUNT_TABLE : [ u16 ; 128 ] = [
34+ 1266 , 733 , 561 , 474 , 422 , 387 , 362 , 344 , 329 , 318 , 308 , 300 , 296 , 289 , 283 , 279 , 275 , 272 , 269 ,
35+ 266 , 265 , 260 , 259 , 256 , 255 , 254 , 252 , 251 , 250 , 249 , 249 , 220 , 228 , 225 , 223 , 219 , 216 , 214 ,
36+ 212 , 209 , 209 , 205 , 203 , 202 , 200 , 198 , 196 , 199 , 195 , 192 , 192 , 191 , 190 , 187 , 186 , 185 , 184 ,
37+ 184 , 181 , 181 , 181 , 180 , 178 , 179 , 176 , 177 , 176 , 175 , 174 , 173 , 171 , 171 , 170 , 170 , 169 , 168 ,
38+ 168 , 167 , 167 , 166 , 165 , 167 , 166 , 166 , 165 , 165 , 164 , 164 , 163 , 163 , 162 , 162 , 160 , 163 , 159 ,
39+ 162 , 159 , 160 , 159 , 159 , 158 , 158 , 158 , 158 , 157 , 157 , 156 , 155 , 155 , 156 , 155 , 155 , 154 , 155 ,
40+ 154 , 153 , 153 , 153 , 152 , 152 , 152 , 152 , 151 , 151 , 151 , 151 , 151 , 150 ,
41+ ] ;
3542
3643/// Encode Fq as `96` bytes by performing Big-Endian encoding of the corresponding (unsigned) integer.
3744fn encode_fq ( field : Fq ) -> [ u8 ; 96 ] {
@@ -178,8 +185,7 @@ fn decode_g2(input: &[u8], offset: usize) -> Result<G2Projective, PrecompileFail
178185pub struct Bw6761G1Add ;
179186
180187impl Bw6761G1Add {
181- // TODO::to be estimated
182- const GAS_COST : u64 = 0 ;
188+ const GAS_COST : u64 = 180 ;
183189}
184190
185191impl Precompile for Bw6761G1Add {
@@ -216,8 +222,7 @@ impl Precompile for Bw6761G1Add {
216222pub struct Bw6761G1Mul ;
217223
218224impl Bw6761G1Mul {
219- // TODO::to be estimated
220- const GAS_COST : u64 = 0 ;
225+ const GAS_COST : u64 = 64_000 ;
221226}
222227
223228impl Precompile for Bw6761G1Mul {
@@ -254,7 +259,6 @@ impl Precompile for Bw6761G1Mul {
254259pub struct Bw6761G1MultiExp ;
255260
256261impl Bw6761G1MultiExp {
257- // TODO::to be estimated
258262 const MULTIPLIER : u64 = 1_000 ;
259263
260264 /// Returns the gas required to execute the pre-compiled contract.
@@ -326,8 +330,7 @@ impl Precompile for Bw6761G1MultiExp {
326330pub struct Bw6761G2Add ;
327331
328332impl Bw6761G2Add {
329- // TODO::to be estimated
330- const GAS_COST : u64 = 0 ;
333+ const GAS_COST : u64 = 180 ;
331334}
332335
333336impl Precompile for Bw6761G2Add {
@@ -364,8 +367,7 @@ impl Precompile for Bw6761G2Add {
364367pub struct Bw6761G2Mul ;
365368
366369impl Bw6761G2Mul {
367- // TODO::to be estimated
368- const GAS_COST : u64 = 0 ;
370+ const GAS_COST : u64 = 64_000 ;
369371}
370372
371373impl Precompile for Bw6761G2Mul {
@@ -402,7 +404,6 @@ impl Precompile for Bw6761G2Mul {
402404pub struct Bw6761G2MultiExp ;
403405
404406impl Bw6761G2MultiExp {
405- // TODO::to be estimated
406407 const MULTIPLIER : u64 = 1_000 ;
407408
408409 /// Returns the gas required to execute the pre-compiled contract.
@@ -474,9 +475,8 @@ impl Precompile for Bw6761G2MultiExp {
474475pub struct Bw6761Pairing ;
475476
476477impl Bw6761Pairing {
477- // TODO::to be estimated
478- const BASE_GAS : u64 = 0 ;
479- const PER_PAIR_GAS : u64 = 0 ;
478+ const BASE_GAS : u64 = 120_000 ;
479+ const PER_PAIR_GAS : u64 = 320_000 ;
480480}
481481
482482impl Precompile for Bw6761Pairing {
0 commit comments