14
14
*/
15
15
package org .hyperledger .besu .evmtool .benchmarks ;
16
16
17
+ import org .hyperledger .besu .datatypes .Address ;
17
18
import org .hyperledger .besu .evm .EvmSpecVersion ;
19
+ import org .hyperledger .besu .evm .fluent .EvmSpec ;
18
20
import org .hyperledger .besu .evm .precompile .AbstractBLS12PrecompiledContract ;
19
- import org .hyperledger .besu .evm .precompile .BLS12G1AddPrecompiledContract ;
20
- import org .hyperledger .besu .evm .precompile .BLS12G1MultiExpPrecompiledContract ;
21
- import org .hyperledger .besu .evm .precompile .BLS12G2AddPrecompiledContract ;
22
- import org .hyperledger .besu .evm .precompile .BLS12G2MultiExpPrecompiledContract ;
23
- import org .hyperledger .besu .evm .precompile .BLS12MapFp2ToG2PrecompiledContract ;
24
- import org .hyperledger .besu .evm .precompile .BLS12MapFpToG1PrecompiledContract ;
25
- import org .hyperledger .besu .evm .precompile .BLS12PairingPrecompiledContract ;
21
+ import org .hyperledger .besu .evm .precompile .PrecompiledContract ;
26
22
27
23
import java .io .PrintStream ;
28
24
import java .util .LinkedHashMap ;
@@ -167,22 +163,23 @@ public void runBenchmark(final Boolean attemptNative, final String fork) {
167
163
return ;
168
164
}
169
165
170
- benchmarkG1Add (output );
171
- benchmarkG1MultiExp32Pairs (output );
172
- benchmarkMapFpToG1 (output );
173
- benchmarkG2Add (output );
174
- benchmarkG2MultiExp32Pairs (output );
175
- benchmarkMapFp2ToG2 (output );
176
- benchmarkBlsPairing (output );
166
+ benchmarkG1Add (output , forkVersion );
167
+ benchmarkG1MultiExp32Pairs (output , forkVersion );
168
+ benchmarkMapFpToG1 (output , forkVersion );
169
+ benchmarkG2Add (output , forkVersion );
170
+ benchmarkG2MultiExp32Pairs (output , forkVersion );
171
+ benchmarkMapFp2ToG2 (output , forkVersion );
172
+ benchmarkBlsPairing (output , forkVersion );
177
173
}
178
174
179
- private void benchmarkG1Add (final PrintStream output ) {
175
+ private void benchmarkG1Add (final PrintStream output , final EvmSpecVersion forkVersion ) {
180
176
final Map <String , Bytes > testCases = new LinkedHashMap <>();
181
177
for (int i = 0 ; i < g1PointPairs .length - 1 ; i ++) {
182
178
testCases .put ("G1 Add " + i , Bytes .fromHexString (g1PointPairs [i ] + g1PointPairs [i + 1 ]));
183
179
}
184
180
185
- BLS12G1AddPrecompiledContract g1addContract = new BLS12G1AddPrecompiledContract ();
181
+ PrecompiledContract g1addContract =
182
+ EvmSpec .evmSpec (forkVersion ).getPrecompileContractRegistry ().get (Address .BLS12_G1ADD );
186
183
warmIterations = MATH_WARMUP / testCases .size ();
187
184
execIterations = MATH_ITERATIONS / testCases .size ();
188
185
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
@@ -198,7 +195,8 @@ private void benchmarkG1Add(final PrintStream output) {
198
195
gasCost , execTime * 1_000_000 , gasCost / execTime / 1_000_000 );
199
196
}
200
197
201
- private void benchmarkG1MultiExp32Pairs (final PrintStream output ) {
198
+ private void benchmarkG1MultiExp32Pairs (
199
+ final PrintStream output , final EvmSpecVersion forkVersion ) {
202
200
final Map <String , Bytes > testCases = new LinkedHashMap <>();
203
201
204
202
// add test cases for 2, 4, 8, 16, and 32 point/scalar pairs
@@ -210,7 +208,8 @@ private void benchmarkG1MultiExp32Pairs(final PrintStream output) {
210
208
testCases .put ("G1 MSM " + (1 << i ) + " pairs" , Bytes .fromHexString (g1msmPairs .toString ()));
211
209
}
212
210
213
- BLS12G1MultiExpPrecompiledContract g1msmContract = new BLS12G1MultiExpPrecompiledContract ();
211
+ PrecompiledContract g1msmContract =
212
+ EvmSpec .evmSpec (forkVersion ).getPrecompileContractRegistry ().get (Address .BLS12_G1MULTIEXP );
214
213
warmIterations = MATH_WARMUP / testCases .size ();
215
214
execIterations = MATH_ITERATIONS / testCases .size ();
216
215
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
@@ -224,13 +223,16 @@ private void benchmarkG1MultiExp32Pairs(final PrintStream output) {
224
223
gasCost , execTime * 1_000_000 , gasCost / execTime / 1_000_000 );
225
224
}
226
225
227
- private void benchmarkMapFpToG1 (final PrintStream output ) {
226
+ private void benchmarkMapFpToG1 (final PrintStream output , final EvmSpecVersion forkVersion ) {
228
227
final Map <String , Bytes > testCases = new LinkedHashMap <>();
229
228
for (int i = 0 ; i < g1PointPairs .length ; i ++) {
230
229
testCases .put ("Map Fp to G1 " + i , Bytes .fromHexString (g1PointPairs [i ].substring (0 , 128 )));
231
230
}
232
231
233
- BLS12MapFpToG1PrecompiledContract g1MapFpToG1Contract = new BLS12MapFpToG1PrecompiledContract ();
232
+ PrecompiledContract g1MapFpToG1Contract =
233
+ EvmSpec .evmSpec (forkVersion )
234
+ .getPrecompileContractRegistry ()
235
+ .get (Address .BLS12_MAP_FP_TO_G1 );
234
236
warmIterations = MATH_WARMUP / testCases .size ();
235
237
execIterations = MATH_ITERATIONS / testCases .size ();
236
238
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
@@ -247,13 +249,14 @@ private void benchmarkMapFpToG1(final PrintStream output) {
247
249
gasCost , execTime * 1_000_000 , gasCost / execTime / 1_000_000 );
248
250
}
249
251
250
- private void benchmarkG2Add (final PrintStream output ) {
252
+ private void benchmarkG2Add (final PrintStream output , final EvmSpecVersion forkVersion ) {
251
253
final Map <String , Bytes > testCases = new LinkedHashMap <>();
252
254
for (int i = 0 ; i < g2PointPairs .length - 1 ; i ++) {
253
255
testCases .put ("G2 Add " + i , Bytes .fromHexString (g2PointPairs [i ] + g2PointPairs [i + 1 ]));
254
256
}
255
257
256
- BLS12G2AddPrecompiledContract g1addContract = new BLS12G2AddPrecompiledContract ();
258
+ PrecompiledContract g1addContract =
259
+ EvmSpec .evmSpec (forkVersion ).getPrecompileContractRegistry ().get (Address .BLS12_G2ADD );
257
260
warmIterations = MATH_WARMUP / testCases .size ();
258
261
execIterations = MATH_ITERATIONS / testCases .size ();
259
262
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
@@ -269,7 +272,8 @@ private void benchmarkG2Add(final PrintStream output) {
269
272
gasCost , execTime * 1_000_000 , gasCost / execTime / 1_000_000 );
270
273
}
271
274
272
- private void benchmarkG2MultiExp32Pairs (final PrintStream output ) {
275
+ private void benchmarkG2MultiExp32Pairs (
276
+ final PrintStream output , final EvmSpecVersion forkVersion ) {
273
277
final Map <String , Bytes > testCases = new LinkedHashMap <>();
274
278
275
279
// add test cases for 2, 4, 8, 16, and 32 point/scalar pairs
@@ -281,7 +285,8 @@ private void benchmarkG2MultiExp32Pairs(final PrintStream output) {
281
285
testCases .put ("G2 MSM " + (1 << i ) + " pairs" , Bytes .fromHexString (g2msmPairs .toString ()));
282
286
}
283
287
284
- BLS12G2MultiExpPrecompiledContract g2msmContract = new BLS12G2MultiExpPrecompiledContract ();
288
+ PrecompiledContract g2msmContract =
289
+ EvmSpec .evmSpec (forkVersion ).getPrecompileContractRegistry ().get (Address .BLS12_G2MULTIEXP );
285
290
warmIterations = MATH_WARMUP / testCases .size ();
286
291
execIterations = MATH_ITERATIONS / testCases .size ();
287
292
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
@@ -295,14 +300,16 @@ private void benchmarkG2MultiExp32Pairs(final PrintStream output) {
295
300
gasCost , execTime * 1_000_000 , gasCost / execTime / 1_000_000 );
296
301
}
297
302
298
- private void benchmarkMapFp2ToG2 (final PrintStream output ) {
303
+ private void benchmarkMapFp2ToG2 (final PrintStream output , final EvmSpecVersion forkVersion ) {
299
304
final Map <String , Bytes > testCases = new LinkedHashMap <>();
300
305
for (int i = 0 ; i < g2PointPairs .length ; i ++) {
301
306
testCases .put ("Map Fp2 to G2 " + i , Bytes .fromHexString (g2PointPairs [i ].substring (0 , 256 )));
302
307
}
303
308
304
- BLS12MapFp2ToG2PrecompiledContract g1MapFp2ToG2Contract =
305
- new BLS12MapFp2ToG2PrecompiledContract ();
309
+ PrecompiledContract g1MapFp2ToG2Contract =
310
+ EvmSpec .evmSpec (forkVersion )
311
+ .getPrecompileContractRegistry ()
312
+ .get (Address .BLS12_MAP_FP2_TO_G2 );
306
313
warmIterations = MATH_WARMUP / testCases .size ();
307
314
execIterations = MATH_ITERATIONS / testCases .size ();
308
315
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
@@ -319,7 +326,7 @@ private void benchmarkMapFp2ToG2(final PrintStream output) {
319
326
gasCost , execTime * 1_000_000 , gasCost / execTime / 1_000_000 );
320
327
}
321
328
322
- private void benchmarkBlsPairing (final PrintStream output ) {
329
+ private void benchmarkBlsPairing (final PrintStream output , final EvmSpecVersion forkVersion ) {
323
330
final Map <String , Bytes > testCases = new LinkedHashMap <>();
324
331
325
332
// add test cases for 2, 4, 8, 16, and 32 point/scalar pairs
@@ -331,7 +338,8 @@ private void benchmarkBlsPairing(final PrintStream output) {
331
338
testCases .put ("BLS Pairing " + (1 << i ) + " pairs" , Bytes .fromHexString (pairs .toString ()));
332
339
}
333
340
334
- BLS12PairingPrecompiledContract blsPairingContract = new BLS12PairingPrecompiledContract ();
341
+ PrecompiledContract blsPairingContract =
342
+ EvmSpec .evmSpec (forkVersion ).getPrecompileContractRegistry ().get (Address .BLS12_PAIRING );
335
343
warmIterations = MATH_WARMUP / testCases .size ();
336
344
execIterations = MATH_ITERATIONS / testCases .size ();
337
345
double execTime = Double .MIN_VALUE ; // a way to dodge divide by zero
0 commit comments