add g1_multi_exp

This commit is contained in:
Kevaundray Wedderburn 2024-04-23 12:44:50 +01:00
parent e51f7df77d
commit 640675f628
2 changed files with 21 additions and 3 deletions

View File

@ -277,9 +277,10 @@ def g1_lincomb(points: Sequence[KZGCommitment], scalars: Sequence[BLSFieldElemen
BLS multiscalar multiplication. This function can be optimized using Pippenger's algorithm and variants.
"""
assert len(points) == len(scalars)
result = bls.Z1()
for x, a in zip(points, scalars):
result = bls.add(result, bls.multiply(bls.bytes48_to_G1(x), a))
points_g1 = []
for point in points:
points_g1.append(bls.bytes48_to_G1(point))
result = bls.g1_multi_exp(points_g1,scalars)
return KZGCommitment(bls.G1_to_bytes48(result))
```

View File

@ -224,6 +224,23 @@ 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:
int_as_bytes = integer.to_bytes(32, 'little')
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):
result = add(result, multiply(point, scalar))
return result
def neg(point):
"""