From 6aa950e1dd5440f6831fad679de6113e2711d7f4 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 23 Apr 2024 13:38:04 +0100 Subject: [PATCH] add g2_multi_exp and lint fixes --- tests/core/pyspec/eth2spec/utils/bls.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/utils/bls.py b/tests/core/pyspec/eth2spec/utils/bls.py index 3a03623d3..45d40f7be 100644 --- a/tests/core/pyspec/eth2spec/utils/bls.py +++ b/tests/core/pyspec/eth2spec/utils/bls.py @@ -224,13 +224,13 @@ def multiply(point, scalar): return point * scalar return py_ecc_mul(point, scalar) + def g1_multi_exp(points, integers): """ Performs a multi-scalar multiplication between `points` and `scalars`. `point` should be in G1 """ - assert(len(points) == len(integers)) if bls == arkworks_bls or bls == fastest_bls: scalars = [] for integer in integers: @@ -238,10 +238,30 @@ def g1_multi_exp(points, integers): scalars.append(arkworks_Scalar.from_le_bytes(int_as_bytes)) return arkworks_G1.multiexp_unchecked(points, scalars) result = Z1() - for point,scalar in points.zip(scalars): + for point, scalar in points.zip(integers): result = add(result, multiply(point, scalar)) return result + +# TODO: Duplicated code for now +def g2_multi_exp(points, integers): + """ + Performs a multi-scalar multiplication between + `points` and `scalars`. + `point` should be in G2 + """ + if bls == arkworks_bls or bls == fastest_bls: + scalars = [] + for integer in integers: + int_as_bytes = integer.to_bytes(32, 'little') + scalars.append(arkworks_Scalar.from_le_bytes(int_as_bytes)) + return arkworks_G2.multiexp_unchecked(points, scalars) + result = Z2() + for point, scalar in points.zip(integers): + result = add(result, multiply(point, scalar)) + return result + + def neg(point): """ Returns the point negation of `point`