-
Notifications
You must be signed in to change notification settings - Fork 0
/
TurboIKOS.py
176 lines (139 loc) · 6.86 KB
/
TurboIKOS.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
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
import sys, random, time, unittest
import math, pickle, gmpy2, argparse
from objsize import get_deep_size
from Cryptodome.Util.number import bytes_to_long, long_to_bytes
import circuit, prover, verifier, tree
from gate import gate
from wire import Wire
from serial import *
import Preprocessing as p
import Fiat_Shamir as fs
from Value import Value
class TestMPCInTheHead(unittest.TestCase):
def test_seed(self):
for test in range(1, len(sys.argv)):
with self.subTest(test = test):
n_parties = 3
temp = circuit.parse(gate, n_parties)
n_wires = temp[4]
n_gate = temp[3]
l_input = temp[1]
n_input = temp[6]
n_output = temp[5]
l_output = temp[2]
n_mul = temp[8]
n_sca = temp[-1]
c_info = temp[10]
Circuit = temp[0]
v_circuit = circuit.parse(gate, 1)
# Create list of wire data
n_parties = 3
wire_data = circuit.wire_data(n_wires)
w = Wire(wire_data, n_parties, n_wires)
#Preprocessing - assign lambdas and triples, generate master seeds
(party_seeds, root) = tree.make_tree(n_parties)
party_seeds = party_seeds[:n_parties]
assign_lambda = p.PRassignLambda(Circuit, w, n_parties, party_seeds)
triples = assign_lambda[0]
#Assign v values
inputs = []
for i in range(n_input):
val = Value()
val.getRand()
inputs.append(val)
expected_output = circuit.compute_output_wires(c_info, Circuit, inputs)
prover_results = prover.run_prover(c_info, Circuit, w, n_parties, inputs, party_seeds, root)
# v_circuit = circuit.parse(gate, 1)
verifier.run_verifier(c_info, v_circuit[0], prover_results, expected_output)
print("passed")
def test_timing_full(self):
COMMIT_BYTES = 32
VALUE_BYTES = 16
SEED_BYTES = int(256/8)
for test in range(1, len(sys.argv)):
with self.subTest(test = test):
#user inputs
n_parties = int(input('number of parties:'))
#read in parameter from console and calculate number of repition
param = int(input('lambda:'))
#Calculate repitition
rep = math.ceil(math.log(0.5**param, 1/n_parties))
#Store each run time in an array
preprocessing_arr = [None]*rep
run_time_arr = [None]*rep
verifier_time_arr = [None]*rep
#initialize size variables
broadcastc_size = 0
viewsc_size = 0
broadcast_size = 0
views_size_PR = 0
temp = circuit.parse(gate, n_parties)
n_wires = temp[4]
n_gate = temp[3]
l_input = temp[1]
n_input = temp[6]
n_output = temp[5]
l_output = temp[2]
n_mul = temp[8]
n_sca = temp[-1]
c_info = temp[10]
Circuit = temp[0]
v_circuit = circuit.parse(gate, 1)
for repetition in range(rep):
# Create list of wire data
wire_data = circuit.wire_data(n_wires)
w = Wire(wire_data, n_parties, n_wires)
#Timing preprocessing
start_time_preprocessing = time.process_time()
#Preprocessing - assign lambdas and triples, generate master seeds
(party_seeds, root) = tree.make_tree(n_parties)
party_seeds = party_seeds[:n_parties]
assign_lambda = p.PRassignLambda(Circuit, w, n_parties, party_seeds)
triples = assign_lambda[0]
#Assign v values
inputs = []
for i in range(n_input):
val = Value()
val.getRand()
inputs.append(val)
#Get preprocessing time
preprocessing_time = time.process_time() - start_time_preprocessing
preprocessing_arr[repetition] = preprocessing_time
expected_output = circuit.compute_output_wires(c_info, Circuit, inputs)
prover_results = prover.run_prover(c_info, Circuit, w, n_parties, inputs, party_seeds, root)
#Start time for verifier
start_time = time.process_time()
#verifier test
verifier.run_verifier(c_info, v_circuit[0], prover_results, expected_output)
#Set time for verifier
verifier_time = time.process_time() - start_time
verifier_time_arr[repetition] = verifier_time
print('prover test passed')
# #Calculate size statistics
# broadcastc_size += COMMIT_BYTES*3
# viewsc_size += COMMIT_BYTES*len(views_committed)
# broadcast_size += len(dict_broadcast)
# views_size_PR += len(open_views)
#Print statistics
#print('number of parties to corrupt:', n_parties - 1)
# print('number of add gates:', n_gate-n_mul-n_sca)
# print('number of mul gates:', n_mul)
# print('number of sca gates:', n_sca)
# preprocessing_time = sum(preprocessing_arr)
# print('preprocessing time:', preprocessing_time, 'seconds')
# run_time = sum(run_time_arr)
# print('run time:', run_time, 'seconds')
# # Proof size = wire size + circuit size + alpha size + zeta size
# print('broadcast commit size:', broadcastc_size)
# print('views commit size:', viewsc_size)
# print('broadcast size:', broadcast_size)
# print('prover views size:', views_size_PR)
# output_wire = [w.v(w.n_wire-1-i) for i in range(n_output)]
# flat_output_wires = serial(output_wire)
# size_output_wires = len(flat_output_wires)
print("passed")
# outputs = {'parties': n_parties, 'proof size': size_output_wires + broadcastc_size + broadcast_size + viewsc_size + views_size_PR,'prover time': preprocessing_time + run_time, 'verifier time': sum(verifier_time_arr), \
# 'preprocessing time': preprocessing_time}
# return outputs
if __name__ == "__main__":
unittest.main(argv=[sys.argv[0]])