@@ -11,12 +11,15 @@ PYBIND11_MODULE(chiavdf, m) {
11
11
// Creates discriminant.
12
12
m.def (" create_discriminant" , [] (const py::bytes& challenge_hash, int discriminant_size_bits) {
13
13
std::string challenge_hash_str (challenge_hash);
14
- py::gil_scoped_release release;
15
- auto challenge_hash_bits = std::vector<uint8_t >(challenge_hash_str.begin (), challenge_hash_str.end ());
16
- integer D = CreateDiscriminant (
17
- challenge_hash_bits,
18
- discriminant_size_bits
19
- );
14
+ integer D;
15
+ {
16
+ py::gil_scoped_release release;
17
+ auto challenge_hash_bits = std::vector<uint8_t >(challenge_hash_str.begin (), challenge_hash_str.end ());
18
+ D = CreateDiscriminant (
19
+ challenge_hash_bits,
20
+ discriminant_size_bits
21
+ );
22
+ }
20
23
return D.to_string ();
21
24
});
22
25
@@ -29,13 +32,14 @@ PYBIND11_MODULE(chiavdf, m) {
29
32
std::string x_s_copy (x_s);
30
33
std::string y_s_copy (y_s);
31
34
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 ());
36
-
37
35
bool is_valid = false ;
38
- VerifyWesolowskiProof (D, x, y, proof, num_iterations, is_valid);
36
+ {
37
+ py::gil_scoped_release release;
38
+ form x = DeserializeForm (D, (const uint8_t *)x_s_copy.data (), x_s_copy.size ());
39
+ form y = DeserializeForm (D, (const uint8_t *)y_s_copy.data (), y_s_copy.size ());
40
+ form proof = DeserializeForm (D, (const uint8_t *)proof_s_copy.data (), proof_s_copy.size ());
41
+ VerifyWesolowskiProof (D, x, y, proof, num_iterations, is_valid);
42
+ }
39
43
return is_valid;
40
44
});
41
45
@@ -47,17 +51,22 @@ PYBIND11_MODULE(chiavdf, m) {
47
51
std::string discriminant_copy (discriminant);
48
52
std::string x_s_copy (x_s);
49
53
std::string proof_blob_copy (proof_blob);
50
- py::gil_scoped_release release;
51
54
uint8_t *proof_blob_ptr = reinterpret_cast <uint8_t *>(proof_blob_copy.data ());
52
55
int proof_blob_size = proof_blob_copy.size ();
53
-
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);
56
+ bool is_valid = false ;
57
+ {
58
+ py::gil_scoped_release release;
59
+ is_valid=CheckProofOfTimeNWesolowski (integer (discriminant_copy), (const uint8_t *)x_s_copy.data (), proof_blob_ptr, proof_blob_size, num_iterations, disc_size_bits, recursion);
60
+ }
61
+ return is_valid;
55
62
});
56
63
64
+
57
65
m.def (" prove" , [] (const py::bytes& challenge_hash, const string& x_s, int discriminant_size_bits, uint64_t num_iterations, const string& shutdown_file_path) {
58
66
std::string challenge_hash_str (challenge_hash);
59
67
std::string x_s_copy (x_s);
60
68
std::vector<uint8_t > result;
69
+ std::string shutdown_file_path_copy (shutdown_file_path);
61
70
{
62
71
py::gil_scoped_release release;
63
72
std::vector<uint8_t > challenge_hash_bytes (challenge_hash_str.begin (), challenge_hash_str.end ());
@@ -66,7 +75,7 @@ PYBIND11_MODULE(chiavdf, m) {
66
75
discriminant_size_bits
67
76
);
68
77
form x = DeserializeForm (D, (const uint8_t *) x_s_copy.data (), x_s_copy.size ());
69
- result = ProveSlow (D, x, num_iterations, shutdown_file_path );
78
+ result = ProveSlow (D, x, num_iterations, shutdown_file_path_copy );
70
79
}
71
80
py::bytes ret = py::bytes (reinterpret_cast <char *>(result.data ()), result.size ());
72
81
return ret;
@@ -78,12 +87,12 @@ PYBIND11_MODULE(chiavdf, m) {
78
87
const string& x_s,
79
88
const string& proof_blob,
80
89
const uint64_t num_iterations, const uint64_t recursion) {
90
+ std::string discriminant_copy (discriminant);
91
+ std::string B_copy (B);
92
+ std::string x_s_copy (x_s);
93
+ std::string proof_blob_copy (proof_blob);
81
94
std::pair<bool , std::vector<uint8_t >> result;
82
95
{
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);
87
96
py::gil_scoped_release release;
88
97
uint8_t *proof_blob_ptr = reinterpret_cast <uint8_t *>(proof_blob_copy.data ());
89
98
int proof_blob_size = proof_blob_copy.size ();
@@ -101,10 +110,12 @@ PYBIND11_MODULE(chiavdf, m) {
101
110
std::string discriminant_copy (discriminant);
102
111
std::string x_s_copy (x_s);
103
112
std::string proof_blob_copy (proof_blob);
104
- py::gil_scoped_release release;
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);
113
+ {
114
+ py::gil_scoped_release release;
115
+ uint8_t *proof_blob_ptr = reinterpret_cast <uint8_t *>(proof_blob_copy.data ());
116
+ int proof_blob_size = proof_blob_copy.size ();
117
+ integer B = GetBFromProof (integer (discriminant_copy), (const uint8_t *)x_s_copy.data (), proof_blob_ptr, proof_blob_size, num_iterations, recursion);
118
+ }
108
119
return B.to_string ();
109
120
});
110
121
}
0 commit comments