From c409c6083d0eade853e295f488516615b7a5137f Mon Sep 17 00:00:00 2001 From: Andrew Miller Date: Fri, 1 Mar 2019 21:44:49 -0600 Subject: [PATCH] Make test_hbavss actually fail on exceptions Fix G1.one() --- honeybadgermpc/betterpairing.py | 20 +++++++++++++++----- tests/test_hbavss.py | 2 +- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/honeybadgermpc/betterpairing.py b/honeybadgermpc/betterpairing.py index 69c4176c..adbf978a 100644 --- a/honeybadgermpc/betterpairing.py +++ b/honeybadgermpc/betterpairing.py @@ -72,6 +72,9 @@ def __imul__(self, other): if type(other) is G1: self.pyg1.add_assign(other.pyg1) return self + raise TypeError( + 'Invalid multiplication param. Expected G1. Got ' + + str(type(other))) def __truediv__(self, other): if type(other) is G1: @@ -87,6 +90,9 @@ def __idiv__(self, other): if type(other) is G1: self.pyg1.sub_assign(other.pyg1) return self + raise TypeError( + 'Invalid division param. Expected G1. Got ' + + str(type(other))) def __pow__(self, other): if type(other) is int: @@ -115,7 +121,7 @@ def __ipow__(self, other): return self if other < 0: self.invert() - other = other * -1 + other *= -1 self.pyg1.mul_assign(ZR(other).val) return self elif type(other) is ZR: @@ -172,7 +178,9 @@ def pair_with(self, other): @staticmethod def one(): - return G1(PyG1().zero()) + one = G1() + one.pyg1.zero() + return one @staticmethod def rand(seed=None): @@ -277,7 +285,7 @@ def __ipow__(self, other): return self if other < 0: self.invert() - other = other * -1 + other *= -1 self.pyg2.mul_assign(ZR(other).val) return self elif type(other) is ZR: @@ -329,7 +337,9 @@ def projective(self): @staticmethod def one(): - return G2(PyG2().zero()) + one = G2() + one.pyg2.zero() + return one @staticmethod def rand(seed=None): @@ -377,7 +387,7 @@ def __mul__(self, other): return out if other < 0: out.pyfq12.negate() - other = -1 * other + other *= -1 prodend = GT(other) out.pyfq12.mul_assign(prodend.pyfq12) return out diff --git a/tests/test_hbavss.py b/tests/test_hbavss.py index 300d6dd6..75623578 100644 --- a/tests/test_hbavss.py +++ b/tests/test_hbavss.py @@ -30,4 +30,4 @@ async def test_hbavss(test_router): for r in recipients: threads.append(r.run()) threads.append(dealer.run()) - await asyncio.wait(threads) + await asyncio.gather(*threads)