add is_zero check

This commit is contained in:
Kevaundray Wedderburn 2024-04-23 14:55:37 +01:00
parent 274d013d5c
commit d28a0164d2
2 changed files with 10 additions and 0 deletions

View File

@ -133,9 +133,14 @@ def g2_lincomb(points: Sequence[G2Point], scalars: Sequence[BLSFieldElement]) ->
BLS multiscalar multiplication in G2. This can be naively implemented using double-and-add.
"""
assert len(points) == len(scalars)
if len(points) == 0:
return bls.Z2()
points_g2 = []
for point in points:
points_g2.append(bls.bytes96_to_G2(point))
result = bls.multi_exp(points_g2, scalars)
return Bytes96(bls.G2_to_bytes96(result))
```

View File

@ -277,9 +277,14 @@ def g1_lincomb(points: Sequence[KZGCommitment], scalars: Sequence[BLSFieldElemen
BLS multiscalar multiplication in G1. This can be naively implemented using double-and-add.
"""
assert len(points) == len(scalars)
if len(points) == 0:
return bls.Z1()
points_g1 = []
for point in points:
points_g1.append(bls.bytes48_to_G1(point))
result = bls.multi_exp(points_g1, scalars)
return KZGCommitment(bls.G1_to_bytes48(result))
```