From a94cd06f9380292cac687b529e26b2eb157613dc Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 11 Dec 2024 18:52:58 +1100 Subject: [PATCH 1/8] update gas costs --- .../Precompiles/Bls/Discount.cs | 275 +++++++++--------- .../Precompiles/Bls/G1AddPrecompile.cs | 2 +- .../Precompiles/Bls/G1MSMPrecompile.cs | 2 +- .../Precompiles/Bls/G2AddPrecompile.cs | 2 +- .../Precompiles/Bls/G2MSMPrecompile.cs | 2 +- .../Precompiles/Bls/G2MulPrecompile.cs | 2 +- .../Precompiles/Bls/MapFp2ToG2Precompile.cs | 2 +- .../Precompiles/Bls/MapFpToG1Precompile.cs | 2 +- .../Precompiles/Bls/PairingCheckPrecompile.cs | 4 +- 9 files changed, 147 insertions(+), 146 deletions(-) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs index a84d69d1d06..5b3abad3059 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System.Collections.Generic; +using System.Reflection.Metadata; namespace Nethermind.Evm.Precompiles.Bls { @@ -10,146 +11,146 @@ namespace Nethermind.Evm.Precompiles.Bls /// internal static class Discount { - public static int For(int k) + public static int For(int k, bool isG2) => k switch { - return k switch - { - 0 => 0, - var x when x >= 128 => 174, - _ => _discountTable[k] - }; - } + var x when x >= 128 => isG2 ? _maxDiscountG2 : _maxDiscountG1, + _ => isG2 ? _discountTable[k].g2 : _discountTable[k].g1 + }; + + private const int _maxDiscountG1 = 435; + private const int _maxDiscountG2 = 696; - private static readonly Dictionary _discountTable = new() + private static readonly (int g1, int g2)[] _discountTable = { - { 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 } + (0, 0), // 0 + (1800, 1800), // 1 + (888, 1776), // 2 + (955, 1528), // 3 + (802, 1282), // 4 + (743, 1188), // 5 + (821, 1368), // 6 + (750, 1250), // 7 + (680, 1133), // 8 + (657, 1095), // 9 + (635, 1269), // 10 + (612, 1224), // 11 + (591, 1182), // 12 + (664, 1137), // 13 + (637, 1274), // 14 + (611, 1222), // 15 + (585, 1169), // 16 + (578, 1155), // 17 + (571, 1141), // 18 + (564, 1127), // 19 + (557, 1113), // 20 + (628, 1256), // 21 + (620, 1240), // 22 + (612, 1224), // 23 + (604, 1208), // 24 + (596, 1192), // 25 + (588, 1176), // 26 + (578, 1156), // 27 + (570, 1140), // 28 + (562, 1124), // 29 + (693, 1108), // 30 + (683, 1092), // 31 + (673, 1076), // 32 + (670, 1072), // 33 + (665, 1064), // 34 + (663, 1060), // 35 + (658, 1052), // 36 + (655, 1048), // 37 + (650, 1040), // 38 + (648, 1036), // 39 + (643, 1028), // 40 + (640, 1024), // 41 + (635, 1016), // 42 + (633, 1012), // 43 + (628, 1004), // 44 + (625, 1000), // 45 + (620, 992), // 46 + (618, 988), // 47 + (613, 980), // 48 + (610, 976), // 49 + (605, 968), // 50 + (603, 964), // 51 + (598, 956), // 52 + (595, 952), // 53 + (590, 944), // 54 + (588, 940), // 55 + (583, 932), // 56 + (580, 928), // 57 + (578, 924), // 58 + (573, 916), // 59 + (570, 912), // 60 + (565, 904), // 61 + (563, 900), // 62 + (558, 892), // 63 + (555, 888), // 64 + (553, 884), // 65 + (550, 880), // 66 + (548, 876), // 67 + (548, 876), // 68 + (545, 872), // 69 + (543, 868), // 70 + (540, 864), // 71 + (540, 864), // 72 + (538, 860), // 73 + (535, 856), // 74 + (533, 852), // 75 + (533, 852), // 76 + (530, 848), // 77 + (528, 844), // 78 + (528, 844), // 79 + (525, 840), // 80 + (523, 836), // 81 + (520, 832), // 82 + (520, 832), // 83 + (518, 828), // 84 + (515, 824), // 85 + (513, 820), // 86 + (513, 820), // 87 + (510, 816), // 88 + (508, 812), // 89 + (505, 808), // 90 + (505, 808), // 91 + (503, 804), // 92 + (500, 800), // 93 + (498, 796), // 94 + (498, 796), // 95 + (495, 792), // 96 + (493, 788), // 97 + (490, 784), // 98 + (490, 784), // 99 + (488, 780), // 100 + (485, 776), // 101 + (483, 772), // 102 + (483, 772), // 103 + (480, 768), // 104 + (478, 764), // 105 + (478, 764), // 106 + (475, 760), // 107 + (473, 756), // 108 + (470, 752), // 109 + (470, 752), // 110 + (468, 748), // 111 + (465, 744), // 112 + (463, 740), // 113 + (463, 740), // 114 + (460, 736), // 115 + (458, 732), // 116 + (455, 728), // 117 + (455, 728), // 118 + (453, 724), // 119 + (450, 720), // 120 + (448, 716), // 121 + (448, 716), // 122 + (445, 712), // 123 + (443, 708), // 124 + (440, 704), // 125 + (440, 704), // 126 + (438, 700), // 127 + (435, 696) // 128 }; } } diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs index 53df7f426df..aa8c155a747 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1AddPrecompile.cs @@ -23,7 +23,7 @@ private G1AddPrecompile() public static Address Address { get; } = Address.FromNumber(0x0b); - public long BaseGasCost(IReleaseSpec releaseSpec) => 500L; + public long BaseGasCost(IReleaseSpec releaseSpec) => 375L; public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs index 8f3f734f37f..fc0c926c270 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs @@ -30,7 +30,7 @@ private G1MSMPrecompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { int k = inputData.Length / ItemSize; - return 12000L * k * Discount.For(k) / 1000; + return 12000L * k * Discount.For(k, false) / 1000; } public const int ItemSize = 160; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs index 710954f3a3b..4cafcb61634 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2AddPrecompile.cs @@ -23,7 +23,7 @@ private G2AddPrecompile() public static Address Address { get; } = Address.FromNumber(0x0e); - public long BaseGasCost(IReleaseSpec releaseSpec) => 800L; + public long BaseGasCost(IReleaseSpec releaseSpec) => 600L; public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs index 495e5c91a59..c45262c0af3 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs @@ -30,7 +30,7 @@ private G2MSMPrecompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { int k = inputData.Length / ItemSize; - return 45000L * k * Discount.For(k) / 1000; + return 45000L * k * Discount.For(k, true) / 1000; } public const int ItemSize = 288; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs index fbe99e32867..bf849287a5d 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MulPrecompile.cs @@ -23,7 +23,7 @@ private G2MulPrecompile() public static Address Address { get; } = Address.FromNumber(0x0f); - public long BaseGasCost(IReleaseSpec releaseSpec) => 45000L; + public long BaseGasCost(IReleaseSpec releaseSpec) => 22500L; public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs index 5190c58be57..28a365e9b1c 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs @@ -23,7 +23,7 @@ private MapFp2ToG2Precompile() public static Address Address { get; } = Address.FromNumber(0x13); - public long BaseGasCost(IReleaseSpec releaseSpec) => 75000; + public long BaseGasCost(IReleaseSpec releaseSpec) => 17000; public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs index eb1032ea1f5..2818449b970 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs @@ -22,7 +22,7 @@ private MapFpToG1Precompile() public static Address Address { get; } = Address.FromNumber(0x12); - public long BaseGasCost(IReleaseSpec releaseSpec) => 5500L; + public long BaseGasCost(IReleaseSpec releaseSpec) => 4125L; public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs index 6be90e9054a..ad82b319f56 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs @@ -25,9 +25,9 @@ private PairingCheckPrecompile() { } public static Address Address { get; } = Address.FromNumber(0x11); - public long BaseGasCost(IReleaseSpec releaseSpec) => 65000L; + public long BaseGasCost(IReleaseSpec releaseSpec) => 78000L; - public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 43000L * (inputData.Length / PairSize); + public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 51600L * (inputData.Length / PairSize); [SkipLocalsInit] public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) From aa4a2c895c9021bea5006ee55ccdaec415041c03 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 11 Dec 2024 19:49:20 +1100 Subject: [PATCH 2/8] fix whitespace --- src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs index 5b3abad3059..7333b59e721 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs @@ -20,7 +20,7 @@ internal static class Discount private const int _maxDiscountG1 = 435; private const int _maxDiscountG2 = 696; - private static readonly (int g1, int g2)[] _discountTable = + private static readonly (int g1, int g2)[] _discountTable = { (0, 0), // 0 (1800, 1800), // 1 From 7fe16a6a2bbe9a63d6ff0968fedb26cbc53dd855 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 11 Dec 2024 20:18:39 +1100 Subject: [PATCH 3/8] clean code --- src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs | 7 ++----- .../Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs | 2 +- .../Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs index 7333b59e721..42184056056 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs @@ -11,11 +11,8 @@ namespace Nethermind.Evm.Precompiles.Bls /// internal static class Discount { - public static int For(int k, bool isG2) => k switch - { - var x when x >= 128 => isG2 ? _maxDiscountG2 : _maxDiscountG1, - _ => isG2 ? _discountTable[k].g2 : _discountTable[k].g1 - }; + public static int ForG1(int k) => k >= 128 ? _maxDiscountG1 : _discountTable[k].g1; + public static int ForG2(int k) => k >= 128 ? _maxDiscountG2 : _discountTable[k].g2; private const int _maxDiscountG1 = 435; private const int _maxDiscountG2 = 696; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs index fc0c926c270..c6a4b3e6d97 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G1MSMPrecompile.cs @@ -30,7 +30,7 @@ private G1MSMPrecompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { int k = inputData.Length / ItemSize; - return 12000L * k * Discount.For(k, false) / 1000; + return 12000L * k * Discount.ForG1(k) / 1000; } public const int ItemSize = 160; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs index c45262c0af3..2edbb0b5246 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/G2MSMPrecompile.cs @@ -30,7 +30,7 @@ private G2MSMPrecompile() public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) { int k = inputData.Length / ItemSize; - return 45000L * k * Discount.For(k, true) / 1000; + return 45000L * k * Discount.ForG2(k) / 1000; } public const int ItemSize = 288; From 1928badf35bc76bbc0d26f0bfc033c53f086a227 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Wed, 11 Dec 2024 20:21:19 +1100 Subject: [PATCH 4/8] explicit long --- .../Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs index 28a365e9b1c..24c7848653c 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs @@ -23,7 +23,7 @@ private MapFp2ToG2Precompile() public static Address Address { get; } = Address.FromNumber(0x13); - public long BaseGasCost(IReleaseSpec releaseSpec) => 17000; + public long BaseGasCost(IReleaseSpec releaseSpec) => 17000L; public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; From c90092145ea3f3d2d20bd58718eb59ca867cf4aa Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Thu, 12 Dec 2024 14:14:50 +1100 Subject: [PATCH 5/8] update mapping precompiles cost --- .../Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs | 2 +- .../Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs index 24c7848653c..04827c9e46d 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFp2ToG2Precompile.cs @@ -23,7 +23,7 @@ private MapFp2ToG2Precompile() public static Address Address { get; } = Address.FromNumber(0x13); - public long BaseGasCost(IReleaseSpec releaseSpec) => 17000L; + public long BaseGasCost(IReleaseSpec releaseSpec) => 23800L; public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs index 2818449b970..eb1032ea1f5 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/MapFpToG1Precompile.cs @@ -22,7 +22,7 @@ private MapFpToG1Precompile() public static Address Address { get; } = Address.FromNumber(0x12); - public long BaseGasCost(IReleaseSpec releaseSpec) => 4125L; + public long BaseGasCost(IReleaseSpec releaseSpec) => 5500L; public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 0L; From 767809f1a4a10e516141699e1a3ebb234cc3f5ac Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Fri, 13 Dec 2024 17:27:42 +1100 Subject: [PATCH 6/8] update discounts to pawel suggestion --- .../Precompiles/Bls/Discount.cs | 260 +++++++++--------- 1 file changed, 130 insertions(+), 130 deletions(-) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs index 42184056056..f3937f00661 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs @@ -14,140 +14,140 @@ internal static class Discount public static int ForG1(int k) => k >= 128 ? _maxDiscountG1 : _discountTable[k].g1; public static int ForG2(int k) => k >= 128 ? _maxDiscountG2 : _discountTable[k].g2; - private const int _maxDiscountG1 = 435; - private const int _maxDiscountG2 = 696; + private const int _maxDiscountG1 = 519; + private const int _maxDiscountG2 = 524; private static readonly (int g1, int g2)[] _discountTable = { (0, 0), // 0 - (1800, 1800), // 1 - (888, 1776), // 2 - (955, 1528), // 3 - (802, 1282), // 4 - (743, 1188), // 5 - (821, 1368), // 6 - (750, 1250), // 7 - (680, 1133), // 8 - (657, 1095), // 9 - (635, 1269), // 10 - (612, 1224), // 11 - (591, 1182), // 12 - (664, 1137), // 13 - (637, 1274), // 14 - (611, 1222), // 15 - (585, 1169), // 16 - (578, 1155), // 17 - (571, 1141), // 18 - (564, 1127), // 19 - (557, 1113), // 20 - (628, 1256), // 21 - (620, 1240), // 22 - (612, 1224), // 23 - (604, 1208), // 24 - (596, 1192), // 25 - (588, 1176), // 26 - (578, 1156), // 27 - (570, 1140), // 28 - (562, 1124), // 29 - (693, 1108), // 30 - (683, 1092), // 31 - (673, 1076), // 32 - (670, 1072), // 33 - (665, 1064), // 34 - (663, 1060), // 35 - (658, 1052), // 36 - (655, 1048), // 37 - (650, 1040), // 38 - (648, 1036), // 39 - (643, 1028), // 40 - (640, 1024), // 41 - (635, 1016), // 42 - (633, 1012), // 43 - (628, 1004), // 44 - (625, 1000), // 45 - (620, 992), // 46 - (618, 988), // 47 - (613, 980), // 48 - (610, 976), // 49 - (605, 968), // 50 - (603, 964), // 51 - (598, 956), // 52 - (595, 952), // 53 - (590, 944), // 54 - (588, 940), // 55 - (583, 932), // 56 - (580, 928), // 57 - (578, 924), // 58 - (573, 916), // 59 - (570, 912), // 60 - (565, 904), // 61 - (563, 900), // 62 - (558, 892), // 63 - (555, 888), // 64 - (553, 884), // 65 - (550, 880), // 66 - (548, 876), // 67 - (548, 876), // 68 - (545, 872), // 69 - (543, 868), // 70 - (540, 864), // 71 - (540, 864), // 72 - (538, 860), // 73 - (535, 856), // 74 - (533, 852), // 75 - (533, 852), // 76 - (530, 848), // 77 - (528, 844), // 78 - (528, 844), // 79 - (525, 840), // 80 - (523, 836), // 81 - (520, 832), // 82 - (520, 832), // 83 - (518, 828), // 84 - (515, 824), // 85 - (513, 820), // 86 - (513, 820), // 87 - (510, 816), // 88 - (508, 812), // 89 - (505, 808), // 90 - (505, 808), // 91 - (503, 804), // 92 - (500, 800), // 93 - (498, 796), // 94 - (498, 796), // 95 - (495, 792), // 96 - (493, 788), // 97 - (490, 784), // 98 - (490, 784), // 99 - (488, 780), // 100 - (485, 776), // 101 - (483, 772), // 102 - (483, 772), // 103 - (480, 768), // 104 - (478, 764), // 105 - (478, 764), // 106 - (475, 760), // 107 - (473, 756), // 108 - (470, 752), // 109 - (470, 752), // 110 - (468, 748), // 111 - (465, 744), // 112 - (463, 740), // 113 - (463, 740), // 114 - (460, 736), // 115 - (458, 732), // 116 - (455, 728), // 117 - (455, 728), // 118 - (453, 724), // 119 - (450, 720), // 120 - (448, 716), // 121 - (448, 716), // 122 - (445, 712), // 123 - (443, 708), // 124 - (440, 704), // 125 - (440, 704), // 126 - (438, 700), // 127 - (435, 696) // 128 + (1000, 1000), // 1 + (949, 1000), // 2 + (848, 923), // 3 + (797, 884), // 4 + (764, 855), // 5 + (750, 832), // 6 + (738, 812), // 7 + (728, 796), // 8 + (719, 782), // 9 + (712, 770), // 10 + (705, 759), // 11 + (698, 749), // 12 + (692, 740), // 13 + (687, 732), // 14 + (682, 724), // 15 + (677, 717), // 16 + (673, 711), // 17 + (669, 704), // 18 + (665, 699), // 19 + (661, 693), // 20 + (658, 688), // 21 + (654, 683), // 22 + (651, 679), // 23 + (648, 674), // 24 + (645, 670), // 25 + (642, 666), // 26 + (640, 659), // 27 + (637, 655), // 28 + (635, 652), // 29 + (632, 649), // 30 + (630, 646), // 31 + (627, 643), // 32 + (625, 640), // 33 + (623, 637), // 34 + (621, 634), // 35 + (619, 632), // 36 + (617, 629), // 37 + (615, 627), // 38 + (613, 624), // 39 + (611, 622), // 40 + (609, 620), // 41 + (608, 618), // 42 + (606, 615), // 43 + (604, 613), // 44 + (603, 611), // 45 + (601, 609), // 46 + (599, 606), // 47 + (598, 604), // 48 + (596, 602), // 49 + (595, 600), // 50 + (593, 598), // 51 + (592, 597), // 52 + (591, 595), // 53 + (589, 593), // 54 + (588, 592), // 55 + (586, 590), // 56 + (585, 589), // 57 + (584, 587), // 58 + (582, 586), // 59 + (581, 584), // 60 + (580, 583), // 61 + (579, 582), // 62 + (577, 580), // 63 + (576, 579), // 64 + (575, 578), // 65 + (574, 576), // 66 + (573, 575), // 67 + (572, 574), // 68 + (570, 573), // 69 + (569, 571), // 70 + (568, 570), // 71 + (567, 569), // 72 + (566, 568), // 73 + (565, 567), // 74 + (564, 566), // 75 + (563, 565), // 76 + (562, 563), // 77 + (561, 562), // 78 + (560, 561), // 79 + (559, 560), // 80 + (558, 559), // 81 + (557, 558), // 82 + (556, 557), // 83 + (555, 556), // 84 + (554, 555), // 85 + (553, 554), // 86 + (552, 553), // 87 + (551, 552), // 88 + (550, 552), // 89 + (549, 551), // 90 + (548, 550), // 91 + (547, 549), // 92 + (547, 548), // 93 + (546, 547), // 94 + (545, 546), // 95 + (544, 545), // 96 + (543, 545), // 97 + (542, 544), // 98 + (541, 543), // 99 + (540, 543), // 100 + (540, 542), // 101 + (539, 541), // 102 + (538, 541), // 103 + (537, 540), // 104 + (536, 539), // 105 + (536, 538), // 106 + (535, 537), // 107 + (534, 537), // 108 + (533, 536), // 109 + (532, 535), // 110 + (532, 535), // 111 + (531, 534), // 112 + (530, 533), // 113 + (529, 532), // 114 + (528, 532), // 115 + (528, 531), // 116 + (527, 530), // 117 + (526, 530), // 118 + (525, 529), // 119 + (525, 528), // 120 + (524, 528), // 121 + (523, 527), // 122 + (522, 527), // 123 + (522, 526), // 124 + (521, 526), // 125 + (520, 525), // 126 + (520, 525), // 127 + (519, 524) // 128 }; } } From a178269449d76d9d0b47b95a4f623d99e236bac6 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Fri, 13 Dec 2024 17:43:49 +1100 Subject: [PATCH 7/8] fix discount table --- .../Precompiles/Bls/Discount.cs | 182 +++++++++--------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs index f3937f00661..f0031fe0227 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/Discount.cs @@ -46,107 +46,107 @@ private static readonly (int g1, int g2)[] _discountTable = (648, 674), // 24 (645, 670), // 25 (642, 666), // 26 - (640, 659), // 27 - (637, 655), // 28 - (635, 652), // 29 - (632, 649), // 30 - (630, 646), // 31 - (627, 643), // 32 - (625, 640), // 33 - (623, 637), // 34 - (621, 634), // 35 - (619, 632), // 36 - (617, 629), // 37 - (615, 627), // 38 - (613, 624), // 39 - (611, 622), // 40 - (609, 620), // 41 - (608, 618), // 42 - (606, 615), // 43 - (604, 613), // 44 - (603, 611), // 45 - (601, 609), // 46 - (599, 606), // 47 - (598, 604), // 48 - (596, 602), // 49 - (595, 600), // 50 - (593, 598), // 51 - (592, 597), // 52 - (591, 595), // 53 - (589, 593), // 54 - (588, 592), // 55 - (586, 590), // 56 - (585, 589), // 57 - (584, 587), // 58 - (582, 586), // 59 - (581, 584), // 60 - (580, 583), // 61 - (579, 582), // 62 - (577, 580), // 63 - (576, 579), // 64 - (575, 578), // 65 - (574, 576), // 66 - (573, 575), // 67 - (572, 574), // 68 - (570, 573), // 69 - (569, 571), // 70 - (568, 570), // 71 - (567, 569), // 72 - (566, 568), // 73 - (565, 567), // 74 - (564, 566), // 75 - (563, 565), // 76 - (562, 563), // 77 - (561, 562), // 78 - (560, 561), // 79 - (559, 560), // 80 - (558, 559), // 81 - (557, 558), // 82 - (556, 557), // 83 - (555, 556), // 84 - (554, 555), // 85 - (553, 554), // 86 - (552, 553), // 87 - (551, 552), // 88 - (550, 552), // 89 - (549, 551), // 90 - (548, 550), // 91 - (547, 549), // 92 - (547, 548), // 93 - (546, 547), // 94 - (545, 546), // 95 - (544, 545), // 96 - (543, 545), // 97 - (542, 544), // 98 - (541, 543), // 99 - (540, 543), // 100 - (540, 542), // 101 - (539, 541), // 102 + (640, 663), // 27 + (637, 659), // 28 + (635, 655), // 29 + (632, 652), // 30 + (630, 649), // 31 + (627, 646), // 32 + (625, 643), // 33 + (623, 640), // 34 + (621, 637), // 35 + (619, 634), // 36 + (617, 632), // 37 + (615, 629), // 38 + (613, 627), // 39 + (611, 624), // 40 + (609, 622), // 41 + (608, 620), // 42 + (606, 618), // 43 + (604, 615), // 44 + (603, 613), // 45 + (601, 611), // 46 + (599, 609), // 47 + (598, 607), // 48 + (596, 606), // 49 + (595, 604), // 50 + (593, 602), // 51 + (592, 600), // 52 + (591, 598), // 53 + (589, 597), // 54 + (588, 595), // 55 + (586, 593), // 56 + (585, 592), // 57 + (584, 590), // 58 + (582, 589), // 59 + (581, 587), // 60 + (580, 586), // 61 + (579, 584), // 62 + (577, 583), // 63 + (576, 582), // 64 + (575, 580), // 65 + (574, 579), // 66 + (573, 578), // 67 + (572, 576), // 68 + (570, 575), // 69 + (569, 574), // 70 + (568, 573), // 71 + (567, 571), // 72 + (566, 570), // 73 + (565, 569), // 74 + (564, 568), // 75 + (563, 567), // 76 + (562, 566), // 77 + (561, 565), // 78 + (560, 563), // 79 + (559, 562), // 80 + (558, 561), // 81 + (557, 560), // 82 + (556, 559), // 83 + (555, 558), // 84 + (554, 557), // 85 + (553, 556), // 86 + (552, 555), // 87 + (551, 554), // 88 + (550, 553), // 89 + (549, 552), // 90 + (548, 552), // 91 + (547, 551), // 92 + (547, 550), // 93 + (546, 549), // 94 + (545, 548), // 95 + (544, 547), // 96 + (543, 546), // 97 + (542, 545), // 98 + (541, 545), // 99 + (540, 544), // 100 + (540, 543), // 101 + (539, 542), // 102 (538, 541), // 103 - (537, 540), // 104 - (536, 539), // 105 - (536, 538), // 106 - (535, 537), // 107 + (537, 541), // 104 + (536, 540), // 105 + (536, 539), // 106 + (535, 538), // 107 (534, 537), // 108 - (533, 536), // 109 - (532, 535), // 110 + (533, 537), // 109 + (532, 536), // 110 (532, 535), // 111 - (531, 534), // 112 - (530, 533), // 113 - (529, 532), // 114 + (531, 535), // 112 + (530, 534), // 113 + (529, 533), // 114 (528, 532), // 115 - (528, 531), // 116 - (527, 530), // 117 + (528, 532), // 116 + (527, 531), // 117 (526, 530), // 118 - (525, 529), // 119 - (525, 528), // 120 + (525, 530), // 119 + (525, 529), // 120 (524, 528), // 121 - (523, 527), // 122 + (523, 528), // 122 (522, 527), // 123 (522, 526), // 124 (521, 526), // 125 (520, 525), // 126 - (520, 525), // 127 + (520, 524), // 127 (519, 524) // 128 }; } From 55758282ebc9fb8a47b3d22db6e98d13f37139f6 Mon Sep 17 00:00:00 2001 From: Marc Harvey-Hill Date: Mon, 16 Dec 2024 12:33:39 +1100 Subject: [PATCH 8/8] change pairing cost --- .../Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs index f462c0cb97a..8fcfe13bd8f 100644 --- a/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs +++ b/src/Nethermind/Nethermind.Evm/Precompiles/Bls/PairingCheckPrecompile.cs @@ -25,9 +25,9 @@ private PairingCheckPrecompile() { } public static Address Address { get; } = Address.FromNumber(0x11); - public long BaseGasCost(IReleaseSpec releaseSpec) => 78000L; + public long BaseGasCost(IReleaseSpec releaseSpec) => 37698L; - public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 51600L * (inputData.Length / PairSize); + public long DataGasCost(ReadOnlyMemory inputData, IReleaseSpec releaseSpec) => 32587L * (inputData.Length / PairSize); [SkipLocalsInit] public (ReadOnlyMemory, bool) Run(ReadOnlyMemory inputData, IReleaseSpec releaseSpec)