From ee878efee9732e3066600f80000c422959cd1901 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Thu, 12 Dec 2024 12:29:29 -0800 Subject: [PATCH] use non parallel impl of g1 and g2 msm for values of k = 1 Signed-off-by: garyschulte --- .../besu/nativelib/gnark/LibGnarkEIP2537.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkEIP2537.java b/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkEIP2537.java index 6d21a068..176ce8e3 100644 --- a/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkEIP2537.java +++ b/gnark/src/main/java/org/hyperledger/besu/nativelib/gnark/LibGnarkEIP2537.java @@ -64,11 +64,15 @@ public static int eip2537_perform_operation( o_len.setValue(128); break; case BLS12_G1MULTIEXP_OPERATION_SHIM_VALUE: - ret = eip2537blsG1MultiExpParallel(i, output, err, i_len, - EIP2537_PREALLOCATE_FOR_RESULT_BYTES, - EIP2537_PREALLOCATE_FOR_ERROR_BYTES, - degreeOfMSMParallelism); - o_len.setValue(128); + if (i.length <= 192) { + ret = eip2537blsG1MultiExp(i, output, err, i_len, + EIP2537_PREALLOCATE_FOR_RESULT_BYTES, EIP2537_PREALLOCATE_FOR_ERROR_BYTES); + } else { + ret = eip2537blsG1MultiExpParallel(i, output, err, i_len, + EIP2537_PREALLOCATE_FOR_RESULT_BYTES, EIP2537_PREALLOCATE_FOR_ERROR_BYTES, + degreeOfMSMParallelism); + o_len.setValue(128); + } break; case BLS12_G2ADD_OPERATION_SHIM_VALUE: ret = eip2537blsG2Add(i, output, err, i_len, @@ -83,11 +87,16 @@ public static int eip2537_perform_operation( o_len.setValue(256); break; case BLS12_G2MULTIEXP_OPERATION_SHIM_VALUE: - ret = eip2537blsG2MultiExpParallel(i, output, err, i_len, - EIP2537_PREALLOCATE_FOR_RESULT_BYTES, - EIP2537_PREALLOCATE_FOR_ERROR_BYTES, - degreeOfMSMParallelism); - o_len.setValue(256); + if (i.length <= 288) { + ret = eip2537blsG2MultiExp(i, output, err, i_len, + EIP2537_PREALLOCATE_FOR_RESULT_BYTES, + EIP2537_PREALLOCATE_FOR_ERROR_BYTES); + } else { + ret = eip2537blsG2MultiExpParallel(i, output, err, i_len, + EIP2537_PREALLOCATE_FOR_RESULT_BYTES, EIP2537_PREALLOCATE_FOR_ERROR_BYTES, + degreeOfMSMParallelism); + o_len.setValue(256); + } break; case BLS12_PAIR_OPERATION_SHIM_VALUE: ret = eip2537blsPairing(i, output, err, i_len,