Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EIP-2537: MSM gas repricing #9116

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions EIPS/eip-2537.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,21 +269,35 @@ Assuming a constant `30 MGas/second`, the following prices are suggested.

#### G2 multiplication

`45000` gas
`22500` gas

#### G1/G2 MSM

MSMs are expected to be performed by Pippenger's algorithm (we can also say that it **must** be performed by Pippenger's algorithm to have a speedup that results in a discount over naive implementation by multiplying each pair separately and adding the results). For this case there was a table prepared for discount in case of `k <= 128` points in the MSM with a discount cap `max_discount` for `k > 128`.

To avoid non-integer arithmetic, the call cost is calculated as `(k * multiplication_cost * discount) / multiplier` where `multiplier = 1000`, `k` is a number of (scalar, point) pairs for the call, `multiplication_cost` is a corresponding single multiplication call cost for G1/G2.

Discounts table as a vector of pairs `[k, discount]`:
G1 and G2 are priced separately, each having their own discount table and `max_discount`.

##### G1 discounts

Discounts table for G1 MSM as a vector of pairs `[k, discount]`:

```
[[1, 1800], [2, 888], [3, 955], [4, 802], [5, 743], [6, 821], [7, 750], [8, 680], [9, 657], [10, 635], [11, 612], [12, 591], [13, 664], [14, 637], [15, 611], [16, 585], [17, 578], [18, 571], [19, 564], [20, 557], [21, 628], [22, 620], [23, 612], [24, 604], [25, 596], [26, 588], [27, 578], [28, 570], [29, 562], [30, 693], [31, 683], [32, 673], [33, 670], [34, 665], [35, 663], [36, 658], [37, 655], [38, 650], [39, 648], [40, 643], [41, 640], [42, 635], [43, 633], [44, 628], [45, 625], [46, 620], [47, 618], [48, 613], [49, 610], [50, 605], [51, 603], [52, 598], [53, 595], [54, 590], [55, 588], [56, 583], [57, 580], [58, 578], [59, 573], [60, 570], [61, 565], [62, 563], [63, 558], [64, 555], [65, 553], [66, 550], [67, 548], [68, 548], [69, 545], [70, 543], [71, 540], [72, 540], [73, 538], [74, 535], [75, 533], [76, 533], [77, 530], [78, 528], [79, 528], [80, 525], [81, 523], [82, 520], [83, 520], [84, 518], [85, 515], [86, 513], [87, 513], [88, 510], [89, 508], [90, 505], [91, 505], [92, 503], [93, 500], [94, 498], [95, 498], [96, 495], [97, 493], [98, 490], [99, 490], [100, 488], [101, 485], [102, 483], [103, 483], [104, 480], [105, 478], [106, 478], [107, 475], [108, 473], [109, 470], [110, 470], [111, 468], [112, 465], [113, 463], [114, 463], [115, 460], [116, 458], [117, 455], [118, 455], [119, 453], [120, 450], [121, 448], [122, 448], [123, 445], [124, 443], [125, 440], [126, 440], [127, 438], [128, 435]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For k=1 we should put 1000 (the same cost as multiplication). Otherwise, we incentivize contracts to put a condition to redirect inputs from MSM to MUL in case they have single point.
In other words, if you have single point to multiply, you should not use any MSM algorithm. Just use regular multiplication in your MSM precompile implementation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are not monotonic, so you have to fix this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me the terminal value k=128 is 520.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are not monotonic, so you have to fix this.

missed that. they should definitely be monotonic, regardless of the performance profile for any particular k,

```

`max_discount = 435`

##### G2 discounts

Discounts table for G2 MSM as a vector of pairs `[k, discount]`:

