Commit f004f31
authored
core/vm: use go-bigmodexpfix for modexp (erigontech#17151)
Cherry pick ethereum/go-ethereum#32576
BEFORE
```
goos: darwin
goarch: arm64
pkg: github.com/erigontech/erigon/core/vm
cpu: Apple M2 Max
BenchmarkPrecompiledModExpEip7883/eip_example1-Gas=4080-12 75729 16444 ns/op 4080 gas/op 248.1 mgas/s 2144 B/op 27 allocs/op
BenchmarkPrecompiledModExpEip7883/eip_example2-Gas=4080-12 12680174 93.87 ns/op 4080 gas/op 43465 mgas/s 160 B/op 3 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-1-square-Gas=500-12 2373879 501.7 ns/op 500.0 gas/op 996.6 mgas/s 696 B/op 7 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-1-qube-Gas=500-12 1602600 750.7 ns/op 500.0 gas/op 666.0 mgas/s 984 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-1-pow0x10001-Gas=2048-12 228504 4965 ns/op 2048 gas/op 412.4 mgas/s 1480 B/op 11 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-2-square-Gas=512-12 1320512 918.9 ns/op 512.0 gas/op 557.2 mgas/s 1224 B/op 7 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-2-qube-Gas=512-12 714223 1527 ns/op 512.0 gas/op 335.3 mgas/s 1768 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-2-pow0x10001-Gas=8192-12 103635 11486 ns/op 8192 gas/op 713.2 mgas/s 2664 B/op 11 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-3-square-Gas=2048-12 545532 1955 ns/op 2048 gas/op 1047 mgas/s 2280 B/op 7 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-3-qube-Gas=2048-12 279217 4026 ns/op 2048 gas/op 508.7 mgas/s 3496 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-3-pow0x10001-Gas=32768-12 45536 26570 ns/op 32768 gas/op 1233 mgas/s 5224 B/op 11 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-4-square-Gas=8192-12 212790 5417 ns/op 8192 gas/op 1512 mgas/s 4552 B/op 7 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-4-qube-Gas=8192-12 97126 12566 ns/op 8192 gas/op 651.9 mgas/s 11595 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-4-pow0x10001-Gas=131072-12 14682 81482 ns/op 131072 gas/op 1609 mgas/s 15051 B/op 12 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-5-square-Gas=32768-12 71446 16877 ns/op 32768 gas/op 1941 mgas/s 9230 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-5-qube-Gas=32768-12 30558 38567 ns/op 32768 gas/op 849.6 mgas/s 23188 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-5-pow0x10001-Gas=524288-12 4429 265553 ns/op 524288 gas/op 1974 mgas/s 32030 B/op 28 allocs/op
BenchmarkPrecompiledModExpEip7883/marius-1-even-Gas=45296-12 26780 44394 ns/op 45296 gas/op 1020 mgas/s 1992 B/op 40 allocs/op
BenchmarkPrecompiledModExpEip7883/guido-1-even-Gas=51136-12 41125 28834 ns/op 51136 gas/op 1773 mgas/s 1960 B/op 43 allocs/op
BenchmarkPrecompiledModExpEip7883/guido-2-even-Gas=51152-12 23472 50577 ns/op 51152 gas/op 1011 mgas/s 2088 B/op 41 allocs/op
BenchmarkPrecompiledModExpEip7883/guido-3-even-Gas=32400-12 86510 13684 ns/op 32400 gas/op 2368 mgas/s 8009 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/guido-4-even-Gas=94448-12 7207062 165.4 ns/op 94448 gas/op 570947 mgas/s 488 B/op 6 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-1-base-heavy-Gas=1152-12 412336 2758 ns/op 1152 gas/op 417.7 mgas/s 2568 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-1-exp-heavy-Gas=16624-12 106598 11272 ns/op 16624 gas/op 1475 mgas/s 1112 B/op 25 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-1-balanced-Gas=1200-12 139212 8523 ns/op 1200 gas/op 140.8 mgas/s 840 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-2-base-heavy-Gas=5202-12 132448 8974 ns/op 5202 gas/op 579.6 mgas/s 9322 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-2-exp-heavy-Gas=16368-12 64364 18475 ns/op 16368 gas/op 885.9 mgas/s 1536 B/op 25 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-2-balanced-Gas=5978-12 41782 28878 ns/op 5978 gas/op 207.0 mgas/s 1576 B/op 12 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-3-base-heavy-Gas=2032-12 129862 8876 ns/op 2032 gas/op 228.9 mgas/s 2144 B/op 25 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-3-exp-heavy-Gas=4080-12 110368 10622 ns/op 4080 gas/op 384.1 mgas/s 1856 B/op 25 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-3-balanced-Gas=4080-12 69883 16505 ns/op 4080 gas/op 247.2 mgas/s 2160 B/op 25 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-8-exp-648-Gas=16624-12 97918 12297 ns/op 16624 gas/op 1352 mgas/s 1336 B/op 38 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-8-exp-896-Gas=24560-12 77826 15248 ns/op 24560 gas/op 1611 mgas/s 1352 B/op 38 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-32-exp-32-Gas=500-12 155653 7206 ns/op 500.0 gas/op 69.38 mgas/s 728 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-32-exp-36-Gas=560-12 146266 8080 ns/op 560.0 gas/op 69.30 mgas/s 872 B/op 11 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-32-exp-40-Gas=624-12 134626 8994 ns/op 624.0 gas/op 69.37 mgas/s 728 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-32-exp-64-Gas=1008-12 82645 14400 ns/op 1008 gas/op 69.99 mgas/s 728 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-32-exp-65-Gas=1024-12 140695 8480 ns/op 1024 gas/op 120.7 mgas/s 2640 B/op 41 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-32-exp-128-Gas=2032-12 137784 8532 ns/op 2032 gas/op 238.2 mgas/s 2640 B/op 41 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-256-exp-2-Gas=2048-12 276464 4177 ns/op 2048 gas/op 490.2 mgas/s 3496 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-264-exp-2-Gas=2178-12 259459 4383 ns/op 2178 gas/op 496.9 mgas/s 3624 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-1024-exp-2-Gas=32768-12 33732 31730 ns/op 32768 gas/op 1033 mgas/s 24212 B/op 11 allocs/op
BenchmarkPrecompiledModExpEip7883/pawel-1-exp-heavy-Gas=24560-12 78891 15046 ns/op 24560 gas/op 1632 mgas/s 1408 B/op 40 allocs/op
BenchmarkPrecompiledModExpEip7883/pawel-2-exp-heavy-Gas=6128-12 105846 11001 ns/op 6128 gas/op 557.0 mgas/s 1928 B/op 42 allocs/op
BenchmarkPrecompiledModExpEip7883/pawel-3-exp-heavy-Gas=2672-12 119985 9480 ns/op 2672 gas/op 281.8 mgas/s 2352 B/op 42 allocs/op
BenchmarkPrecompiledModExpEip7883/pawel-4-exp-heavy-Gas=1520-12 134353 8740 ns/op 1520 gas/op 173.9 mgas/s 2648 B/op 42 allocs/op
BenchmarkPrecompiledModExpEip7883/mod_vul_pawel_3_exp_8-Gas=1008-12 80396 15129 ns/op 1008 gas/op 66.62 mgas/s 608 B/op 9 allocs/op
```
AFTER
```
goos: darwin
goarch: arm64
pkg: github.com/erigontech/erigon/core/vm
cpu: Apple M2 Max
BenchmarkPrecompiledModExpEip7883/eip_example1-Gas=4080-12 52860 22778 ns/op 4080 gas/op 179.1 mgas/s 496 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/eip_example2-Gas=4080-12 12801109 91.61 ns/op 4080 gas/op 44533 mgas/s 160 B/op 3 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-1-square-Gas=500-12 2422894 487.8 ns/op 500.0 gas/op 1025 mgas/s 696 B/op 7 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-1-qube-Gas=500-12 1609234 741.7 ns/op 500.0 gas/op 674.1 mgas/s 984 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-1-pow0x10001-Gas=2048-12 364200 3284 ns/op 2048 gas/op 623.6 mgas/s 936 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-2-square-Gas=512-12 1356390 886.2 ns/op 512.0 gas/op 577.7 mgas/s 1224 B/op 7 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-2-qube-Gas=512-12 719048 1540 ns/op 512.0 gas/op 332.6 mgas/s 1768 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-2-pow0x10001-Gas=8192-12 123076 9663 ns/op 8192 gas/op 847.7 mgas/s 1672 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-3-square-Gas=2048-12 552962 1973 ns/op 2048 gas/op 1038 mgas/s 2280 B/op 7 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-3-qube-Gas=2048-12 286252 4043 ns/op 2048 gas/op 506.5 mgas/s 3496 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-3-pow0x10001-Gas=32768-12 40658 29910 ns/op 32768 gas/op 1096 mgas/s 3112 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-4-square-Gas=8192-12 225214 5273 ns/op 8192 gas/op 1553 mgas/s 4553 B/op 7 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-4-qube-Gas=8192-12 99357 12177 ns/op 8192 gas/op 672.7 mgas/s 6985 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-4-pow0x10001-Gas=131072-12 10000 115794 ns/op 131072 gas/op 1132 mgas/s 6219 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-5-square-Gas=32768-12 73618 15983 ns/op 32768 gas/op 2050 mgas/s 9101 B/op 7 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-5-qube-Gas=32768-12 32450 36631 ns/op 32768 gas/op 894.5 mgas/s 13196 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/nagydani-5-pow0x10001-Gas=524288-12 2623 451022 ns/op 524288 gas/op 1162 mgas/s 12447 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/marius-1-even-Gas=45296-12 19376 62163 ns/op 45296 gas/op 728.6 mgas/s 592 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/guido-1-even-Gas=51136-12 35404 33843 ns/op 51136 gas/op 1511 mgas/s 680 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/guido-2-even-Gas=51152-12 17017 69739 ns/op 51152 gas/op 733.4 mgas/s 648 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/guido-3-even-Gas=32400-12 110955 10649 ns/op 32400 gas/op 3042 mgas/s 8009 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/guido-4-even-Gas=94448-12 7252432 165.1 ns/op 94448 gas/op 572094 mgas/s 488 B/op 6 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-1-base-heavy-Gas=1152-12 442668 2629 ns/op 1152 gas/op 438.1 mgas/s 2568 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-1-exp-heavy-Gas=16624-12 100824 11898 ns/op 16624 gas/op 1397 mgas/s 344 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-1-balanced-Gas=1200-12 310458 3887 ns/op 1200 gas/op 308.7 mgas/s 712 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-2-base-heavy-Gas=5202-12 132290 9050 ns/op 5202 gas/op 574.8 mgas/s 5225 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-2-exp-heavy-Gas=16368-12 45422 25915 ns/op 16368 gas/op 631.6 mgas/s 448 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-2-balanced-Gas=5978-12 72652 16630 ns/op 5978 gas/op 359.4 mgas/s 888 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-3-base-heavy-Gas=2032-12 100966 11972 ns/op 2032 gas/op 169.7 mgas/s 528 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-3-exp-heavy-Gas=4080-12 85906 13942 ns/op 4080 gas/op 292.6 mgas/s 496 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/marcin-3-balanced-Gas=4080-12 50563 23756 ns/op 4080 gas/op 171.7 mgas/s 544 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-8-exp-648-Gas=16624-12 96452 12356 ns/op 16624 gas/op 1345 mgas/s 352 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-8-exp-896-Gas=24560-12 70987 16708 ns/op 24560 gas/op 1470 mgas/s 368 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-32-exp-32-Gas=500-12 319215 3796 ns/op 500.0 gas/op 131.7 mgas/s 568 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-32-exp-36-Gas=560-12 291817 4096 ns/op 560.0 gas/op 136.7 mgas/s 568 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-32-exp-40-Gas=624-12 261309 4475 ns/op 624.0 gas/op 139.4 mgas/s 568 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-32-exp-64-Gas=1008-12 177766 6670 ns/op 1008 gas/op 151.1 mgas/s 568 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-32-exp-65-Gas=1024-12 178934 6448 ns/op 1024 gas/op 158.8 mgas/s 608 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-32-exp-128-Gas=2032-12 109399 10844 ns/op 2032 gas/op 187.4 mgas/s 608 B/op 10 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-256-exp-2-Gas=2048-12 279650 4236 ns/op 2048 gas/op 483.5 mgas/s 3496 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-264-exp-2-Gas=2178-12 269932 4334 ns/op 2178 gas/op 502.5 mgas/s 3624 B/op 8 allocs/op
BenchmarkPrecompiledModExpEip7883/mod-1024-exp-2-Gas=32768-12 40960 28069 ns/op 32768 gas/op 1167 mgas/s 14224 B/op 9 allocs/op
BenchmarkPrecompiledModExpEip7883/pawel-1-exp-heavy-Gas=24560-12 71101 16897 ns/op 24560 gas/op 1453 mgas/s 424 B/op 12 allocs/op
BenchmarkPrecompiledModExpEip7883/pawel-2-exp-heavy-Gas=6128-12 88423 13373 ns/op 6128 gas/op 458.2 mgas/s 488 B/op 11 allocs/op
BenchmarkPrecompiledModExpEip7883/pawel-3-exp-heavy-Gas=2672-12 121406 9772 ns/op 2672 gas/op 273.4 mgas/s 576 B/op 11 allocs/op
BenchmarkPrecompiledModExpEip7883/pawel-4-exp-heavy-Gas=1520-12 138334 8490 ns/op 1520 gas/op 179.0 mgas/s 616 B/op 11 allocs/op
BenchmarkPrecompiledModExpEip7883/mod_vul_pawel_3_exp_8-Gas=1008-12 264200 4392 ns/op 1008 gas/op 229.5 mgas/s 496 B/op 10 allocs/op
```
Note that though some cases become worse, the worst performance goes
from 66.62 mgas/s to 131.7 mgas/s.1 parent faf06c6 commit f004f31
File tree
4 files changed
+124
-27
lines changed- core/vm
- testdata/precompiles
4 files changed
+124
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
555 | 556 | | |
556 | 557 | | |
557 | 558 | | |
| 559 | + | |
558 | 560 | | |
559 | 561 | | |
560 | 562 | | |
| |||
599 | 601 | | |
600 | 602 | | |
601 | 603 | | |
602 | | - | |
603 | | - | |
604 | | - | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
605 | 607 | | |
606 | 608 | | |
607 | 609 | | |
608 | | - | |
| 610 | + | |
609 | 611 | | |
610 | | - | |
| 612 | + | |
611 | 613 | | |
612 | | - | |
| 614 | + | |
613 | 615 | | |
614 | 616 | | |
615 | 617 | | |
| |||
620 | 622 | | |
621 | 623 | | |
622 | 624 | | |
623 | | - | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | 625 | | |
644 | 626 | | |
645 | 627 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
218 | 330 | | |
219 | 331 | | |
0 commit comments