diff --git a/.github/workflows/pyzpkpackage.yml b/.github/workflows/pyzpkpackage.yml index 4dfc117..9b5b68a 100644 --- a/.github/workflows/pyzpkpackage.yml +++ b/.github/workflows/pyzpkpackage.yml @@ -41,14 +41,14 @@ jobs: flake8 . --exclude third_party \ --count --select=E9,F63,F7,F82 --show-source --statistics \ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - flake8 test - name: Building Library run: | chmod 557 build.sh - ./build.sh + ./build.sh - name: Scan for security issues run: | bandit -r syft -ll - name: Run tests run: | + cp build/src/*.so test coverage run -m pytest test diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index db010d3..ed94752 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -47,9 +47,14 @@ jobs: flake8 . --exclude third_party \ --count --select=E9,F63,F7,F82 --show-source --statistics \ --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Building Library + run: | + chmod 557 build.sh + ./build.sh - name: Scan for security issues run: | bandit -r syft -ll - name: Run tests run: | + cp build/src/*.so test coverage run -m pytest test diff --git a/_pyzpk/__init__.py b/_pyzpk/__init__.py deleted file mode 100644 index 030b9dc..0000000 --- a/_pyzpk/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from _pyzpk.main import sum diff --git a/_pyzpk/main.py b/_pyzpk/main.py deleted file mode 100644 index 55d2ab4..0000000 --- a/_pyzpk/main.py +++ /dev/null @@ -1,6 +0,0 @@ -import torch - - -def sum(x, y): - - return torch.add(x, y) diff --git a/src/PyZPK/binding.cpp b/src/PyZPK/binding.cpp index bc49b1d..37de08c 100644 --- a/src/PyZPK/binding.cpp +++ b/src/PyZPK/binding.cpp @@ -11,6 +11,8 @@ #include #include #include +#include +#include using namespace std; using namespace libsnark; namespace py = pybind11; @@ -114,4 +116,13 @@ PYBIND11_MODULE(pyzpk, m) )pbdoc", py::arg("left"), py::arg("right"), py::arg("lo"), py::arg("hi"), py::arg("permutation"), py::arg("permutation_inv"), py::arg("routing")); m.def("get_as_waksman_routing", &get_as_waksman_routing, py::arg("permutation")); m.def("valid_as_waksman_routing", &valid_as_waksman_routing, py::arg("permutation"), py::arg("routing")); + + + // Binding for #include common/default_types/r1cs_ppzkpcd_pp.hpp + py::class_(m, "default_r1cs_ppzkpcd_pp") + .def_static("init_public_params", &default_r1cs_ppzkpcd_pp::init_public_params); + + // Binding for #include common/default_types/tinyram_ppzksnark_pp.hpp + py::class_(m, "default_tinyram_ppzksnark_pp") + .def_static("init_public_params", &default_tinyram_ppzksnark_pp::init_public_params); } diff --git a/src/PyZPK/main.cpp b/src/PyZPK/main.cpp deleted file mode 100644 index 4c24888..0000000 --- a/src/PyZPK/main.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include -int add(int i, int j) -{ - return i + j; -} -// using namespace std; -using namespace libsnark; -namespace py = pybind11; - -PYBIND11_MODULE(pyzpk, m) -{ - m.doc() = "Python wrapper for open source Zero Proof Knowledge Library"; - - m.def("add", &add, R"pbdoc( - Add two numbers - )pbdoc"); -} - diff --git a/src/PyZPK/test/routing_algorithms.py b/src/PyZPK/test/routing_algorithms.py deleted file mode 100644 index 5c8419f..0000000 --- a/src/PyZPK/test/routing_algorithms.py +++ /dev/null @@ -1,23 +0,0 @@ -# Testing functionality for routing on an benes network and arbitrary-size (AS) Waksman network. - -import pyzpk -import math - -def test_benes(num_packets): - permutation = pyzpk.integer_permutation(math.ceil(num_packets)) - while permutation.next_permutation(): - routing = pyzpk.get_benes_routing(permutation) - assert pyzpk.valid_benes_routing(permutation, routing) == True - -def test_as_waksman(num_packets): - permutation = pyzpk.integer_permutation(num_packets) - while permutation.next_permutation(): - routing = pyzpk.get_as_waksman_routing(permutation) - assert pyzpk.valid_as_waksman_routing(permutation, routing) == True - - -if __name__ == "__main__": - num_packets = 8 - for i in range(2, num_packets+1): - test_as_waksman(i) - test_benes(num_packets) diff --git a/test/__init__.py b/test/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/test_binding.py b/test/test_binding.py new file mode 100644 index 0000000..20aa064 --- /dev/null +++ b/test/test_binding.py @@ -0,0 +1,62 @@ +# Testing functionality for routing on an benes network and arbitrary-size (AS) Waksman network. +import pytest +import pyzpk +import math + +def test_benes(): + num_packets = 8 + permutation = pyzpk.integer_permutation(math.ceil(num_packets)) + while permutation.next_permutation(): + routing = pyzpk.get_benes_routing(permutation) + assert pyzpk.valid_benes_routing(permutation, routing) == True + +def test_as_waksman(): + num_packets = 8 + permutation = pyzpk.integer_permutation(num_packets) + while permutation.next_permutation(): + routing = pyzpk.get_as_waksman_routing(permutation) + assert pyzpk.valid_as_waksman_routing(permutation, routing) == True + +def test_data_structures(): + min_element = 0 + max_element = 7 + + # intiallize vector and populate from 0 to 7 of size 8 using std::iota + vec = pyzpk.integer_permutation(min_element,max_element) + assert vec.get(2) == 2 + assert vec.get(1) == 1 + assert vec.get(5) == 5 + assert vec.get(7) == 7 + # slice from a to b + vec1 = vec.slice(3,5) + assert vec1.get(5) == 5 + # Permutating the vector + vec.set(0,7) + vec.set(1,4) + vec.set(2,3) + vec.set(3,0) + vec.set(4,5) + vec.set(5,1) + vec.set(6,2) + vec.set(7,6) + assert vec.get(2) == 3 + assert vec.get(1) == 4 + assert vec.get(5) == 1 + assert vec.get(7) == 6 + # .size() + assert vec.size() == 8 + # Check is_valid permute + assert vec.is_valid() == True + # Random shuffle elements of vector + vec.random_shuffle() + assert vec.is_valid() == True + # Finding next permute + vec.next_permutation() + assert vec.is_valid() == True + # Finding next permute + vec2 = vec.inverse() + assert vec2.is_valid() == True + # set a number above max_element for idx 5 + vec.set(5,10) + # Check is_valid permute + assert vec.is_valid() == False diff --git a/test/test_dummy.py b/test/test_dummy.py deleted file mode 100644 index 2cc5597..0000000 --- a/test/test_dummy.py +++ /dev/null @@ -1,19 +0,0 @@ -import unittest -import torch - -from _pyzpk import sum - - -class TestSum(unittest.TestCase): - def test_list(self): - """ - Test that it can sum two pytorch tensors. - """ - x = torch.Tensor([2, 3.5]) - y = torch.Tensor([3, 2.5]) - result = sum(x, y).tolist() - self.assertEqual(result, [5.0, 6.0]) - - -if __name__ == "__main__": - unittest.main() diff --git a/test_binding.py b/test_binding.py deleted file mode 100644 index 78a3a3a..0000000 --- a/test_binding.py +++ /dev/null @@ -1,54 +0,0 @@ -import pyzpk - -min_element = 0 -max_element = 7 - -# intiallize vector and populate from 0 to 7 of size 8 using std::iota -vec = pyzpk.integer_permutation(min_element,max_element) - -assert vec.get(2) == 2 -assert vec.get(1) == 1 -assert vec.get(5) == 5 -assert vec.get(7) == 7 - -# slice from a to b -vec1 = vec.slice(3,5) -assert vec1.get(5) == 5 - -# Permutating the vector -vec.set(0,7) -vec.set(1,4) -vec.set(2,3) -vec.set(3,0) -vec.set(4,5) -vec.set(5,1) -vec.set(6,2) -vec.set(7,6) - -assert vec.get(2) == 3 -assert vec.get(1) == 4 -assert vec.get(5) == 1 -assert vec.get(7) == 6 - -# .size() -assert vec.size() == 8 - -# Check is_valid permute -assert vec.is_valid() == True - -# Random shuffle elements of vector -vec.random_shuffle() -assert vec.is_valid() == True - -# Finding next permute -vec.next_permutation() -assert vec.is_valid() == True - -# Finding next permute -vec2 = vec.inverse() -assert vec2.is_valid() == True - -# set a number above max_element for idx 5 -vec.set(5,10) -# Check is_valid permute -assert vec.is_valid() == False \ No newline at end of file