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

Revert "python-bindings: Add pickle support for G1Element (#265)" #278

Merged
merged 1 commit into from Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 0 additions & 10 deletions python-bindings/pythonbindings.cpp
Expand Up @@ -373,16 +373,6 @@ PYBIND11_MODULE(blspy, m)
// PythonGIL release_lock;
return G1Element::FromBytes(Bytes(data_ptr, G1Element::SIZE));
})
.def(py::pickle(
[](const G1Element &dp) { // __getstate__
return py::make_tuple(dp.Serialize());
},
[](py::tuple t) { // __setstate__
if (t.size() != 1)
throw std::runtime_error("Invalid state!");
auto vecBytes = t[0].cast<std::vector<uint8_t>>();
return G1Element::FromByteVector(vecBytes);
}))
.def("generator", &G1Element::Generator)
.def("from_message", py::overload_cast<const std::vector<uint8_t>&, const uint8_t*, int>(&G1Element::FromMessage))
.def("pair", &G1Element::Pair)
Expand Down
14 changes: 0 additions & 14 deletions python-bindings/test.py
@@ -1,6 +1,5 @@
# flake8: noqa: E501
import binascii
import pickle
from copy import deepcopy

from blspy import (
Expand Down Expand Up @@ -336,24 +335,11 @@ def test_aggregate_verify_zero_items():
assert AugSchemeMPL.aggregate_verify([], [], G2Element())


def test_pickle_support():
seed = bytes([
0, 50, 6, 244, 24, 199, 1, 25, 52, 88, 192, 19, 18, 12, 89, 6,
220, 18, 102, 58, 209, 82, 12, 62, 89, 110, 182, 9, 44, 20, 254, 22
])
key: PrivateKey = AugSchemeMPL.key_gen(seed)
g1: G1Element = key.get_g1()
g1_data = pickle.dumps(g1)
g1_restored = pickle.loads(g1_data)
assert g1 == g1_restored


test_schemes()
test_vectors_invalid()
test_vectors_valid()
test_readme()
test_aggregate_verify_zero_items()
test_pickle_support()

print("\nAll tests passed.")

Expand Down