From e25f267621b2dbd387ee6b2165d8cbec960fcb75 Mon Sep 17 00:00:00 2001 From: seemenkina Date: Fri, 13 Sep 2024 18:41:40 +0700 Subject: [PATCH] chore(rln): refactor --- .github/workflows/ci.yml | 2 +- .../circuit_loading_arkzkey_benchmark.rs | 17 ++++++++++++----- rln/src/circuit.rs | 10 ++++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e43d0f..270137d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -142,7 +142,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 diff --git a/rln/benches/circuit_loading_arkzkey_benchmark.rs b/rln/benches/circuit_loading_arkzkey_benchmark.rs index 4e15759..89985f8 100644 --- a/rln/benches/circuit_loading_arkzkey_benchmark.rs +++ b/rln/benches/circuit_loading_arkzkey_benchmark.rs @@ -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(|| { @@ -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(|| { @@ -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); - diff --git a/rln/src/circuit.rs b/rln/src/circuit.rs index 62702e6..d187049 100644 --- a/rln/src/circuit.rs +++ b/rln/src/circuit.rs @@ -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"); @@ -149,13 +150,13 @@ pub fn check_vk_from_zkey(verifying_key: VerifyingKey) -> 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, ConstraintMatrices)> { if arkzkey_data.is_empty() { return Err(Report::msg("No proving key found!")); @@ -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, ConstraintMatrices)> { if arkzkey_data.is_empty() { return Err(Report::msg("No proving key found!"));