From 042ad35a8a67a1844e51eac441b310371eba1fe8 Mon Sep 17 00:00:00 2001 From: "yue.wang" Date: Wed, 30 Sep 2020 20:47:55 +0800 Subject: [PATCH 1/2] align compression func with doc description Signed-off-by: yue.wang --- ethsnarks/jubjub.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ethsnarks/jubjub.py b/ethsnarks/jubjub.py index 72f3ded..893aa06 100644 --- a/ethsnarks/jubjub.py +++ b/ethsnarks/jubjub.py @@ -68,7 +68,7 @@ def is_negative(v): assert isinstance(v, FQ) - return v.n < (-v).n + return v.n > (-v).n class AbstractCurveOps(object): @@ -160,7 +160,7 @@ def from_y(cls, y, sign=None): x = xsq.sqrt() if sign is not None: # Used for compress & decompress - if (x.n & 1) != sign: + if is_negative(x) ^ (sign != 0): x = -x else: if is_negative(x): @@ -237,7 +237,7 @@ def __hash__(self): def compress(self): x = self.x.n y = self.y.n - return int.to_bytes(y | ((x&1) << 255), 32, "little") + return int.to_bytes(y | (is_negative(x) << 255), 32, "little") @classmethod def decompress(cls, point): @@ -684,4 +684,4 @@ def mult_naf_lut(point, scalar, width=2): p = w[k_i] if p is not None: a = a.add(p) - return a \ No newline at end of file + return a From 496458fcdee8d4b5f38c9b85a7b78878a01bccbc Mon Sep 17 00:00:00 2001 From: "yue.wang" Date: Thu, 8 Oct 2020 12:03:53 +0800 Subject: [PATCH 2/2] fix compress data type Signed-off-by: yue.wang --- ethsnarks/jubjub.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethsnarks/jubjub.py b/ethsnarks/jubjub.py index 893aa06..edf18a8 100644 --- a/ethsnarks/jubjub.py +++ b/ethsnarks/jubjub.py @@ -235,7 +235,7 @@ def __hash__(self): return hash((self.x, self.y)) def compress(self): - x = self.x.n + x = self.x y = self.y.n return int.to_bytes(y | (is_negative(x) << 255), 32, "little")