```
[[1, 1200], [2, 888], [3, 764], [4, 641], [5, 594], [6, 547], [7, 500], [8, 453], [9, 438], [10, 423], [11, 408], [12, 394], [13, 379], [14, 364], [15, 349], [16, 334], [17, 330], [18, 326], [19, 322], [20, 318], [21, 314], [22, 310], [23, 306], [24, 302], [25, 298], [26, 294], [27, 289], [28, 285], [29, 281], [30, 277], [31, 273], [32, 269], [33, 268], [34, 266], [35, 265], [36, 263], [37, 262], [38, 260], [39, 259], [40, 257], [41, 256], [42, 254], [43, 253], [44, 251], [45, 250], [46, 248], [47, 247], [48, 245], [49, 244], [50, 242], [51, 241], [52, 239], [53, 238], [54, 236], [55, 235], [56, 233], [57, 232], [58, 231], [59, 229], [60, 228], [61, 226], [62, 225], [63, 223], [64, 222], [65, 221], [66, 220], [67, 219], [68, 219], [69, 218], [70, 217], [71, 216], [72, 216], [73, 215], [74, 214], [75, 213], [76, 213], [77, 212], [78, 211], [79, 211], [80, 210], [81, 209], [82, 208], [83, 208], [84, 207], [85, 206], [86, 205], [87, 205], [88, 204], [89, 203], [90, 202], [91, 202], [92, 201], [93, 200], [94, 199], [95, 199], [96, 198], [97, 197], [98, 196], [99, 196], [100, 195], [101, 194], [102, 193], [103, 193], [104, 192], [105, 191], [106, 191], [107, 190], [108, 189], [109, 188], [110, 188], [111, 187], [112, 186], [113, 185], [114, 185], [115, 184], [116, 183], [117, 182], [118, 182], [119, 181], [120, 180], [121, 179], [122, 179], [123, 178], [124, 177], [125, 176], [126, 176], [127, 175], [128, 174]]
[[1, 1800], [2, 1776], [3, 1528], [4, 1282], [5, 1188], [6, 1368], [7, 1250], [8, 1133], [9, 1095], [10, 1269], [11, 1224], [12, 1182], [13, 1137], [14, 1274], [15, 1222], [16, 1169], [17, 1155], [18, 1141], [19, 1127], [20, 1113], [21, 1256], [22, 1240], [23, 1224], [24, 1208], [25, 1192], [26, 1176], [27, 1156], [28, 1140], [29, 1124], [30, 1108], [31, 1092], [32, 1076], [33, 1072], [34, 1064], [35, 1060], [36, 1052], [37, 1048], [38, 1040], [39, 1036], [40, 1028], [41, 1024], [42, 1016], [43, 1012], [44, 1004], [45, 1000], [46, 992], [47, 988], [48, 980], [49, 976], [50, 968], [51, 964], [52, 956], [53, 952], [54, 944], [55, 940], [56, 932], [57, 928], [58, 924], [59, 916], [60, 912], [61, 904], [62, 900], [63, 892], [64, 888], [65, 884], [66, 880], [67, 876], [68, 876], [69, 872], [70, 868], [71, 864], [72, 864], [73, 860], [74, 856], [75, 852], [76, 852], [77, 848], [78, 844], [79, 844], [80, 840], [81, 836], [82, 832], [83, 832], [84, 828], [85, 824], [86, 820], [87, 820], [88, 816], [89, 812], [90, 808], [91, 808], [92, 804], [93, 800], [94, 796], [95, 796], [96, 792], [97, 788], [98, 784], [99, 784], [100, 780], [101, 776], [102, 772], [103, 772], [104, 768], [105, 764], [106, 764], [107, 760], [108, 756], [109, 752], [110, 752], [111, 748], [112, 744], [113, 740], [114, 740], [115, 736], [116, 732], [117, 728], [118, 728], [119, 724], [120, 720], [121, 716], [122, 716], [123, 712], [124, 708], [125, 704], [126, 704], [127, 700], [128, 696]]
```

`max_discount = 174`
`max_discount = 696`

#### Pairing check operation

Expand Down
Loading