Skip to content

Commit

Permalink
Removed scipy from dependencies, removed lagrange test code which use…
Browse files Browse the repository at this point in the history
…s scipy
  • Loading branch information
HarryR authored and HarryR committed Oct 21, 2018
1 parent 6386fe9 commit 5017bc8
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 54 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -142,10 +142,10 @@ requirements-dev:
$(PYTHON) -m pip install $(PIP_ARGS) -r requirements-dev.txt

fedora-dependencies:
dnf install procps-ng-devel gmp-devel boost-devel cmake g++ python3-scipy python3-pip
dnf install procps-ng-devel gmp-devel boost-devel cmake g++ python3-pip

ubuntu-dependencies:
apt-get install cmake make g++ libgmp-dev libboost-all-dev libprocps-dev python3-pip python3-scipy
apt-get install cmake make g++ libgmp-dev libboost-all-dev libprocps-dev python3-pip

mac-dependencies:
brew install pkg-config boost cmake gmp openssl || true
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
@@ -1,4 +1,3 @@
coverage
pyflakes
pylint
scipy
51 changes: 0 additions & 51 deletions test/test_shamir_poly.py
Expand Up @@ -4,47 +4,11 @@
from ethsnarks.field import FQ
from ethsnarks.r1cs import r1cs_constraint

from scipy.interpolate import lagrange as scipy_lagrange


def unzip(x):
return [_[0] for _ in x], [_[1] for _ in x]


class ShamirPolyTests(unittest.TestCase):
def test_fromdocs(self):
p = 100003
k = 4
a = [FQ(6257, p), FQ(85026, p), FQ(44499, p), FQ(14701, p)]
F = lambda i, x: a[i] * (x**i)
X = lambda x: a[0] + F(1, x) + F(2, x) + F(3, x)
# Create the shares
Sx = [_ for _ in range(1, 5)]
Sy = [X(_) for _ in Sx]
for x, y in zip(Sx, Sy):
z = shamirs_poly(FQ(x, p), a)
assert z == y
# Then recover secret
result = int(scipy_lagrange(Sx, [_.n for _ in Sy]).c[-1]) % p
assert a[0] == result


def test_fromdocs2(self):
p = 100003
k = 4
a = [FQ.random(p) for _ in range(0, k)] # [6257, 85026, 44499, 14701]
F = lambda i, x: a[i] * (x**i)
X = lambda x: a[0] + F(1, x) + F(2, x) + F(3, x)
# Create the shares
Sx = range(1, 5)
Sy = [X(_) for _ in Sx]
for x, y in zip(Sx, Sy):
z = shamirs_poly(FQ(x, p), a)
assert z == y
# Then recover secret
result = int(scipy_lagrange(Sx, [_.n for _ in Sy]).c[-1]) % p
assert a[0] == result

def test_random(self):
# Randomized tests
for _ in range(0, 10):
Expand All @@ -56,21 +20,6 @@ def test_random(self):
assert alpha[0] != lagrange(points[1:], 0)
assert alpha[0] != lagrange(points[2:], 0)

def test_random_small(self):
q = 100003
for _ in range(0, 10):
alpha = [FQ.random(q) for _ in range(0, 4)]
points = [(FQ(i, q), shamirs_poly(FQ(i, q), alpha))
for i in range(0, len(alpha))]
assert alpha[0] == lagrange(points, 0)
assert alpha[0] != lagrange(points[1:], 0)
assert alpha[0] != lagrange(points[2:], 0)

# XXX: scipy's lagrange has floating point precision for large numbers
points_x, points_y = unzip(points)
interpolation = scipy_lagrange([_.n for _ in points_x], [_.n for _ in points_y])
assert int(interpolation.c[-1]) == alpha[0]

def test_static(self):
# Verify against static test vectors
alpha = [FQ(6808181831819141657160280673506432691407806061837762993142662373500430825792),
Expand Down

0 comments on commit 5017bc8

Please sign in to comment.