Skip to content

Commit 33f1a40

Browse files
authored
Merge pull request #3226 from o1-labs/volhovm/commit-vs-interpolate-benches
Add a benchmark comparing IPA commitment w/ and w/o Lagrange
2 parents c42d638 + 3c89e47 commit 33f1a40

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

poly-commitment/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ark-serialize.workspace = true
1818
blake2.workspace = true
1919
hex.workspace = true
2020
itertools.workspace = true
21+
num-bigint.workspace = true
2122
once_cell.workspace = true
2223
rand.workspace = true
2324
rand_core.workspace = true

poly-commitment/benches/ipa.rs

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
//! Run this bench using `cargo criterion -p poly-commitment --bench ipa`
22
3-
use ark_ff::UniformRand;
4-
use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial, Radix2EvaluationDomain};
3+
use ark_ff::{UniformRand, Zero};
4+
use ark_poly::{
5+
univariate::DensePolynomial, DenseUVPolynomial, EvaluationDomain, Evaluations,
6+
Radix2EvaluationDomain,
7+
};
58
use criterion::{black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
69
use groupmap::GroupMap;
710
use mina_curves::pasta::{Fp, Vesta, VestaParameters};
811
use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, sponge::DefaultFqSponge, FqSponge};
12+
use num_bigint::BigUint;
13+
use o1_utils::{BigUintFieldHelpers, FieldHelpers};
914
use poly_commitment::{
1015
commitment::CommitmentCurve, ipa::SRS, utils::DensePolynomialOrEvaluations, PolyComm, SRS as _,
1116
};
17+
use rand::Rng;
1218

1319
fn benchmark_ipa_commit_vesta(c: &mut Criterion) {
1420
let mut group = c.benchmark_group("IPA Commit");
@@ -41,6 +47,89 @@ fn benchmark_ipa_commit_vesta(c: &mut Criterion) {
4147
}
4248
}
4349

50+
// This benchmark demonstrates that
51+
// `commit_evaluations_non_hiding` is generally faster than
52+
// `commit_non_hiding` when committing evaluations; and especially so
53+
// when the evaluations vector is sparse or contains small elements.
54+
fn benchmark_ipa_commit_evals_vesta(c: &mut Criterion) {
55+
let mut group = c.benchmark_group("IPA Commit Evaluations");
56+
let mut rng = o1_utils::tests::make_test_rng(None);
57+
58+
group.measurement_time(core::time::Duration::from_secs(10));
59+
60+
let srs_size_log = 15;
61+
62+
let n = 1 << srs_size_log;
63+
let srs = SRS::<Vesta>::create(n);
64+
let domain = Radix2EvaluationDomain::new(n).unwrap();
65+
srs.get_lagrange_basis_from_domain_size(n);
66+
67+
for sparsity in [0.05, 0.2, 0.5, 0.99].into_iter() {
68+
for bitlen in [16, 32, 64, 128, 256].into_iter() {
69+
// When bitlen > |Fp|, Fp::rand() % bitlenmod will return
70+
// just field value without performing modulo reduction.
71+
let bitlenmod: BigUint = Fp::from(1).to_biguint() << bitlen;
72+
group.bench_function(
73+
format!(
74+
"com w/o Lagrange (|SRS| 2^{{{}}}, sparsity {}%, bitlen {})",
75+
srs_size_log,
76+
(sparsity * 100.0) as usize,
77+
bitlen
78+
),
79+
|b| {
80+
b.iter_batched(
81+
|| {
82+
let evaluations: Vec<Fp> = (0..n)
83+
.map(|_| {
84+
if rng.gen::<f64>() < sparsity {
85+
(Fp::rand(&mut rng).to_biguint() % bitlenmod.clone())
86+
.to_field()
87+
.unwrap()
88+
} else {
89+
Fp::zero()
90+
}
91+
})
92+
.collect();
93+
Evaluations::from_vec_and_domain(evaluations, domain)
94+
},
95+
|evals| black_box(srs.commit_non_hiding(&evals.interpolate(), 1)),
96+
BatchSize::LargeInput,
97+
)
98+
},
99+
);
100+
101+
group.bench_function(
102+
format!(
103+
"com Lagrange (|SRS| 2^{{{}}}, sparsity {}%, bitlen {})",
104+
srs_size_log,
105+
(sparsity * 100.0) as usize,
106+
bitlen
107+
),
108+
|b| {
109+
b.iter_batched(
110+
|| {
111+
let evaluations: Vec<Fp> = (0..n)
112+
.map(|_| {
113+
if rng.gen::<f64>() < sparsity {
114+
(Fp::rand(&mut rng).to_biguint() % bitlenmod.clone())
115+
.to_field()
116+
.unwrap()
117+
} else {
118+
Fp::zero()
119+
}
120+
})
121+
.collect();
122+
Evaluations::from_vec_and_domain(evaluations, domain)
123+
},
124+
|evals| black_box(srs.commit_evaluations_non_hiding(domain, &evals)),
125+
BatchSize::LargeInput,
126+
)
127+
},
128+
);
129+
}
130+
}
131+
}
132+
44133
fn benchmark_ipa_open_vesta(c: &mut Criterion) {
45134
let mut group = c.benchmark_group("IPA");
46135
let group_map = <Vesta as CommitmentCurve>::Map::setup();
@@ -88,6 +177,7 @@ fn benchmark_ipa_open_vesta(c: &mut Criterion) {
88177
criterion_group!(
89178
benches,
90179
benchmark_ipa_commit_vesta,
180+
benchmark_ipa_commit_evals_vesta,
91181
benchmark_ipa_open_vesta
92182
);
93183
criterion_main!(benches);

0 commit comments

Comments
 (0)