-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathexpr_based_logup.rs
More file actions
144 lines (119 loc) · 5.4 KB
/
Copy pathexpr_based_logup.rs
File metadata and controls
144 lines (119 loc) · 5.4 KB
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
use std::{array, time::Duration};
use ark_std::test_rng;
use criterion::*;
use ff_ext::FromUniformBytes;
use itertools::Itertools;
use p3_field::extension::BinomialExtensionField;
use p3_goldilocks::Goldilocks;
use subprotocols::{
expression::{Constant, Expression, Witness},
sumcheck::SumcheckProverState,
test_utils::{random_point, random_poly},
zerocheck::ZerocheckProverState,
};
use transcript::BasicTranscript as Transcript;
criterion_group!(benches, zerocheck_fn, sumcheck_fn);
criterion_main!(benches);
const NUM_SAMPLES: usize = 10;
const NV: [usize; 2] = [25, 26];
fn sumcheck_fn(c: &mut Criterion) {
type E = BinomialExtensionField<Goldilocks, 2>;
for nv in NV {
// expand more input size once runtime is acceptable
let mut group = c.benchmark_group(format!("logup_sumcheck_nv_{}", nv));
group.sample_size(NUM_SAMPLES);
// Benchmark the proving time
group.bench_function(
BenchmarkId::new("prove_sumcheck", format!("sumcheck_nv_{}", nv)),
|b| {
b.iter_custom(|iters| {
let mut time = Duration::new(0, 0);
for _ in 0..iters {
let mut rng = test_rng();
// Initialize logup expression.
let eq = Expression::Wit(Witness::EqPoly(0));
let beta = Expression::Const(Constant::Challenge(0));
let [d0, d1, n0, n1] =
array::from_fn(|i| Expression::Wit(Witness::ExtPoly(i)));
let expr = eq * (d0.clone() * d1.clone() + beta * (d0 * n1 + d1 * n0));
// Randomly generate point and witness.
let point = random_point(&mut rng, nv);
let d0 = random_poly(&mut rng, nv);
let d1 = random_poly(&mut rng, nv);
let n0 = random_poly(&mut rng, nv);
let n1 = random_poly(&mut rng, nv);
let mut ext_mles = [d0.clone(), d1.clone(), n0.clone(), n1.clone()];
let challenges = vec![E::random(&mut rng)];
let ext_mle_refs =
ext_mles.iter_mut().map(|v| v.as_mut_slice()).collect_vec();
let mut prover_transcript = Transcript::new(b"test");
let prover = SumcheckProverState::new(
expr,
&[&point],
ext_mle_refs,
vec![],
&challenges,
&mut prover_transcript,
);
let instant = std::time::Instant::now();
let _ = black_box(prover.prove());
let elapsed = instant.elapsed();
time += elapsed;
}
time
});
},
);
group.finish();
}
}
fn zerocheck_fn(c: &mut Criterion) {
type E = BinomialExtensionField<Goldilocks, 2>;
for nv in NV {
// expand more input size once runtime is acceptable
let mut group = c.benchmark_group(format!("logup_sumcheck_nv_{}", nv));
group.sample_size(NUM_SAMPLES);
// Benchmark the proving time
group.bench_function(
BenchmarkId::new("prove_sumcheck", format!("sumcheck_nv_{}", nv)),
|b| {
b.iter_custom(|iters| {
let mut time = Duration::new(0, 0);
for _ in 0..iters {
// Initialize logup expression.
let mut rng = test_rng();
let beta = Expression::Const(Constant::Challenge(0));
let [d0, d1, n0, n1] =
array::from_fn(|i| Expression::Wit(Witness::ExtPoly(i)));
let expr = d0.clone() * d1.clone() + beta * (d0 * n1 + d1 * n0);
// Randomly generate point and witness.
let point = random_point(&mut rng, nv);
let d0 = random_poly(&mut rng, nv);
let d1 = random_poly(&mut rng, nv);
let n0 = random_poly(&mut rng, nv);
let n1 = random_poly(&mut rng, nv);
let mut ext_mles = [d0.clone(), d1.clone(), n0.clone(), n1.clone()];
let challenges = vec![E::random(&mut rng)];
let ext_mle_refs =
ext_mles.iter_mut().map(|v| v.as_mut_slice()).collect_vec();
let mut prover_transcript = Transcript::new(b"test");
let prover = ZerocheckProverState::new(
vec![expr],
&[&point],
ext_mle_refs,
vec![],
&challenges,
&mut prover_transcript,
);
let instant = std::time::Instant::now();
let _ = black_box(prover.prove());
let elapsed = instant.elapsed();
time += elapsed;
}
time
});
},
);
group.finish();
}
}