Skip to content

Commit b23db7d

Browse files
committed
Move to main. isort and black
1 parent a5032c8 commit b23db7d

File tree

4 files changed

+95
-42
lines changed

4 files changed

+95
-42
lines changed

comparenweso.py

+36-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
from chiavdf import verify_wesolowski, verify_n_wesolowski
21
import time
32

3+
from chiavdf import verify_n_wesolowski, verify_wesolowski
4+
5+
46
class ClassGroup(tuple):
57
@classmethod
68
def identity_for_discriminant(class_, d):
@@ -36,7 +38,12 @@ def __init__(self, t):
3638
self._discriminant = None
3739

3840
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+
)
4047

4148
def identity(self):
4249
return self.identity_for_discriminant(self.discriminant())
@@ -68,16 +75,23 @@ def serialize(self):
6875
r = self.reduced()
6976
int_size_bits = int(self.discriminant().bit_length())
7077
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+
)
7281

7382

7483
def deserialize_proof(proof_blob, discriminant):
7584
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+
]
7789
return [ClassGroup.from_bytes(blob, discriminant) for blob in proof_arr]
7890

7991

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+
):
8195
"""
8296
Check the nested wesolowski proof. The proof blob
8397
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
97111
iter_list = []
98112
for i in range(4 * int_size, len(proof_blob), 4 * int_size + 8):
99113
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+
)
101117
proof_blob = new_proof_blob
102118

103119
result_bytes = proof_blob[: (2 * int_size)]
@@ -139,19 +155,11 @@ def check_proof_of_time_nwesolowski(discriminant, x, proof_blob, iterations, int
139155
except Exception:
140156
return False
141157

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):
152160
if z == 0:
153161
x = ClassGroup.from_ab_discriminant(int(a), int(b), int(disc))
154-
162+
155163
return check_proof_of_time_nwesolowski(
156164
int(disc),
157165
x,
@@ -160,32 +168,37 @@ def oldie(
160168
sb,
161169
witness,
162170
)
163-
171+
164172
return verify_n_wesolowski(
165173
disc,
166-
a,b,
174+
a,
175+
b,
167176
proof,
168177
iter,
169178
sb,
170179
witness,
171180
)
172181

182+
173183
for z in range(2):
174184
iters = 1000
175185
t1 = time.time()
176186
for i in range(iters):
177187
is_valid = oldie(
178-
str(-131653324254138636653163861414331698305531090221496467927360326686715180966094250598321899621249972220387687148397451395672779897144571112116763666653213748473909547482437246405018707472153290116227072825447643324530509016778432769802300913461285128339119844239772697652504835780459732685000796733645621728639),
188+
str(
189+
-131653324254138636653163861414331698305531090221496467927360326686715180966094250598321899621249972220387687148397451395672779897144571112116763666653213748473909547482437246405018707472153290116227072825447643324530509016778432769802300913461285128339119844239772697652504835780459732685000796733645621728639
190+
),
179191
str(2),
180192
str(1),
181-
bytes.fromhex("003f360be667de706fe886f766fe20240de04fe2c2f91207f1bbdddf20c554ab8d168b2ce9664d75f4613375a0ab12bf8158983574c9f5cd61c6b8a905fd3fa6bbffc5401b4ccedbe093b560293263a226e46302e720726586251116bc689ef09dc70d99e0a090c4409f928e218e85032fdbee02fedd563073be555b75a70a2d6a430033bc7a4926e3504e87698a0ace0dee6364cced2e9142b4e4cbe55a6371aab41e501ceed21d79d3a0dbbd82ce913c5de40b13eb7c59b1b52b6ef270ee603bd5e7fffcc9f5fae6dbd5aeec394181af130c0fdd195b22be745449b7a584ac80fc75ed49acfdb4d650f5cd344f86377ebbbaef5b19a0af3ae08101d1697f5656a52193000000000071c6f40024c342868a0c2a201b1b26a5d52c5d2f92a106c19ff926deb3fba1e74a444ecee3f8f507c062b949a2eaadd442b049417f82e8811526fa83c6d099d75323e068ffeca9dcd163761000c65d21dede72787ac350f25bdd3d29db6e9cb0e22c8124c724db33660c88784e2871b62ecf816846db7b469c71cad9a5dcfc5548ed2dd781006fa15b968facf4d79219646267eb187a670306d1ff1a59fc28ae00d36bb5a1cba659f48aa64a9022711a66105ef14401ff3948add265240aaad329ee76ba4c2300496746b86bcccacff5947c3fcb956cde2cffae10435960d7097f989aac742cf1047887f11584d20297958385e1715fe0f9b69141750c20d8134420eafec68fd10000000001555540006958aabfe4cc5d870e61fef82bcf1f2c3859e2bd8b1177e8a8872376b5cabace5dcb59b6fecada7e522d05f6f0e352939a6bfdf8c454fbe822cfa5ce97d17be0ffde44a4812cde9d04ec5c08dce6f9146586fdc8e081e05ec690b7effe24ea756f3d300f361203b61e1a39220c6eafa7852842674e317dcae5549c78c7144296ff004a6d0d2854c55e4c1de2f17dc4480b81652cfec37124ef41560a28c853482732434d1c006763b2e341528ae0bcc29fb76f1a4dafd99ade4fd75ec9cc9ca3f3d7001bcb6eb71e43eb22169ab721637551a8ec93838eb0825e9ecba9175297a00b146e9fdd244c5b722f29d3c46ec38840ba18f1f06ddec3dea844867386c2e1ac95"),
193+
bytes.fromhex(
194+
"003f360be667de706fe886f766fe20240de04fe2c2f91207f1bbdddf20c554ab8d168b2ce9664d75f4613375a0ab12bf8158983574c9f5cd61c6b8a905fd3fa6bbffc5401b4ccedbe093b560293263a226e46302e720726586251116bc689ef09dc70d99e0a090c4409f928e218e85032fdbee02fedd563073be555b75a70a2d6a430033bc7a4926e3504e87698a0ace0dee6364cced2e9142b4e4cbe55a6371aab41e501ceed21d79d3a0dbbd82ce913c5de40b13eb7c59b1b52b6ef270ee603bd5e7fffcc9f5fae6dbd5aeec394181af130c0fdd195b22be745449b7a584ac80fc75ed49acfdb4d650f5cd344f86377ebbbaef5b19a0af3ae08101d1697f5656a52193000000000071c6f40024c342868a0c2a201b1b26a5d52c5d2f92a106c19ff926deb3fba1e74a444ecee3f8f507c062b949a2eaadd442b049417f82e8811526fa83c6d099d75323e068ffeca9dcd163761000c65d21dede72787ac350f25bdd3d29db6e9cb0e22c8124c724db33660c88784e2871b62ecf816846db7b469c71cad9a5dcfc5548ed2dd781006fa15b968facf4d79219646267eb187a670306d1ff1a59fc28ae00d36bb5a1cba659f48aa64a9022711a66105ef14401ff3948add265240aaad329ee76ba4c2300496746b86bcccacff5947c3fcb956cde2cffae10435960d7097f989aac742cf1047887f11584d20297958385e1715fe0f9b69141750c20d8134420eafec68fd10000000001555540006958aabfe4cc5d870e61fef82bcf1f2c3859e2bd8b1177e8a8872376b5cabace5dcb59b6fecada7e522d05f6f0e352939a6bfdf8c454fbe822cfa5ce97d17be0ffde44a4812cde9d04ec5c08dce6f9146586fdc8e081e05ec690b7effe24ea756f3d300f361203b61e1a39220c6eafa7852842674e317dcae5549c78c7144296ff004a6d0d2854c55e4c1de2f17dc4480b81652cfec37124ef41560a28c853482732434d1c006763b2e341528ae0bcc29fb76f1a4dafd99ade4fd75ec9cc9ca3f3d7001bcb6eb71e43eb22169ab721637551a8ec93838eb0825e9ecba9175297a00b146e9fdd244c5b722f29d3c46ec38840ba18f1f06ddec3dea844867386c2e1ac95"
195+
),
182196
33554432,
183197
1024,
184198
2,
185-
z
199+
z,
186200
)
187201
assert is_valid
188202

189203
t2 = time.time()
190204
print(f"{z} IPS: {iters / (t2 - t1)}")
191-

setup.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import os
2+
import platform
23
import re
34
import shutil
4-
import sys
5-
import platform
65
import subprocess
7-
6+
import sys
87
from distutils.command.build import build # type: ignore
98
from distutils.command.install import install
109
from distutils.version import LooseVersion
11-
from setuptools.command.build_ext import build_ext
12-
from setuptools import setup, setuptools, Extension, Command
1310

11+
from setuptools import Command, Extension, setup, setuptools
12+
from setuptools.command.build_ext import build_ext
1413

1514
BUILD_HOOKS = []
1615
INSTALL_HOOKS = []

tests/test_verifier.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from chiavdf import prove, verify_wesolowski, create_discriminant
21
import secrets
32
import time
43

4+
from chiavdf import create_discriminant, prove, verify_wesolowski
5+
56

67
def test_prove_and_verify():
78
discriminant_challenge = secrets.token_bytes(10)

tools/gen_pprods.py

+53-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,50 @@
11
#!/usr/bin/python3
2-
import sys, math
2+
import math
3+
import sys
4+
35

46
def dbg(*args):
57
print(*args, file=sys.stderr)
68

7-
primes = 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, \
8-
67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, \
9-
139, 149
9+
10+
primes = (
11+
2,
12+
3,
13+
5,
14+
7,
15+
11,
16+
13,
17+
17,
18+
19,
19+
23,
20+
29,
21+
31,
22+
37,
23+
41,
24+
43,
25+
47,
26+
53,
27+
59,
28+
61,
29+
67,
30+
71,
31+
73,
32+
79,
33+
83,
34+
89,
35+
97,
36+
101,
37+
103,
38+
107,
39+
109,
40+
113,
41+
127,
42+
131,
43+
137,
44+
139,
45+
149,
46+
)
47+
1048

1149
def is_prime(n):
1250
if n in primes:
@@ -21,8 +59,9 @@ def is_prime(n):
2159
return False
2260
raise ValueError("Too big n=%d" % (n,))
2361

62+
2463
def print_pprods_h(prods, factors):
25-
tab = ' '
64+
tab = " "
2665
tmpl = """
2766
#ifndef PPRODS_H
2867
#define PPRODS_H
@@ -37,13 +76,14 @@ def print_pprods_h(prods, factors):
3776
#endif // PPRODS_H
3877
"""
3978
tmpl = tmpl.strip()
40-
prods_str = ''
79+
prods_str = ""
4180
for i, pr in enumerate(prods):
42-
factors_str = '*'.join(map(str, factors[i]))
43-
extra_spaces = ' ' * (16 - (pr.bit_length() + 3) // 4)
44-
prods_str += tab + '0x%x, %s// %s\n' % (pr, extra_spaces, factors_str)
81+
factors_str = "*".join(map(str, factors[i]))
82+
extra_spaces = " " * (16 - (pr.bit_length() + 3) // 4)
83+
prods_str += tab + "0x%x, %s// %s\n" % (pr, extra_spaces, factors_str)
4584
print(tmpl % (prods_str.rstrip(),))
4685

86+
4787
n = int(sys.argv[1])
4888
cnt = 0
4989
pr = 1
@@ -52,12 +92,12 @@ def print_pprods_h(prods, factors):
5292
factors = []
5393
for i in range(3, n):
5494
if is_prime(i):
55-
#print(i, '', end='')
95+
# print(i, '', end='')
5696
cnt += 1
5797
pr *= i
5898
if pr.bit_length() > 64:
5999
pr //= i
60-
#print('%s: %s' % (hex(pr), arr))
100+
# print('%s: %s' % (hex(pr), arr))
61101
prods.append(pr)
62102
factors.append(arr)
63103
pr = i
@@ -67,5 +107,5 @@ def print_pprods_h(prods, factors):
67107
print_pprods_h(prods, factors)
68108

69109
dbg()
70-
dbg('n_primes=%d n_prods=%d last_prime=%d' % (cnt, len(prods), factors[-1][-1]))
71-
#dbg(*list('%s,' % (hex(i),) for i in prods))
110+
dbg("n_primes=%d n_prods=%d last_prime=%d" % (cnt, len(prods), factors[-1][-1]))
111+
# dbg(*list('%s,' % (hex(i),) for i in prods))

0 commit comments

Comments
 (0)