Skip to content

Commit 8a1d3bb

Browse files
committed
core/vm,params: update DiscountTable for Bls12381G1 and Bls12381G2
reference: ethereum/EIPs#9116
1 parent 6abddc6 commit 8a1d3bb

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

core/vm/contracts.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,10 @@ func (c *bls12381G1MultiExp) RequiredGas(input []byte) uint64 {
769769
}
770770
// Lookup discount value for G1 point, scalar value pair length
771771
var discount uint64
772-
if dLen := len(params.Bls12381MultiExpDiscountTable); k < dLen {
773-
discount = params.Bls12381MultiExpDiscountTable[k-1]
772+
if dLen := len(params.Bls12381G1MultiExpDiscountTable); k < dLen {
773+
discount = params.Bls12381G1MultiExpDiscountTable[k-1]
774774
} else {
775-
discount = params.Bls12381MultiExpDiscountTable[dLen-1]
775+
discount = params.Bls12381G1MultiExpDiscountTable[dLen-1]
776776
}
777777
// Calculate gas and return the result
778778
return (uint64(k) * params.Bls12381G1MulGas * discount) / 1000
@@ -864,10 +864,10 @@ func (c *bls12381G2MultiExp) RequiredGas(input []byte) uint64 {
864864
}
865865
// Lookup discount value for G2 point, scalar value pair length
866866
var discount uint64
867-
if dLen := len(params.Bls12381MultiExpDiscountTable); k < dLen {
868-
discount = params.Bls12381MultiExpDiscountTable[k-1]
867+
if dLen := len(params.Bls12381G2MultiExpDiscountTable); k < dLen {
868+
discount = params.Bls12381G2MultiExpDiscountTable[k-1]
869869
} else {
870-
discount = params.Bls12381MultiExpDiscountTable[dLen-1]
870+
discount = params.Bls12381G2MultiExpDiscountTable[dLen-1]
871871
}
872872
// Calculate gas and return the result
873873
return (uint64(k) * params.Bls12381G2MulGas * discount) / 1000

params/protocol_params.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,11 @@ const (
193193
HistoryServeWindow = 8192 // Number of blocks to serve historical block hashes for, EIP-2935.
194194
)
195195

196-
// Gas discount table for BLS12-381 G1 and G2 multi exponentiation operations
197-
var Bls12381MultiExpDiscountTable = [128]uint64{1200, 888, 764, 641, 594, 547, 500, 453, 438, 423, 408, 394, 379, 364, 349, 334, 330, 326, 322, 318, 314, 310, 306, 302, 298, 294, 289, 285, 281, 277, 273, 269, 268, 266, 265, 263, 262, 260, 259, 257, 256, 254, 253, 251, 250, 248, 247, 245, 244, 242, 241, 239, 238, 236, 235, 233, 232, 231, 229, 228, 226, 225, 223, 222, 221, 220, 219, 219, 218, 217, 216, 216, 215, 214, 213, 213, 212, 211, 211, 210, 209, 208, 208, 207, 206, 205, 205, 204, 203, 202, 202, 201, 200, 199, 199, 198, 197, 196, 196, 195, 194, 193, 193, 192, 191, 191, 190, 189, 188, 188, 187, 186, 185, 185, 184, 183, 182, 182, 181, 180, 179, 179, 178, 177, 176, 176, 175, 174}
196+
// Bls12381G1MultiExpDiscountTable is the gas discount table for BLS12-381 G1 multi exponentiation operation
197+
var Bls12381G1MultiExpDiscountTable = [128]uint64{1000, 949, 848, 797, 764, 750, 738, 728, 719, 712, 705, 698, 692, 687, 682, 677, 673, 669, 665, 661, 658, 654, 651, 648, 645, 642, 640, 637, 635, 632, 630, 627, 625, 623, 621, 619, 617, 615, 613, 611, 609, 608, 606, 604, 603, 601, 599, 598, 596, 595, 593, 592, 591, 589, 588, 586, 585, 584, 582, 581, 580, 579, 577, 576, 575, 574, 573, 572, 570, 569, 568, 567, 566, 565, 564, 563, 562, 561, 560, 559, 558, 557, 556, 555, 554, 553, 552, 551, 550, 549, 548, 547, 547, 546, 545, 544, 543, 542, 541, 540, 540, 539, 538, 537, 536, 536, 535, 534, 533, 532, 532, 531, 530, 529, 528, 528, 527, 526, 525, 525, 524, 523, 522, 522, 521, 520, 520, 519}
198+
199+
// Bls12381G2MultiExpDiscountTable is the gas discount table for BLS12-381 G2 multi exponentiation operation
200+
var Bls12381G2MultiExpDiscountTable = [128]uint64{1000, 1000, 923, 884, 855, 832, 812, 796, 782, 770, 759, 749, 740, 732, 724, 717, 711, 704, 699, 693, 688, 683, 679, 674, 670, 666, 663, 659, 655, 652, 649, 646, 643, 640, 637, 634, 632, 629, 627, 624, 622, 620, 618, 615, 613, 611, 609, 607, 606, 604, 602, 600, 598, 597, 595, 593, 592, 590, 589, 587, 586, 584, 583, 582, 580, 579, 578, 576, 575, 574, 573, 571, 570, 569, 568, 567, 566, 565, 563, 562, 561, 560, 559, 558, 557, 556, 555, 554, 553, 552, 552, 551, 550, 549, 548, 547, 546, 545, 545, 544, 543, 542, 541, 541, 540, 539, 538, 537, 537, 536, 535, 535, 534, 533, 532, 532, 531, 530, 530, 529, 528, 528, 527, 526, 526, 525, 524, 524}
198201

199202
var (
200203
DifficultyBoundDivisor = big.NewInt(2048) // The bound divisor of the difficulty, used in the update calculations.

0 commit comments

Comments
 (0)