-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bounded_randomness_lib.mpc
330 lines (225 loc) · 8.56 KB
/
test_bounded_randomness_lib.mpc
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
from Compiler.bounded_randomness_lib import store_randvals_to_db, load_randvals_from_db, get_next_randval, get_next_randvals, get_next_randvals_vectorized
print_ln("----------------------------------- Testing Bounded Randomness Lib -----------------------------------")
class bcolors:
HEADER = '\033[95m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def test(actual, expected):
total_tests = cint.load_mem(3000)
total_tests += 1
total_tests.store_in_mem(3000)
if_then(actual != expected)
print_ln(bcolors.FAIL + 'FAILURE: expected %s, got %s' +
bcolors.ENDC, expected, actual)
failed_tests = cint.load_mem(6000)
failed_tests += 1
failed_tests.store_in_mem(6000)
else_then()
print_ln(bcolors.OKGREEN + "TEST: %s equals %s" +
bcolors.ENDC, expected, actual)
end_if()
def get_absolute_bound(bound):
return 2**bound
def test_bounded_randomness(test_bound, test_total, db=True):
correct_randval = 0
if db:
store_randvals_to_db(test_bound, test_total)
load_randvals_from_db(test_bound, test_total)
absolute_bound = get_absolute_bound(test_bound)
for _ in range(test_total):
next_randval = get_next_randval(test_bound)
comparison = next_randval.reveal() < absolute_bound
correct_randval += comparison
test(correct_randval, test_total)
def test_bounded_randomness_vectorized(test_bound, test_total, db=True):
correct_randval = 0
if db:
store_randvals_to_db(test_bound, test_total)
load_randvals_from_db(test_bound, test_total)
absolute_bound = get_absolute_bound(test_bound)
randvals = get_next_randvals_vectorized(test_bound, test_total)
next_randvals = Array(test_total, sint)
vstms(test_total, randvals, next_randvals.address)
# Check bound of all the generated secret values.
for next_randval in next_randvals:
correct_randval += next_randval.reveal() < absolute_bound
test(correct_randval, test_total)
def test_bounded_randomness_list(test_bound, test_total, db=True):
correct_randval = 0
if db:
store_randvals_to_db(test_bound, test_total)
load_randvals_from_db(test_bound, test_total)
absolute_bound = get_absolute_bound(test_bound)
randvals = get_next_randvals(test_bound, test_total)
for next_randval in randvals:
correct_randval += next_randval.reveal() < absolute_bound
test(correct_randval, test_total)
def test_bounded_randomness_8_100():
test_bound = 8
test_total = 1000
test_bounded_randomness(test_bound, test_total)
def test_bounded_randomness_16_100():
test_bound = 16
test_total = 100
test_bounded_randomness(test_bound, test_total)
def test_bounded_randomness_32_100():
test_bound = 32
test_total = 100
test_bounded_randomness(test_bound, test_total)
def test_bounded_randomness_8_1000():
test_bound = 8
test_total = 1000
test_bounded_randomness(test_bound, test_total)
def test_bounded_randomness_16_1000():
test_bound = 16
test_total = 1000
test_bounded_randomness(test_bound, test_total)
def test_bounded_randomness_32_1000():
test_bound = 32
test_total = 1000
test_bounded_randomness(test_bound, test_total)
def test_bounded_randomness_8_10000():
test_bound = 8
test_total = 10000
test_bounded_randomness(test_bound, test_total)
def test_bounded_randomness_16_10000():
test_bound = 16
test_total = 10000
test_bounded_randomness(test_bound, test_total)
def test_bounded_randomness_32_10000():
test_bound = 32
test_total = 10000
test_bounded_randomness(test_bound, test_total)
def test_bounded_randomness_vectorized_8_100():
test_bound = 8
test_total = 100
test_bounded_randomness_vectorized(test_bound, test_total)
def test_bounded_randomness_vectorized_16_100():
test_bound = 16
test_total = 100
test_bounded_randomness_vectorized(test_bound, test_total)
def test_bounded_randomness_vectorized_32_100():
test_bound = 32
test_total = 100
test_bounded_randomness_vectorized(test_bound, test_total)
def test_bounded_randomness_vectorized_8_1000():
test_bound = 8
test_total = 1000
test_bounded_randomness_vectorized(test_bound, test_total)
def test_bounded_randomness_vectorized_16_1000():
test_bound = 16
test_total = 1000
test_bounded_randomness_vectorized(test_bound, test_total)
def test_bounded_randomness_vectorized_32_1000():
test_bound = 32
test_total = 1000
test_bounded_randomness_vectorized(test_bound, test_total)
def test_bounded_randomness_vectorized_8_10000():
test_bound = 8
test_total = 10000
test_bounded_randomness_vectorized(test_bound, test_total)
def test_bounded_randomness_vectorized_16_10000():
test_bound = 16
test_total = 10000
test_bounded_randomness_vectorized(test_bound, test_total)
def test_bounded_randomness_vectorized_32_10000():
test_bound = 32
test_total = 10000
test_bounded_randomness_vectorized(test_bound, test_total)
def test_bounded_randomness_list_8_100():
test_bound = 8
test_total = 100
test_bounded_randomness_list(test_bound, test_total)
def test_bounded_randomness_list_16_100():
test_bound = 16
test_total = 100
test_bounded_randomness_list(test_bound, test_total)
def test_bounded_randomness_list_32_100():
test_bound = 32
test_total = 100
test_bounded_randomness_list(test_bound, test_total)
def test_bounded_randomness_list_8_1000():
test_bound = 8
test_total = 1000
test_bounded_randomness_list(test_bound, test_total)
def test_bounded_randomness_list_16_1000():
test_bound = 16
test_total = 1000
test_bounded_randomness_list(test_bound, test_total)
def test_bounded_randomness_list_32_1000():
test_bound = 32
test_total = 1000
test_bounded_randomness_list(test_bound, test_total)
def test_bounded_randomness_list_8_10000():
test_bound = 8
test_total = 10000
test_bounded_randomness_list(test_bound, test_total)
def test_bounded_randomness_list_16_10000():
test_bound = 16
test_total = 10000
test_bounded_randomness_list(test_bound, test_total)
def test_bounded_randomness_list_32_10000():
test_bound = 32
test_total = 10000
test_bounded_randomness_list(test_bound, test_total)
# stress tests
def test_bounded_randomness_40_100000():
test_bound = 40
test_total = 100000
test_bounded_randomness(test_bound, test_total)
def test_bounded_randomness_vectorized_40_100000():
test_bound = 40
test_total = 100000
test_bounded_randomness_vectorized(test_bound, test_total)
def test_bounded_randomness_list_40_100000():
test_bound = 40
test_total = 100000
test_bounded_randomness_list(test_bound, test_total)
# no db tests:
def test_bounded_randomness_no_db_32_100():
test_bound = 32
test_total = 100
test_bounded_randomness(test_bound, test_total, False)
def test_bounded_randomness_no_db_vectorized_32_100():
test_bound = 32
test_total = 100
test_bounded_randomness_vectorized(test_bound, test_total, False)
def test_bounded_randomness_no_db_list_32_100():
test_bound = 32
test_total = 100
test_bounded_randomness_list(test_bound, test_total, False)
test_bounded_randomness_8_1000()
test_bounded_randomness_16_1000()
test_bounded_randomness_32_1000()
test_bounded_randomness_8_10000()
test_bounded_randomness_16_10000()
test_bounded_randomness_32_10000()
test_bounded_randomness_vectorized_8_100()
test_bounded_randomness_vectorized_16_100()
test_bounded_randomness_vectorized_32_100()
test_bounded_randomness_vectorized_8_1000()
test_bounded_randomness_vectorized_16_1000()
test_bounded_randomness_vectorized_32_1000()
test_bounded_randomness_vectorized_8_10000()
test_bounded_randomness_vectorized_16_10000()
test_bounded_randomness_vectorized_32_10000()
test_bounded_randomness_list_8_100()
test_bounded_randomness_list_16_100()
test_bounded_randomness_list_32_100()
test_bounded_randomness_list_8_1000()
test_bounded_randomness_list_16_1000()
test_bounded_randomness_list_32_1000()
test_bounded_randomness_list_8_10000()
test_bounded_randomness_list_16_10000()
test_bounded_randomness_list_32_10000()
test_bounded_randomness_vectorized_40_100000()
test_bounded_randomness_list_40_100000()
test_bounded_randomness_no_db_32_100()
test_bounded_randomness_no_db_vectorized_32_100()
test_bounded_randomness_no_db_list_32_100()
print_str(
"\n \n TESTS:" + bcolors.OKGREEN + " %s" + bcolors.ENDC +
"/" + bcolors.FAIL + "%s failed" + bcolors.ENDC + "\n \n",
cint.load_mem(3000), cint.load_mem(6000))