Skip to content

Commit 2dc72ea

Browse files
fix: correct bug in the deserialise method in EllipticCurve
- add references to MNT4_753 parameters - add references for serialisation/deserialisation methods
1 parent d0c8525 commit 2dc72ea

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

elliptic_curves/instantiations/mnt4_753/parameters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Curve parameters ------------------------------------------------------------------------------------------------------
2+
# Taken from [https://github.com/arkworks-rs/curves/tree/master/mnt4_753/src/curves]
23

34
# Seed
45
u = -0x15474b1d641a3fd86dcbcee5dcda7fe51852c8cbe26e600733b714aa43c31a66b0344c4e2c428b07a7713041ba18000

elliptic_curves/models/curve.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, q, r, val_miller_loop, exp_miller_loop, h1, h2, curve, twiste
4343

4444
def deserialise_vk(self, serialised: list[bytes]):
4545
'''
46-
Deserialise the serialisation of a verifying key. This function is based on the deserialisation of VK in arkworks. [ref]
46+
Deserialise the serialisation of a verifying key. This function is based on the deserialisation of VK in arkworks. [https://github.com/arkworks-rs/groth16/blob/master/src/data_structures.rs#L32]
4747
4848
vk is a list of: alpha_g1, beta_g2, gamma_g2, delta_g2, gamma_abc_g1, and each element is serialised in turn
4949
alpha_g1 -> element in G1
@@ -87,7 +87,7 @@ def deserialise_vk(self, serialised: list[bytes]):
8787

8888
def deserialise_proof(self, serialised: list[bytes]):
8989
"""
90-
Function to deserialise a proof. This function is based on arkworks deserialisation of a proof. [ref]
90+
Function to deserialise a proof. This function is based on arkworks deserialisation of a proof. [https://github.com/arkworks-rs/groth16/blob/master/src/data_structures.rs#L9]
9191
9292
A proof is formed by: A, B, C, and each element is serialised in turn
9393
A, C -> elements in G1
@@ -118,7 +118,7 @@ def deserialise_proof(self, serialised: list[bytes]):
118118

119119
def prepare_groth16_proof(self, pub, proof, vk, miller_loop_type, denominator_elimination):
120120
"""
121-
Take a a list of public statements, a proof and a vk, returns the data needed to generate the unlocking script for the Groth16 Bitcoin Script verifier [ref]
121+
Take a a list of public statements, a proof and a vk, returns the data needed to generate the unlocking script for the Groth16 Bitcoin Script verifier [https://github.com/nchain-innovation/zkscript_package/blob/main/zkscript/groth16/model/groth16.py#L141]
122122
123123
Miller loop type is either 'base_curve' or 'twisted_curve'
124124
"""

elliptic_curves/models/ec.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def line_evaluation(self,Q,P):
183183
def deserialise(serialised: list[bytes], field):
184184
"""
185185
Function that a list of integers and inteprets it as a point on the elliptic curve self and returns its serialisation.
186-
This function is based on the deserialisation function for the trait SWCurveConfig of arkworks, only uncompressed mode. [ref]
186+
This function is based on the deserialisation function for the trait SWCurveConfig of arkworks, only uncompressed mode. [https://github.com/arkworks-rs/algebra/blob/master/ec/src/models/short_weierstrass/mod.rs#L115]
187187
188188
It works as follows: serialised is a list of ints representing the little-endian encoding of (x,y). The encoding is:
189189
[LE(x), LE(y)_mod]
@@ -206,8 +206,11 @@ def deserialise(serialised: list[bytes], field):
206206
serialised_y[-1] = serialised_y[-1] & ~(1 << 7)
207207
y = field.deserialise(serialised_y)
208208

209-
y_is_largest = False
209+
y_is_largest = None
210210
for el, minus_el in zip(y.to_list()[::-1],(-y).to_list()[::-1]):
211+
if el < minus_el:
212+
y_is_largest = False
213+
break
211214
if el > minus_el:
212215
y_is_largest = True
213216
break
@@ -382,8 +385,11 @@ def deserialise(serialised: list[bytes], field):
382385
serialised_y[-1] = serialised_y[-1] & ~(1 << 7)
383386
y = field.deserialise(serialised_y)
384387

385-
y_is_largest = False
388+
y_is_largest = None
386389
for el, minus_el in zip(y.to_list()[::-1],(-y).to_list()[::-1]):
390+
if el < minus_el:
391+
y_is_largest = False
392+
break
387393
if el > minus_el:
388394
y_is_largest = True
389395
break

0 commit comments

Comments
 (0)