Skip to content

Commit

Permalink
Running black on repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Drake-Eidukas committed Jul 18, 2019
1 parent 502903f commit a47f37f
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 61 deletions.
166 changes: 142 additions & 24 deletions benchmark/test_benchmark_hbavss.py
Expand Up @@ -19,10 +19,35 @@ def get_avss_params(n, t):
return g, h, public_keys, private_keys


@mark.parametrize("t, k", [(1, 5), (3, 5), (5, 5), (16, 5), (33, 5), (85, 5),
(1, 25), (3, 25), (5, 25), (16, 25), (33, 25), (85, 25),
(1, 50), (3, 50), (5, 50), (16, 50), (33, 50), (85, 50),
(1, 100), (3, 100), (5, 100), (16, 100), (33, 100), (85, 100)]) # (# noqa: E501)
@mark.parametrize(
"t, k",
[
(1, 5),
(3, 5),
(5, 5),
(16, 5),
(33, 5),
(85, 5),
(1, 25),
(3, 25),
(5, 25),
(16, 25),
(33, 25),
(85, 25),
(1, 50),
(3, 50),
(5, 50),
(16, 50),
(33, 50),
(85, 50),
(1, 100),
(3, 100),
(5, 100),
(16, 100),
(33, 100),
(85, 100),
],
) # (# noqa: E501)
def test_benchmark_hbavss_lite_dealer(test_router, benchmark, t, k):
loop = asyncio.get_event_loop()
field = ZR
Expand All @@ -36,13 +61,35 @@ def test_benchmark_hbavss_lite_dealer(test_router, benchmark, t, k):

def _prog():
loop.run_until_complete(hbavss_light_batch_dealer(test_router, params))

benchmark(_prog)


@mark.parametrize("t, k", [(1, 5), (3, 5), (5, 5), (16, 5), (33, 5),
(1, 25), (3, 25), (5, 25), (16, 25), (33, 25),
(1, 50), (3, 50), (5, 50), (16, 50), (33, 50),
(1, 100), (3, 100), (5, 100), (16, 100), (33, 100)])
@mark.parametrize(
"t, k",
[
(1, 5),
(3, 5),
(5, 5),
(16, 5),
(33, 5),
(1, 25),
(3, 25),
(5, 25),
(16, 25),
(33, 25),
(1, 50),
(3, 50),
(5, 50),
(16, 50),
(33, 50),
(1, 100),
(3, 100),
(5, 100),
(16, 100),
(33, 100),
],
)
def test_benchmark_hbavss_dealer(test_router, benchmark, t, k):
loop = asyncio.get_event_loop()
n = 3 * t + 1
Expand All @@ -57,13 +104,39 @@ def test_benchmark_hbavss_dealer(test_router, benchmark, t, k):

def _prog():
loop.run_until_complete(hbavss_multibatch_dealer(test_router, params))

benchmark(_prog)


@mark.parametrize("t, k", [(1, 5), (3, 5), (5, 5), (16, 5), (33, 5), (85, 5),
(1, 25), (3, 25), (5, 25), (16, 25), (33, 25), (85, 25),
(1, 50), (3, 50), (5, 50), (16, 50), (33, 50), (85, 50),
(1, 100), (3, 100), (5, 100), (16, 100), (33, 100), (85, 100)]) # (# noqa: E501)
@mark.parametrize(
"t, k",
[
(1, 5),
(3, 5),
(5, 5),
(16, 5),
(33, 5),
(85, 5),
(1, 25),
(3, 25),
(5, 25),
(16, 25),
(33, 25),
(85, 25),
(1, 50),
(3, 50),
(5, 50),
(16, 50),
(33, 50),
(85, 50),
(1, 100),
(3, 100),
(5, 100),
(16, 100),
(33, 100),
(85, 100),
],
) # (# noqa: E501)
def test_benchmark_hbavss_lite(test_router, benchmark, t, k):
loop = asyncio.get_event_loop()
# field = GF(Subgroup.BLS12_381)
Expand All @@ -78,13 +151,35 @@ def test_benchmark_hbavss_lite(test_router, benchmark, t, k):

def _prog():
loop.run_until_complete(hbavss_light_batch(test_router, params))

benchmark(_prog)


@mark.parametrize("t, k", [(1, 5), (3, 5), (5, 5), (16, 5), (33, 5),
(1, 25), (3, 25), (5, 25), (16, 25), (33, 25),
(1, 50), (3, 50), (5, 50), (16, 50), (33, 50),
(1, 100), (3, 100), (5, 100), (16, 100), (33, 100)])
@mark.parametrize(
"t, k",
[
(1, 5),
(3, 5),
(5, 5),
(16, 5),
(33, 5),
(1, 25),
(3, 25),
(5, 25),
(16, 25),
(33, 25),
(1, 50),
(3, 50),
(5, 50),
(16, 50),
(33, 50),
(1, 100),
(3, 100),
(5, 100),
(16, 100),
(33, 100),
],
)
def test_benchmark_hbavss(test_router, benchmark, t, k):
loop = asyncio.get_event_loop()
n = 3 * t + 1
Expand All @@ -99,6 +194,7 @@ def test_benchmark_hbavss(test_router, benchmark, t, k):

