mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-20 23:49:54 +00:00
add g2_multi_exp and lint fixes
This commit is contained in:
parent
640675f628
commit
6aa950e1dd
@ -224,13 +224,13 @@ def multiply(point, scalar):
|
|||||||
return point * scalar
|
return point * scalar
|
||||||
return py_ecc_mul(point, scalar)
|
return py_ecc_mul(point, scalar)
|
||||||
|
|
||||||
|
|
||||||
def g1_multi_exp(points, integers):
|
def g1_multi_exp(points, integers):
|
||||||
"""
|
"""
|
||||||
Performs a multi-scalar multiplication between
|
Performs a multi-scalar multiplication between
|
||||||
`points` and `scalars`.
|
`points` and `scalars`.
|
||||||
`point` should be in G1
|
`point` should be in G1
|
||||||
"""
|
"""
|
||||||
assert(len(points) == len(integers))
|
|
||||||
if bls == arkworks_bls or bls == fastest_bls:
|
if bls == arkworks_bls or bls == fastest_bls:
|
||||||
scalars = []
|
scalars = []
|
||||||
for integer in integers:
|
for integer in integers:
|
||||||
@ -238,10 +238,30 @@ def g1_multi_exp(points, integers):
|
|||||||
scalars.append(arkworks_Scalar.from_le_bytes(int_as_bytes))
|
scalars.append(arkworks_Scalar.from_le_bytes(int_as_bytes))
|
||||||
return arkworks_G1.multiexp_unchecked(points, scalars)
|
return arkworks_G1.multiexp_unchecked(points, scalars)
|
||||||
result = Z1()
|
result = Z1()
|
||||||
for point,scalar in points.zip(scalars):
|
for point, scalar in points.zip(integers):
|
||||||
result = add(result, multiply(point, scalar))
|
result = add(result, multiply(point, scalar))
|
||||||
return result
|
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):
|
def neg(point):
|
||||||
"""
|
"""
|
||||||
Returns the point negation of `point`
|
Returns the point negation of `point`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user