1
- from chiavdf import verify_wesolowski , verify_n_wesolowski
2
1
import time
3
2
3
+ from chiavdf import verify_n_wesolowski , verify_wesolowski
4
+
5
+
4
6
class ClassGroup (tuple ):
5
7
@classmethod
6
8
def identity_for_discriminant (class_ , d ):
@@ -36,7 +38,12 @@ def __init__(self, t):
36
38
self ._discriminant = None
37
39
38
40
def __eq__ (self , obj ):
39
- return isinstance (obj , ClassGroup ) and obj [0 ] == self [0 ] and obj [1 ] == self [1 ] and obj [2 ] == self [2 ]
41
+ return (
42
+ isinstance (obj , ClassGroup )
43
+ and obj [0 ] == self [0 ]
44
+ and obj [1 ] == self [1 ]
45
+ and obj [2 ] == self [2 ]
46
+ )
40
47
41
48
def identity (self ):
42
49
return self .identity_for_discriminant (self .discriminant ())
@@ -68,16 +75,23 @@ def serialize(self):
68
75
r = self .reduced ()
69
76
int_size_bits = int (self .discriminant ().bit_length ())
70
77
int_size = (int_size_bits + 16 ) >> 4
71
- return b"" .join ([x .to_bytes (int_size , "big" , signed = True ) for x in [r [0 ], r [1 ]]])
78
+ return b"" .join (
79
+ [x .to_bytes (int_size , "big" , signed = True ) for x in [r [0 ], r [1 ]]]
80
+ )
72
81
73
82
74
83
def deserialize_proof (proof_blob , discriminant ):
75
84
int_size = (discriminant .bit_length () + 16 ) >> 4
76
- proof_arr = [proof_blob [_ : _ + 2 * int_size ] for _ in range (0 , len (proof_blob ), 2 * int_size )]
85
+ proof_arr = [
86
+ proof_blob [_ : _ + 2 * int_size ]
87
+ for _ in range (0 , len (proof_blob ), 2 * int_size )
88
+ ]
77
89
return [ClassGroup .from_bytes (blob , discriminant ) for blob in proof_arr ]
78
90
79
91
80
- def check_proof_of_time_nwesolowski (discriminant , x , proof_blob , iterations , int_size_bits , depth ):
92
+ def check_proof_of_time_nwesolowski (
93
+ discriminant , x , proof_blob , iterations , int_size_bits , depth
94
+ ):
81
95
"""
82
96
Check the nested wesolowski proof. The proof blob
83
97
includes the output of the VDF, along with the proof. The following
@@ -97,7 +111,9 @@ def check_proof_of_time_nwesolowski(discriminant, x, proof_blob, iterations, int
97
111
iter_list = []
98
112
for i in range (4 * int_size , len (proof_blob ), 4 * int_size + 8 ):
99
113
iter_list .append (int .from_bytes (proof_blob [i : (i + 8 )], byteorder = "big" ))
100
- new_proof_blob = new_proof_blob + proof_blob [(i + 8 ) : (i + 8 + 4 * int_size )]
114
+ new_proof_blob = (
115
+ new_proof_blob + proof_blob [(i + 8 ) : (i + 8 + 4 * int_size )]
116
+ )
101
117
proof_blob = new_proof_blob
102
118
103
119
result_bytes = proof_blob [: (2 * int_size )]
@@ -139,19 +155,11 @@ def check_proof_of_time_nwesolowski(discriminant, x, proof_blob, iterations, int
139
155
except Exception :
140
156
return False
141
157
142
- def oldie (
143
- disc ,
144
- a ,
145
- b ,
146
- proof ,
147
- iter ,
148
- sb ,
149
- witness ,
150
- doold
151
- ):
158
+
159
+ def oldie (disc , a , b , proof , iter , sb , witness , doold ):
152
160
if z == 0 :
153
161
x = ClassGroup .from_ab_discriminant (int (a ), int (b ), int (disc ))
154
-
162
+
155
163
return check_proof_of_time_nwesolowski (
156
164
int (disc ),
157
165
x ,
@@ -160,32 +168,37 @@ def oldie(
160
168
sb ,
161
169
witness ,
162
170
)
163
-
171
+
164
172
return verify_n_wesolowski (
165
173
disc ,
166
- a ,b ,
174
+ a ,
175
+ b ,
167
176
proof ,
168
177
iter ,
169
178
sb ,
170
179
witness ,
171
180
)
172
181
182
+
173
183
for z in range (2 ):
174
184
iters = 1000
175
185
t1 = time .time ()
176
186
for i in range (iters ):
177
187
is_valid = oldie (
178
- str (- 131653324254138636653163861414331698305531090221496467927360326686715180966094250598321899621249972220387687148397451395672779897144571112116763666653213748473909547482437246405018707472153290116227072825447643324530509016778432769802300913461285128339119844239772697652504835780459732685000796733645621728639 ),
188
+ str (
189
+ - 131653324254138636653163861414331698305531090221496467927360326686715180966094250598321899621249972220387687148397451395672779897144571112116763666653213748473909547482437246405018707472153290116227072825447643324530509016778432769802300913461285128339119844239772697652504835780459732685000796733645621728639
190
+ ),
179
191
str (2 ),
180
192
str (1 ),
181
- bytes .fromhex ("003f360be667de706fe886f766fe20240de04fe2c2f91207f1bbdddf20c554ab8d168b2ce9664d75f4613375a0ab12bf8158983574c9f5cd61c6b8a905fd3fa6bbffc5401b4ccedbe093b560293263a226e46302e720726586251116bc689ef09dc70d99e0a090c4409f928e218e85032fdbee02fedd563073be555b75a70a2d6a430033bc7a4926e3504e87698a0ace0dee6364cced2e9142b4e4cbe55a6371aab41e501ceed21d79d3a0dbbd82ce913c5de40b13eb7c59b1b52b6ef270ee603bd5e7fffcc9f5fae6dbd5aeec394181af130c0fdd195b22be745449b7a584ac80fc75ed49acfdb4d650f5cd344f86377ebbbaef5b19a0af3ae08101d1697f5656a52193000000000071c6f40024c342868a0c2a201b1b26a5d52c5d2f92a106c19ff926deb3fba1e74a444ecee3f8f507c062b949a2eaadd442b049417f82e8811526fa83c6d099d75323e068ffeca9dcd163761000c65d21dede72787ac350f25bdd3d29db6e9cb0e22c8124c724db33660c88784e2871b62ecf816846db7b469c71cad9a5dcfc5548ed2dd781006fa15b968facf4d79219646267eb187a670306d1ff1a59fc28ae00d36bb5a1cba659f48aa64a9022711a66105ef14401ff3948add265240aaad329ee76ba4c2300496746b86bcccacff5947c3fcb956cde2cffae10435960d7097f989aac742cf1047887f11584d20297958385e1715fe0f9b69141750c20d8134420eafec68fd10000000001555540006958aabfe4cc5d870e61fef82bcf1f2c3859e2bd8b1177e8a8872376b5cabace5dcb59b6fecada7e522d05f6f0e352939a6bfdf8c454fbe822cfa5ce97d17be0ffde44a4812cde9d04ec5c08dce6f9146586fdc8e081e05ec690b7effe24ea756f3d300f361203b61e1a39220c6eafa7852842674e317dcae5549c78c7144296ff004a6d0d2854c55e4c1de2f17dc4480b81652cfec37124ef41560a28c853482732434d1c006763b2e341528ae0bcc29fb76f1a4dafd99ade4fd75ec9cc9ca3f3d7001bcb6eb71e43eb22169ab721637551a8ec93838eb0825e9ecba9175297a00b146e9fdd244c5b722f29d3c46ec38840ba18f1f06ddec3dea844867386c2e1ac95" ),
193
+ bytes .fromhex (
194
+ "003f360be667de706fe886f766fe20240de04fe2c2f91207f1bbdddf20c554ab8d168b2ce9664d75f4613375a0ab12bf8158983574c9f5cd61c6b8a905fd3fa6bbffc5401b4ccedbe093b560293263a226e46302e720726586251116bc689ef09dc70d99e0a090c4409f928e218e85032fdbee02fedd563073be555b75a70a2d6a430033bc7a4926e3504e87698a0ace0dee6364cced2e9142b4e4cbe55a6371aab41e501ceed21d79d3a0dbbd82ce913c5de40b13eb7c59b1b52b6ef270ee603bd5e7fffcc9f5fae6dbd5aeec394181af130c0fdd195b22be745449b7a584ac80fc75ed49acfdb4d650f5cd344f86377ebbbaef5b19a0af3ae08101d1697f5656a52193000000000071c6f40024c342868a0c2a201b1b26a5d52c5d2f92a106c19ff926deb3fba1e74a444ecee3f8f507c062b949a2eaadd442b049417f82e8811526fa83c6d099d75323e068ffeca9dcd163761000c65d21dede72787ac350f25bdd3d29db6e9cb0e22c8124c724db33660c88784e2871b62ecf816846db7b469c71cad9a5dcfc5548ed2dd781006fa15b968facf4d79219646267eb187a670306d1ff1a59fc28ae00d36bb5a1cba659f48aa64a9022711a66105ef14401ff3948add265240aaad329ee76ba4c2300496746b86bcccacff5947c3fcb956cde2cffae10435960d7097f989aac742cf1047887f11584d20297958385e1715fe0f9b69141750c20d8134420eafec68fd10000000001555540006958aabfe4cc5d870e61fef82bcf1f2c3859e2bd8b1177e8a8872376b5cabace5dcb59b6fecada7e522d05f6f0e352939a6bfdf8c454fbe822cfa5ce97d17be0ffde44a4812cde9d04ec5c08dce6f9146586fdc8e081e05ec690b7effe24ea756f3d300f361203b61e1a39220c6eafa7852842674e317dcae5549c78c7144296ff004a6d0d2854c55e4c1de2f17dc4480b81652cfec37124ef41560a28c853482732434d1c006763b2e341528ae0bcc29fb76f1a4dafd99ade4fd75ec9cc9ca3f3d7001bcb6eb71e43eb22169ab721637551a8ec93838eb0825e9ecba9175297a00b146e9fdd244c5b722f29d3c46ec38840ba18f1f06ddec3dea844867386c2e1ac95"
195
+ ),
182
196
33554432 ,
183
197
1024 ,
184
198
2 ,
185
- z
199
+ z ,
186
200
)
187
201
assert is_valid
188
202
189
203
t2 = time .time ()
190
204
print (f"{ z } IPS: { iters / (t2 - t1 )} " )
191
-
0 commit comments