-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrs_test.py
90 lines (65 loc) · 2.82 KB
/
srs_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import unittest
from bls import is_identity, compressed_g1_to_bytes, compressed_g2_to_bytes, G1Generator
from keypair import KeyPair
from srs import SRS, SRSParameters
class TestSRS(unittest.TestCase):
def test_no_update__allowed(self):
"""
Checks that if the user makes their private key `1`
Then it is the same as no update.
We note that this is allowed in the ceremony and should be accepted.
"""
# Since the secret is 1, the SRS should not change
secret = 1
keys = KeyPair(secret)
# Size of the setup
num_g1_elements_needed = 3
num_g2_elements_needed = 2
params = SRSParameters(num_g1_elements_needed, num_g2_elements_needed)
srs = SRS(params)
update_proof = srs.update(keys)
self.assertEqual(G1Generator,
update_proof.after_degree_1_point)
def test_zero_update__not_allowed(self):
"""
Checks that if the user makes their private key `0`
Then the resultant SRS is a list of the identity point
We note that this is NOT allowed in the ceremony and should not be accepted.
"""
secret = 0
keys = KeyPair(secret)
# Size of the setup
num_g1_elements_needed = 3
num_g2_elements_needed = 2
params = SRSParameters(num_g1_elements_needed, num_g2_elements_needed)
srs = SRS(params)
srs.update(keys)
for point in srs.g1_points:
self.assertTrue(is_identity(point))
for point in srs.g2_points:
self.assertTrue(is_identity(point))
self.assertFalse(srs.is_correct())
def test_serialisation_consistency(self):
"""
Checks that when we serialise/deserialise are consistent
"""
# Size of the setup
num_g1_elements_needed = 3
num_g2_elements_needed = 2
params = SRSParameters(num_g1_elements_needed, num_g2_elements_needed)
srs = SRS(params)
srs.update(KeyPair(2))
serialised_srs = srs.serialise()
deserialised_srs = SRS.deserialise(params, serialised_srs)
self.assertIsNotNone(deserialised_srs)
# Check that the sizes are the same
self.assertEqual(len(srs.g1_points), len(deserialised_srs.g1_points))
self.assertEqual(len(srs.g2_points), len(deserialised_srs.g2_points))
for point, des_point in zip(srs.g1_points, deserialised_srs.g1_points):
self.assertEqual(compressed_g1_to_bytes(point),
compressed_g1_to_bytes(des_point))
for point, des_point in zip(srs.g2_points, deserialised_srs.g2_points):
self.assertEqual(compressed_g2_to_bytes(point),
compressed_g2_to_bytes(des_point))
if __name__ == '__main__':
unittest.main()