mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-20 15:38:55 +00:00
add g1_multi_exp
This commit is contained in:
parent
e51f7df77d
commit
640675f628
@ -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))
|
||||
```
|
||||
|
||||
|
@ -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):
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user