Skip to content

Commit

Permalink
Feature: Orion PCS Prototype (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfloatersu authored Nov 21, 2024
1 parent 4867d69 commit a6117bf
Show file tree
Hide file tree
Showing 12 changed files with 1,142 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: python3 ./scripts/install.py
- name: Set RUSTFLAGS for AVX
if: matrix.feature != ''
run: echo "RUSTFLAGS=$RUSTFLAGS -C target-feature=+${{ matrix.feature }}" >> $GITHUB_ENV
run: echo "RUSTFLAGS=$RUSTFLAGS -C target-feature=+${{ matrix.feature }}" >> $GITHUB_ENV
- name: Prepare binary
run: cargo build --release --bin expander-exec
- name: Upload release asset
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ members = [
]
resolver = "2"


[workspace.dependencies]
ark-std = "0.4"
ark-bn254 = "0.4.0"
Expand Down
15 changes: 15 additions & 0 deletions poly_commit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,20 @@ gkr_field_config = { path = "../config/gkr_field_config" }
mpi_config = { path = "../config/mpi_config" }
polynomials = { path = "../arith/polynomials"}
transcript = { path = "../transcript" }
tree = { path = "../tree" }

rand.workspace = true
ark-std.workspace = true
thiserror.workspace = true

[dev-dependencies]
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
114 changes: 114 additions & 0 deletions poly_commit/benches/orion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
use std::{hint::black_box, ops::Mul};

use arith::{Field, FieldSerde, SimdField};
use ark_std::test_rng;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use gf2::{GF2x128, GF2x8, GF2};
use gf2_128::GF2_128;
use poly_commit::{OrionPublicParams, ORION_CODE_PARAMETER_INSTANCE};
use polynomials::MultiLinearPoly;
use transcript::{BytesHashTranscript, Keccak256hasher, Transcript};
use tynm::type_name;

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

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 =
OrionPublicParams::from_random::<F>(num_vars, ORION_CODE_PARAMETER_INSTANCE, &mut rng);

group
.bench_function(
BenchmarkId::new(format!("{num_vars} variables"), num_vars),
|b| b.iter(|| _ = black_box(orion_pp.commit::<F, ComPackF>(&random_poly).unwrap())),
)
.sample_size(10);
}
}

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

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

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 =
OrionPublicParams::from_random::<F>(num_vars, ORION_CODE_PARAMETER_INSTANCE, &mut rng);

let commitment_with_data = orion_pp.commit::<F, ComPackF>(&random_poly).unwrap();

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

fn orion_opening_benchmark(c: &mut Criterion) {
opening_benchmark_helper::<GF2, GF2_128, GF2x128, GF2x8, BytesHashTranscript<_, Keccak256hasher>>(
c, 19, 30,
);
}

criterion_group!(bench, orion_committing_benchmark, orion_opening_benchmark);
criterion_main!(bench);
5 changes: 5 additions & 0 deletions poly_commit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ pub fn expander_pcs_init_testing_only<
)
}

pub const PCS_SOUNDNESS_BITS: usize = 128;

mod utils;
use transcript::Transcript;
use utils::PCSEmptyType;

pub mod raw;

pub mod orion;
pub use self::orion::*;
11 changes: 11 additions & 0 deletions poly_commit/src/orion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mod utils;
pub use utils::{OrionPCSError, OrionResult, SubsetSumLUTs};

mod linear_code;
pub use linear_code::{OrionCodeParameter, ORION_CODE_PARAMETER_INSTANCE};

mod pcs_impl;
pub use pcs_impl::{OrionCommitment, OrionCommitmentWithData, OrionProof, OrionPublicParams};

#[cfg(test)]
mod tests;
Loading

0 comments on commit a6117bf

Please sign in to comment.