Skip to content

Commit

Permalink
add g1_multi_exp
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray committed Apr 23, 2024
1 parent e51f7df commit 640675f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 4 additions & 3 deletions specs/deneb/polynomial-commitments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
```

Expand Down
17 changes: 17 additions & 0 deletions tests/core/pyspec/eth2spec/utils/bls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit 640675f

Please sign in to comment.