forked from grnet/snarky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow.rs
85 lines (73 loc) · 2.48 KB
/
flow.rs
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
use std::time::Instant;
use circuits::ConstraintSystem;
use protocol::{SRS, Trapdoor, BatchProof, Phase, Verification};
use protocol;
fn main() {
let m = util::parse_arg(1, "50", "m should be a positive integer");
let n = util::parse_arg(2, "40", "n should be a positive integer");
let l = util::parse_arg(3, "30", "l should be a positive integer");
let nr_1 = util::parse_arg(4, "5", "phase 1 repeats should be a non-negative integer");
let nr_2 = util::parse_arg(5, "5", "phase 2 repeats should be a non-negative integer");
let naive = util::parse_arg::<bool>(6, "false", "Should be truly");
println!("--------------------------");
let start = Instant::now();
let qap = {
let start = Instant::now();
match ConstraintSystem::create_default(m, n, l) {
Ok(qap) => {
println!("[+] Created QAP with m:{} n:{} l:{} ({:.2?})",
m,
n,
l,
start.elapsed()
);
qap
},
Err(err) => {
println!("{}", err); std::process::exit(1);
}
}
};
let (mut srs, trp) = {
let start = Instant::now();
let (srs, trp) = SRS::setup_with_unit_trapdoor(&qap);
println!("[+] Initialized SRS ({:.2?})", start.elapsed());
(srs, trp)
};
let mut batch = BatchProof::initiate();
// phase 1 updates
let mut count = 0;
loop {
let start = Instant::now();
protocol::update(&qap, &mut srs, &mut batch, Phase::ONE);
println!("[+] Phase 1 SRS update ({:.2?})", start.elapsed());
count += 1;
if count == nr_1 {
break;
}
}
// phase 2 updates
let mut count = 0;
loop {
let start = Instant::now();
protocol::update(&qap, &mut srs, &mut batch, Phase::TWO);
println!("[+] Phase 2 SRS update ({:.2?})", start.elapsed());
count += 1;
if count == nr_2 {
break;
}
}
let res = {
let start = Instant::now();
let res = match naive {
true => protocol::verify_naive(&qap, &srs, &batch),
false => protocol::verify(&qap, &srs, &batch),
};
println!("[+] {:?} ({:.2?})", res, start.elapsed());
res
};
assert!(bool::from(res));
let elapsed = start.elapsed();
println!("--------------------------");
println!("Time elapsed: {:.2?}", elapsed);
}