Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed import errors and input errors in fixtures.py. #439

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions benchmark/test_benchmark_comparisons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from pytest import mark

from honeybadgermpc.progs.fixedpoint import FixedPoint
from honeybadgermpc.progs.mixins.share_arithmetic import (
BeaverMultiply,
BeaverMultiplyArrays,
DivideShareArrays,
DivideShares,
InvertShare,
InvertShareArray,
)
from honeybadgermpc.progs.mixins.share_comparison import Equality

MIXINS = [
BeaverMultiply(),
BeaverMultiplyArrays(),
InvertShare(),
InvertShareArray(),
DivideShares(),
DivideShareArrays(),
Equality(),
]

TEST_PREPROCESSING = ["rands", "triples", "zeros", "cubes", "bits"]

ALL_BIT_NUMBERS = [int(f"0b{'1' * i}", 2) for i in [1, 64, 128, 256]]

n, t = 4, 1
k = 50000
COUNT_MAX = 2


def run_benchmark(
runner, prog, n=n, t=t, preprocessing=TEST_PREPROCESSING, k=k, mixins=MIXINS
):
runner(prog, n, t, preprocessing, k, mixins)


@mark.parametrize("comparator", ALL_BIT_NUMBERS)
def test_benchmark_fixedpoint_lt(benchmark_runner, comparator):
async def _prog(context):
base = FixedPoint(
context,
6846412461894745224441235558443359243034138132682534265960483512729196124138,
)
result = await base.lt(FixedPoint(context, comparator))
await result.open()

run_benchmark(benchmark_runner, _prog)


@mark.parametrize("comparator", ALL_BIT_NUMBERS)
def test_benchmark_share_eq(benchmark_runner, comparator):
equality = Equality()

async def _prog(context):
base = context.Share(
6846412461894745224441235558443359243034138132682534265960483512729196124138
)
comp = context.Share(comparator)
result = await equality(context, base, comp)
await result.open()

run_benchmark(benchmark_runner, _prog)
3 changes: 1 addition & 2 deletions benchmark/test_benchmark_jubjub.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
BeaverMultiplyArrays,
DivideShareArrays,
DivideShares,
Equality,
InvertShare,
InvertShareArray,
)

from honeybadgermpc.progs.mixins.share_comparison import Equality

MIXINS = [
BeaverMultiply(),
Expand Down
2 changes: 1 addition & 1 deletion benchmark/test_benchmark_mimc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
BeaverMultiplyArrays,
DivideShareArrays,
DivideShares,
Equality,
InvertShare,
InvertShareArray,
)
from honeybadgermpc.progs.mixins.share_comparison import Equality

CONFIG = {
BeaverMultiply.name: BeaverMultiply(),
Expand Down
2 changes: 1 addition & 1 deletion benchmark/test_benchmark_polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pytest import mark

from honeybadgermpc.ntl.helpers import fft_interpolate, lagrange_interpolate
from honeybadgermpc.ntl import fft_interpolate, lagrange_interpolate
from honeybadgermpc.polynomial import get_omega

cache = {}
Expand Down
50 changes: 50 additions & 0 deletions benchmark/test_benchmark_share_mult.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from pytest import mark

from honeybadgermpc.progs.mixins.share_arithmetic import (
BeaverMultiply,
BeaverMultiplyArrays,
DivideShareArrays,
DivideShares,
InvertShare,
InvertShareArray,
)
from honeybadgermpc.progs.mixins.share_comparison import Equality

MIXINS = [
BeaverMultiply(),
BeaverMultiplyArrays(),
InvertShare(),
InvertShareArray(),
DivideShares(),
DivideShareArrays(),
Equality(),
]

TEST_PREPROCESSING = ["rands", "triples", "zeros", "cubes", "bits"]

ALL_BIT_NUMBERS = [int(f"0b{'1' * i}", 2) for i in [1, 64, 128, 256]]

n, t = 4, 1
k = 50000
COUNT_MAX = 2


def run_benchmark(
runner, prog, n=n, t=t, preprocessing=TEST_PREPROCESSING, k=k, mixins=MIXINS
):
runner(prog, n, t, preprocessing, k, mixins)


@mark.parametrize("multiplier", ALL_BIT_NUMBERS)
def test_benchmark_beaver_mul_shares(benchmark_runner, multiplier):
multiply = BeaverMultiply()

async def _prog(context):
base = context.Share(
6846412461894745224441235558443359243034138132682534265960483512729196124138
)
mult = context.Share(multiplier)
result = await multiply(context, base, mult)
await result.open()

run_benchmark(benchmark_runner, _prog)
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ services:
- ./pairing/benches:/usr/src/HoneyBadgerMPC/pairing/benches
- ./pairing/Cargo.toml:/usr/src/HoneyBadgerMPC/pairing/Cargo.toml
- ./pairing/setup.py:/usr/src/HoneyBadgerMPC/pairing/setup.py
- /usr/src/HoneyBadgerMPC/honeybadgermpc/ntl # Directory _not_ mounted from host
# - /usr/src/HoneyBadgerMPC/honeybadgermpc/ntl # Directory _not_ mounted from host
command: pytest -v --cov=honeybadgermpc
22 changes: 12 additions & 10 deletions honeybadgermpc/ntl/hbmpc_ntl_helpers.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,8 @@ async def _test_runner(prog, n=4, t=1, to_generate=[], k=1000, mixins=[]):

@fixture
def benchmark_runner(benchmark):
from honeybadgermpc.preprocessing import PreProcessedElements

def _benchmark_runner(prog, n=4, t=1, to_generate=[], k=1000, mixins=[]):
pp_elements = PreProcessedElements()
_preprocess(pp_elements, n, t, k, to_generate)
_preprocess(n, t, k, to_generate)

config = _build_config(mixins)
program_runner = TaskProgramRunner(n, t, config)
Expand All @@ -208,6 +205,6 @@ def _benchmark_runner(prog, n=4, t=1, to_generate=[], k=1000, mixins=[]):
def _work():
loop.run_until_complete(program_runner.join())

benchmark(_work)
benchmark.pedantic(_work, iterations=100, rounds=10, warmup_rounds=10)

return _benchmark_runner