-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_fibonacci.py
61 lines (51 loc) · 2.68 KB
/
test_fibonacci.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
#!/usr/bin/python3.10
from scripts.util import extract_contraints, generate_circuit, generate_input, generate_input_fibonnaci, measure_command
def test_circuit(circuit_name, input_path,pot_path,verbose=True,time = True, memory = True):
# print("inside test_circuit")
r1cs_path = 'output/compiled_circuit/compiled_{}/{}.r1cs'
# print("r1cs_path: ",r1cs_path)
t_c,m_c = measure_command(f'./scripts/compile_circuit.sh ./circuits/benchmark/{circuit_name}.circom {input_path} --nodejs',time,memory)
if verbose:
print(f'[{circuit_name}] Compile Circuit: {"" if t_c is None else f"{t_c} seconds"} {"" if m_c is None else f"{m_c} KB"}')
constraints = extract_contraints(r1cs_path.format(circuit_name,circuit_name))
if verbose:
print(f'[{circuit_name}] Constraints: {constraints}')
# print("before setup prover")
t_sp,m_sp = measure_command(f'./scripts/proving_system/setup_prover.sh {circuit_name} {pot_path}',time,memory)
if verbose:
print(f'[{circuit_name}] Setup Prover: {"" if t_sp is None else f"{t_sp} seconds"} {"" if m_sp is None else f"{m_sp} KB"}')
# print("after setup prover")
# print("before prove")
t_p,m_p = measure_command(f'./scripts/proving_system/prover.sh {circuit_name} ',time,memory)
if verbose:
print(f'[{circuit_name}] Prover: {"" if t_p is None else f"{t_p} seconds"} {"" if m_p is None else f"{m_p} KB"}')
# print("after prove")
t_v,m_v = measure_command(f'./scripts/proving_system/verifier.sh {circuit_name}',time,memory)
if verbose:
print(f'[{circuit_name}] Verifier: {"" if t_v is None else f"{t_v} seconds"} {"" if m_v is None else f"{m_v} KB"}')
return {'CIRCUIT':circuit_name,
'INPUT SIZE':input_path.split('_')[-1].split('.')[0],
'CONSTRAINTS':constraints,
'COMPILE_TIME':t_c,
'COMPILE_MEMORY':m_c,
'SETUP_TIME':t_sp,
'SETUP_MEMORY':m_sp,
'PROVER_TIME':t_p,
'PROVER_MEMORY':m_p,
'VERIFIER_TIME':t_v,
'VERIFIER_MEMORY':m_v}
if __name__ == '__main__':
# test fibonacci circuit
TIME, MEMORY = True, True
POT = './powersoftau/28pot.ptau'
NUM = 100000
circuit_name = f'fibonacci'
# print("before generate_circuit")
generate_circuit({'NUM':NUM},f'./circuits/base/{circuit_name}.circom',id=NUM)
# print("after generate_circuit")
# print("before generate_input")
generate_input_fibonnaci(f'./input/input_fibonacci.json')
# print("after generate_input")
# print("before test_circuit")
measures = test_circuit(f'{circuit_name}_{NUM}',f'/input/input_fibonacci.json',POT,time=TIME,memory=MEMORY)
print("measures: ",measures)