def _prog():
loop.run_until_complete(hbavss_multibatch(test_router, params))

benchmark(_prog)


Expand All @@ -112,15 +208,15 @@ async def hbavss_light_batch(test_router, params):
with ExitStack() as stack:
for i in range(n):
hbavss = HbAvssLight(
pks, sks[i], crs, n, t, i, sends[i], recvs[i], pc=pc, field=field)
pks, sks[i], crs, n, t, i, sends[i], recvs[i], pc=pc, field=field
)
hbavss_list[i] = hbavss
stack.enter_context(hbavss)
if i == dealer_id:
avss_tasks[i] = asyncio.create_task(hbavss.avss(0, value=values))
else:
avss_tasks[i] = asyncio.create_task(hbavss.avss(0, dealer_id=dealer_id))
await asyncio.gather(
*[hbavss_list[i].output_queue.get() for i in range(n)])
await asyncio.gather(*[hbavss_list[i].output_queue.get() for i in range(n)])
for task in avss_tasks:
task.cancel()

Expand All @@ -131,7 +227,18 @@ async def hbavss_light_batch_dealer(test_router, params):
sends, recvs, _ = test_router(n + 1)
dealer_id = n

hbavss = HbAvssLight(pks, None, crs, n, t, dealer_id, sends[dealer_id], recvs[dealer_id], pc=pc, field=field) # (# noqa: E501)
hbavss = HbAvssLight(
pks,
None,
crs,
n,
t,
dealer_id,
sends[dealer_id],
recvs[dealer_id],
pc=pc,
field=field,
) # (# noqa: E501)
await asyncio.create_task(hbavss.avss(0, value=values, client_mode=True))


Expand All @@ -146,15 +253,15 @@ async def hbavss_multibatch(test_router, params):
hbavss_list = [None] * n
for i in range(n):
hbavss = HbAvssBatch(
pks, sks[i], crs, n, t, i, sends[i], recvs[i], pc=pc, field=field)
pks, sks[i], crs, n, t, i, sends[i], recvs[i], pc=pc, field=field
)
hbavss_list[i] = hbavss
stack.enter_context(hbavss)
if i == dealer_id:
avss_tasks[i] = asyncio.create_task(hbavss.avss(0, values=values))
else:
avss_tasks[i] = asyncio.create_task(hbavss.avss(0, dealer_id=dealer_id))
await asyncio.gather(
*[hbavss_list[i].output_queue.get() for i in range(n)])
await asyncio.gather(*[hbavss_list[i].output_queue.get() for i in range(n)])
for task in avss_tasks:
task.cancel()

Expand All @@ -163,5 +270,16 @@ async def hbavss_multibatch_dealer(test_router, params):
(t, n, g, h, pks, sks, crs, pc, values, field) = params
sends, recvs, _ = test_router(n + 1)
dealer_id = n
hbavss = HbAvssBatch(pks, None, crs, n, t, dealer_id, sends[dealer_id], recvs[dealer_id], pc=pc, field=field) # (# noqa: E501)
hbavss = HbAvssBatch(
pks,
None,
crs,
n,
t,
dealer_id,
sends[dealer_id],
recvs[dealer_id],
pc=pc,
field=field,
) # (# noqa: E501)
await hbavss.avss(0, values=values, client_mode=True)
58 changes: 48 additions & 10 deletions benchmark/test_benchmark_rbc.py
Expand Up @@ -5,10 +5,27 @@
import os


@mark.parametrize("t, msglen", [(1, 200), (1, 10000), (3, 200), (3, 10000),
(5, 200), (5, 10000), (10, 200), (10, 10000),
(16, 200), (16, 10000), (25, 200), (25, 10000),
(33, 200), (33, 10000), (50, 200), (50, 10000)])
@mark.parametrize(
"t, msglen",
[
(1, 200),
(1, 10000),
(3, 200),
(3, 10000),
(5, 200),
(5, 10000),
(10, 200),
(10, 10000),
(16, 200),
(16, 10000),
(25, 200),
(25, 10000),
(33, 200),
(33, 10000),
(50, 200),
(50, 10000),
],
)
def test_benchmark_rbc(test_router, benchmark, t, msglen):
loop = asyncio.get_event_loop()
n = 3 * t + 1
Expand All @@ -18,14 +35,32 @@ def test_benchmark_rbc(test_router, benchmark, t, msglen):

