Skip to content

Commit

Permalink
chore(rln): refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
seemenkina committed Sep 24, 2024
1 parent 34829cd commit bf249fa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ jobs:
runs-on: ${{ matrix.platform }}
timeout-minutes: 60

name: benchmark - ${{ matrix.platform }} - ${{ matrix.crate }}
name: benchmark - ${{ matrix.platform }} - ${{ matrix.crate }} - ${{ matrix.feature }}
steps:
- name: Checkout sources
uses: actions/checkout@v3
Expand Down
17 changes: 12 additions & 5 deletions rln/benches/circuit_loading_arkzkey_benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use criterion::{criterion_group, criterion_main, Criterion};
use rln::circuit::{arkzkey_from_raw_compressed, arkzkey_from_raw_uncompressed, ARKZKEY_BYTES, ARKZKEY_BYTES_UNCOMPR};
use rln::circuit::{
arkzkey_from_raw_compressed, arkzkey_from_raw_uncompressed, ARKZKEY_BYTES,
ARKZKEY_BYTES_UNCOMPR,
};

pub fn uncompressed_bench(c: &mut Criterion) {
let arkzkey = ARKZKEY_BYTES_UNCOMPR.to_vec();
let size = arkzkey.len() as f32;
println!("Size of uncompressed arkzkey: {:.2?} MB", size / 1024.0 / 1024.0);
println!(
"Size of uncompressed arkzkey: {:.2?} MB",
size / 1024.0 / 1024.0
);

c.bench_function("arkzkey::arkzkey_from_raw_uncompressed", |b| {
b.iter(|| {
Expand All @@ -16,7 +22,10 @@ pub fn uncompressed_bench(c: &mut Criterion) {
pub fn compressed_bench(c: &mut Criterion) {
let arkzkey = ARKZKEY_BYTES.to_vec();
let size = arkzkey.len() as f32;
println!("Size of compressed arkzkey: {:.2?} MB", size / 1024.0 / 1024.0);
println!(
"Size of compressed arkzkey: {:.2?} MB",
size / 1024.0 / 1024.0
);

c.bench_function("arkzkey::arkzkey_from_raw_compressed", |b| {
b.iter(|| {
Expand All @@ -26,11 +35,9 @@ pub fn compressed_bench(c: &mut Criterion) {
});
}


criterion_group! {
name = benches;
config = Criterion::default().measurement_time(std::time::Duration::from_secs(250));
targets = uncompressed_bench, compressed_bench
}
criterion_main!(benches);

10 changes: 6 additions & 4 deletions rln/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ use {ark_circom::read_zkey, std::io::Cursor};
#[cfg(feature = "arkzkey")]
pub const ARKZKEY_BYTES: &[u8] = include_bytes!("../resources/tree_height_20/rln_final.arkzkey");
#[cfg(feature = "arkzkey")]
pub const ARKZKEY_BYTES_UNCOMPR: &[u8] = include_bytes!("../resources/tree_height_20/rln_final_uncompr.arkzkey");
pub const ARKZKEY_BYTES_UNCOMPR: &[u8] =
include_bytes!("../resources/tree_height_20/rln_final_uncompr.arkzkey");

pub const ZKEY_BYTES: &[u8] = include_bytes!("../resources/tree_height_20/rln_final.zkey");
pub const VK_BYTES: &[u8] = include_bytes!("../resources/tree_height_20/verification_key.arkvkey");
Expand Down Expand Up @@ -149,13 +150,13 @@ pub fn check_vk_from_zkey(verifying_key: VerifyingKey<Curve>) -> Result<()> {
}
}


////////////////////////////////////////////////////////
// Function from [arkzkey](https://github.com/zkmopro/ark-zkey/blob/main/src/lib.rs#L106) for benchmark
// without print and using compressed and uncompressed data
////////////////////////////////////////////////////////
#[cfg(feature = "arkzkey")]
pub fn arkzkey_from_raw_uncompressed(arkzkey_data: &[u8],
pub fn arkzkey_from_raw_uncompressed(
arkzkey_data: &[u8],
) -> Result<(ProvingKey<Curve>, ConstraintMatrices<Fr>)> {
if arkzkey_data.is_empty() {
return Err(Report::msg("No proving key found!"));
Expand Down Expand Up @@ -189,7 +190,8 @@ pub fn arkzkey_from_raw_uncompressed(arkzkey_data: &[u8],
}

#[cfg(feature = "arkzkey")]
pub fn arkzkey_from_raw_compressed(arkzkey_data: &[u8],
pub fn arkzkey_from_raw_compressed(
arkzkey_data: &[u8],
) -> Result<(ProvingKey<Curve>, ConstraintMatrices<Fr>)> {
if arkzkey_data.is_empty() {
return Err(Report::msg("No proving key found!"));
Expand Down

0 comments on commit bf249fa

Please sign in to comment.