@@ -25,11 +25,14 @@ PYBIND11_MODULE(chiavdf, m) {
25
25
const string& x_s, const string& y_s,
26
26
const string& proof_s,
27
27
uint64_t num_iterations) {
28
- py::gil_scoped_release release;
29
28
integer D (discriminant);
30
- form x = DeserializeForm (D, (const uint8_t *)x_s.data (), x_s.size ());
31
- form y = DeserializeForm (D, (const uint8_t *)y_s.data (), y_s.size ());
32
- form proof = DeserializeForm (D, (const uint8_t *)proof_s.data (), proof_s.size ());
29
+ std::string x_s_copy (x_s);
30
+ std::string y_s_copy (y_s);
31
+ std::string proof_s_copy (proof_s);
32
+ py::gil_scoped_release release;
33
+ form x = DeserializeForm (D, (const uint8_t *)x_s_copy.data (), x_s_copy.size ());
34
+ form y = DeserializeForm (D, (const uint8_t *)y_s_copy.data (), y_s_copy.size ());
35
+ form proof = DeserializeForm (D, (const uint8_t *)proof_s_copy.data (), proof_s_copy.size ());
33
36
34
37
bool is_valid = false ;
35
38
VerifyWesolowskiProof (D, x, y, proof, num_iterations, is_valid);
@@ -41,16 +44,19 @@ PYBIND11_MODULE(chiavdf, m) {
41
44
const string& x_s,
42
45
const string& proof_blob,
43
46
const uint64_t num_iterations, const uint64_t disc_size_bits, const uint64_t recursion) {
47
+ std::string discriminant_copy (discriminant);
48
+ std::string x_s_copy (x_s);
49
+ std::string proof_blob_copy (proof_blob);
44
50
py::gil_scoped_release release;
45
- std::string proof_blob_str (proof_blob);
46
- uint8_t *proof_blob_ptr = reinterpret_cast <uint8_t *>(proof_blob_str.data ());
47
- int proof_blob_size = proof_blob.size ();
51
+ uint8_t *proof_blob_ptr = reinterpret_cast <uint8_t *>(proof_blob_copy.data ());
52
+ int proof_blob_size = proof_blob_copy.size ();
48
53
49
- return CheckProofOfTimeNWesolowski (integer (discriminant ), (const uint8_t *)x_s .data (), proof_blob_ptr, proof_blob_size, num_iterations, disc_size_bits, recursion);
54
+ return CheckProofOfTimeNWesolowski (integer (discriminant_copy ), (const uint8_t *)x_s_copy .data (), proof_blob_ptr, proof_blob_size, num_iterations, disc_size_bits, recursion);
50
55
});
51
56
52
57
m.def (" prove" , [] (const py::bytes& challenge_hash, const string& x_s, int discriminant_size_bits, uint64_t num_iterations) {
53
58
std::string challenge_hash_str (challenge_hash);
59
+ std::string x_s_copy (x_s);
54
60
std::vector<uint8_t > result;
55
61
{
56
62
py::gil_scoped_release release;
@@ -59,7 +65,7 @@ PYBIND11_MODULE(chiavdf, m) {
59
65
challenge_hash_bytes,
60
66
discriminant_size_bits
61
67
);
62
- form x = DeserializeForm (D, (const uint8_t *) x_s .data (), x_s .size ());
68
+ form x = DeserializeForm (D, (const uint8_t *) x_s_copy .data (), x_s_copy .size ());
63
69
result = ProveSlow (D, x, num_iterations);
64
70
}
65
71
py::bytes ret = py::bytes (reinterpret_cast <char *>(result.data ()), result.size ());
@@ -74,11 +80,14 @@ PYBIND11_MODULE(chiavdf, m) {
74
80
const uint64_t num_iterations, const uint64_t recursion) {
75
81
std::pair<bool , std::vector<uint8_t >> result;
76
82
{
83
+ std::string discriminant_copy (discriminant);
84
+ std::string B_copy (B);
85
+ std::string x_s_copy (x_s);
86
+ std::string proof_blob_copy (proof_blob);
77
87
py::gil_scoped_release release;
78
- std::string proof_blob_str (proof_blob);
79
- uint8_t *proof_blob_ptr = reinterpret_cast <uint8_t *>(proof_blob_str.data ());
80
- int proof_blob_size = proof_blob.size ();
81
- result = CheckProofOfTimeNWesolowskiWithB (integer (discriminant), integer (B), (const uint8_t *)x_s.data (), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
88
+ uint8_t *proof_blob_ptr = reinterpret_cast <uint8_t *>(proof_blob_copy.data ());
89
+ int proof_blob_size = proof_blob_copy.size ();
90
+ result = CheckProofOfTimeNWesolowskiWithB (integer (discriminant_copy), integer (B_copy), (const uint8_t *)x_s_copy.data (), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
82
91
}
83
92
py::bytes res_bytes = py::bytes (reinterpret_cast <char *>(result.second .data ()), result.second .size ());
84
93
py::tuple res_tuple = py::make_tuple (result.first , res_bytes);
@@ -89,11 +98,13 @@ PYBIND11_MODULE(chiavdf, m) {
89
98
const string& x_s,
90
99
const string& proof_blob,
91
100
const uint64_t num_iterations, const uint64_t recursion) {
101
+ std::string discriminant_copy (discriminant);
102
+ std::string x_s_copy (x_s);
103
+ std::string proof_blob_copy (proof_blob);
92
104
py::gil_scoped_release release;
93
- std::string proof_blob_str (proof_blob);
94
- uint8_t *proof_blob_ptr = reinterpret_cast <uint8_t *>(proof_blob_str.data ());
95
- int proof_blob_size = proof_blob.size ();
96
- integer B = GetBFromProof (integer (discriminant), (const uint8_t *)x_s.data (), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
105
+ uint8_t *proof_blob_ptr = reinterpret_cast <uint8_t *>(proof_blob_copy.data ());
106
+ int proof_blob_size = proof_blob_copy.size ();
107
+ integer B = GetBFromProof (integer (discriminant_copy), (const uint8_t *)x_s_copy.data (), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
97
108
return B.to_string ();
98
109
});
99
110
}
0 commit comments