def _prog():
loop.run_until_complete(rbc(params))

benchmark(_prog)
# cProfile.runctx("_prog()", None, locals())


@mark.parametrize("t, msglen", [(1, 200), (1, 10000), (3, 200), (3, 10000),
(5, 200), (5, 10000), (10, 200), (10, 10000),
(16, 200), (16, 10000), (25, 200), (25, 10000),
(33, 200), (33, 10000), (50, 200), (50, 10000)])
@mark.parametrize(
"t, msglen",
[
(1, 200),
(1, 10000),
(3, 200),
(3, 10000),
(5, 200),
(5, 10000),
(10, 200),
(10, 10000),
(16, 200),
(16, 10000),
(25, 200),
(25, 10000),
(33, 200),
(33, 10000),
(50, 200),
(50, 10000),
],
)
def test_benchmark_rbc_dealer(test_router, benchmark, t, msglen):
loop = asyncio.get_event_loop()
n = 3 * t + 1
Expand All @@ -35,6 +70,7 @@ def test_benchmark_rbc_dealer(test_router, benchmark, t, msglen):

def _prog():
loop.run_until_complete(rbc_dealer(params))

benchmark(_prog)
# cProfile.runctx("_prog()", None, locals())

Expand All @@ -49,10 +85,12 @@ async def rbc(params):
for i in range(n):
if i == dealer_id:
rbc_tasks[i] = asyncio.create_task(
reliablebroadcast(tag, i, n, t, dealer_id, msg, recvs[i], sends[i]))
reliablebroadcast(tag, i, n, t, dealer_id, msg, recvs[i], sends[i])
)
else:
rbc_tasks[i] = asyncio.create_task(
reliablebroadcast(tag, i, n, t, dealer_id, None, recvs[i], sends[i]))
reliablebroadcast(tag, i, n, t, dealer_id, None, recvs[i], sends[i])
)
await asyncio.gather(*rbc_tasks)
for task in rbc_tasks:
task.cancel()
Expand Down
2 changes: 1 addition & 1 deletion benchmark/test_benchmark_reed_solomon.py
Expand Up @@ -53,5 +53,5 @@ def test_benchmark_gao_robust_decode_fft(benchmark, t, galois_field):
if i in faults:
shares_with_faults.append(int(galois_field.random()))
else:
shares_with_faults.append(int(truepoly(omega**(i) % p)))
shares_with_faults.append(int(truepoly(omega ** (i) % p)))
benchmark(dec.robust_decode, parties, shares_with_faults)
21 changes: 11 additions & 10 deletions honeybadgermpc/betterpairing.py
Expand Up @@ -125,8 +125,9 @@ def __pow__(self, other):
exponend = ZR(intother)
except ValueError:
raise TypeError(
'Invalid exponentiation param. Expected ZR or int. Got '
+ str(type(other)))
"Invalid exponentiation param. Expected ZR or int. Got "
+ str(type(other))
)
out = G1(dupe_pyg1(self.pyg1))
self.pyg1.ppmul(exponend.val, out.pyg1)
return out
Expand Down Expand Up @@ -549,21 +550,21 @@ def __init__(self, val=None):
self.val = PyFr(0, 0, 0, 0)
elif type(val) is int:
uint = val % (bls12_381_r)
u1 = uint % 2**64
u2 = (uint // (2**64)) % 2**64
u3 = (uint // (2**128)) % 2**64
u4 = (uint // (2**192))
u1 = uint % 2 ** 64
u2 = (uint // (2 ** 64)) % 2 ** 64
u3 = (uint // (2 ** 128)) % 2 ** 64
u4 = uint // (2 ** 192)
self.val = PyFr(u1, u2, u3, u4)
elif type(val) is str:
if val[0:2] == "0x":
intval = int(val, 0)
else:
intval = int(val)
uint = intval % (bls12_381_r)
u1 = uint % 2**64
u2 = (uint // (2**64)) % 2**64
u3 = (uint // (2**128)) % 2**64
u4 = (uint // (2**192))
u1 = uint % 2 ** 64
u2 = (uint // (2 ** 64)) % 2 ** 64
u3 = (uint // (2 ** 128)) % 2 ** 64
u4 = uint // (2 ** 192)
self.val = PyFr(u1, u2, u3, u4)
elif type(val) is PyFr:
self.val = val
Expand Down
2 changes: 1 addition & 1 deletion honeybadgermpc/broadcast/crypto/boldyreva.py
Expand Up @@ -84,7 +84,7 @@ def __setstate__(self, d):

def __eq__(self, other):
return (
self.l == other.l # noqa: E741
self.l == other.l # noqa: E741
and self.k == other.k # noqa: E741
and self.VK == other.VK
and self.VKs == other.VKs
Expand Down

0 comments on commit a47f37f

Please sign in to comment.