Skip to content

Commit

Permalink
one benchmarking for orion over GF2 evaluated over GF2ext128
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfloatersu committed Nov 12, 2024
1 parent 22d3f11 commit 18e7aa7
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pcs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ thiserror.workspace = true
gf2 = { path = "../arith/gf2" }
gf2_128 = { path = "../arith/gf2_128" }
mersenne31 = { path = "../arith/mersenne31" }

tynm.workspace = true
criterion.workspace = true

[[bench]]
name = "orion"
harness = false
128 changes: 128 additions & 0 deletions pcs/benches/orion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
use std::{hint::black_box, ops::Mul, time::Duration};

use arith::{Field, FieldSerde, SimdField};
use ark_std::test_rng;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use gf2::{GF2x128, GF2x64, GF2};
use gf2_128::GF2_128;
use pcs::{OrionPCS, OrionPCSSetup, PolynomialCommitmentScheme, ORION_CODE_PARAMETER_INSTANCE};
use polynomials::MultiLinearPoly;
use transcript::{BytesHashTranscript, Keccak256hasher, Transcript};
use tynm::type_name;

fn committing_benchmark_helper<F, PackF, EvalF, T>(
c: &mut Criterion,
lowest_num_vars: usize,
highest_num_vars: usize,
) where
F: Field + FieldSerde,
PackF: SimdField<Scalar = F>,
EvalF: Field + FieldSerde + From<F> + Mul<F, Output = EvalF>,
T: Transcript<EvalF>,
{
let mut group = c.benchmark_group(format!(
"Orion PCS committing benchmarking: F = {}, PackF = {}",
type_name::<F>(),
type_name::<PackF>(),
));

let mut rng = test_rng();

for num_vars in lowest_num_vars..=highest_num_vars {
let random_poly = MultiLinearPoly::<F>::random(num_vars, &mut rng);

let orion_pp = OrionPCS::<F, PackF, EvalF, T>::gen_srs_for_testing(
&mut rng,
&OrionPCSSetup {
num_vars,
code_parameter: ORION_CODE_PARAMETER_INSTANCE,
},
);

group
.bench_function(
BenchmarkId::new(format!("{num_vars} variables"), num_vars),
|b| {
b.iter(|| {
_ = black_box(OrionPCS::<F, PackF, EvalF, T>::commit(
&orion_pp,
&random_poly,
))
})
},
)
.sample_size(10)
.measurement_time(Duration::from_secs(30));
}
}

fn orion_committing_benchmark(c: &mut Criterion) {
committing_benchmark_helper::<GF2, GF2x128, GF2_128, BytesHashTranscript<_, Keccak256hasher>>(
c, 19, 25,
)
}

fn opening_benchmark_helper<F, PackF, EvalF, T>(
c: &mut Criterion,
lowest_num_vars: usize,
highest_num_vars: usize,
) where
F: Field + FieldSerde,
PackF: SimdField<Scalar = F>,
EvalF: Field + FieldSerde + From<F> + Mul<F, Output = EvalF>,
T: Transcript<EvalF>,
{
let mut group = c.benchmark_group(format!(
"Orion PCS opening benchmarking: F = {}, EvalF = {}, PackF = {}",
type_name::<F>(),
type_name::<EvalF>(),
type_name::<PackF>(),
));

let mut rng = test_rng();
let mut transcript = T::new();

for num_vars in lowest_num_vars..=highest_num_vars {
let random_poly = MultiLinearPoly::<F>::random(num_vars, &mut rng);
let random_point: Vec<_> = (0..num_vars)
.map(|_| EvalF::random_unsafe(&mut rng))
.collect();

let orion_pp = OrionPCS::<F, PackF, EvalF, T>::gen_srs_for_testing(
&mut rng,
&OrionPCSSetup {
num_vars,
code_parameter: ORION_CODE_PARAMETER_INSTANCE,
},
);

let commitment_with_data = OrionPCS::<F, PackF, EvalF, T>::commit(&orion_pp, &random_poly);

group
.bench_function(
BenchmarkId::new(format!("{num_vars} variables"), num_vars),
|b| {
b.iter(|| {
_ = black_box(OrionPCS::<F, PackF, EvalF, T>::open(
&orion_pp,
&random_poly,
&random_point,
&commitment_with_data,
&mut transcript,
))
})
},
)
.sample_size(10)
.measurement_time(Duration::from_secs(30));
}
}

fn orion_opening_benchmark(c: &mut Criterion) {
opening_benchmark_helper::<GF2, GF2x64, GF2_128, BytesHashTranscript<_, Keccak256hasher>>(
c, 19, 25,
)
}

criterion_group!(bench, orion_committing_benchmark, orion_opening_benchmark);
criterion_main!(bench);
4 changes: 2 additions & 2 deletions pcs/src/orion_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ where
.collect(),
);
let random_point: Vec<_> = (0..num_vars)
.map(|_| EvalF::random_bool(&mut rng))
.map(|_| EvalF::random_unsafe(&mut rng))
.collect();

let mut transcript: BytesHashTranscript<EvalF, Keccak256hasher> = BytesHashTranscript::new();
Expand Down Expand Up @@ -289,7 +289,7 @@ where
.collect(),
);
let random_point: Vec<_> = (0..num_vars)
.map(|_| EvalF::random_bool(&mut rng))
.map(|_| EvalF::random_unsafe(&mut rng))
.collect();
let expected_eval = random_poly_ext.evaluate_jolt(&random_point);

Expand Down

0 comments on commit 18e7aa7

Please sign in to comment.