-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: added opening & verifying benches * feat: configured sample size 10 for reducing time of benchmark * feat: added manual trigger for starting benchmark * feat: added benchmark workflow on GH action * fix: bench on rangechipU64 * fix: bench name and removed un-necessary benchmark task * fix: following review comments
- Loading branch information
Showing
5 changed files
with
284 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Benchmark | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
run_benchmark: | ||
description: 'Run benchmark tests (yes/no)' | ||
required: true | ||
default: 'no' | ||
|
||
jobs: | ||
wakeup: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.run_benchmark == 'yes' }} | ||
permissions: | ||
id-token: write | ||
contents: read | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Configure AWS Credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: arn:aws:iam::490752553772:role/summa-solvency-ec2-slc | ||
role-duration-seconds: 900 | ||
aws-region: us-west-2 | ||
|
||
- name: Wakeup runner | ||
run: .github/scripts/wakeup.sh | ||
|
||
benchmark: | ||
runs-on: [summa-solvency-runner] | ||
needs: [wakeup] | ||
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.run_benchmark == 'yes' }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Run Benchmark Tests | ||
run: | | ||
cd kzg_prover | ||
cargo bench | ||
- name: Upload Benchmark Results | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: benchmark-results | ||
path: kzg_prover/target/criterion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
username,balance_ETH_ETH,balance_USDT_ETH | ||
dxGaEAii,11888,41163 | ||
MBlfbBGI,67823,18651 | ||
lAhWlEWZ,18651,2087 | ||
nuZweYtO,22073,55683 | ||
gbdSwiuY,34897,83296 | ||
RZNneNuP,83296,16881 | ||
YsscHXkp,31699,35479 | ||
RkLzkDun,2087,79731 | ||
HlQlnEYI,30605,11888 | ||
RqkZOFYe,16881,14874 | ||
NjCSRAfD,41163,67823 | ||
pHniJMQY,14874,22073 | ||
dOGIMzKR,10032,10032 | ||
HfMDmNLp,55683,34897 | ||
xPLKzCBl,79731,30605 | ||
AtwIxZHo,35479,31699 | ||
aaGaEAaa,11888,41163 | ||
bblfbBGI,67823,18651 | ||
cchWlEWZ,18651,2087 | ||
ddZweYtO,22073,55683 | ||
eedSwiuY,34897,83296 | ||
ffNneNuP,83296,16881 | ||
ggscHXkp,31699,35479 | ||
hhLzkDun,2087,79731 | ||
iiQlnEYI,30605,11888 | ||
llkZOFYe,16881,14874 | ||
mmCSRAfD,41163,67823 | ||
nnniJMQY,14874,22073 | ||
ooGIMzKR,10032,10032 | ||
ppMDmNLp,55683,34897 | ||
qqLKzCBl,79731,30605 | ||
rrwIxZHo,35479,31699 | ||
a1GaEAaa,11888,41163 | ||
b2lfbBGI,67823,18651 | ||
c3hWlEWZ,18651,2087 | ||
d4ZweYtO,22073,55683 | ||
e5dSwiuY,34897,83296 | ||
f6NneNuP,83296,16881 | ||
g7scHXkp,31699,35479 | ||
h8LzkDun,2087,79731 | ||
i9QlnEYI,30605,11888 | ||
l0kZOFYe,16881,14874 | ||
m1CSRAfD,41163,67823 | ||
n2niJMQY,14874,22073 | ||
o3GIMzKR,10032,10032 | ||
p4MDmNLp,55683,34897 | ||
q5LKzCBl,79731,30605 | ||
r6wIxZHo,35479,31699 | ||
a17aEAaa,11888,41163 | ||
b28fbBGI,67823,18651 | ||
c39WlEWZ,18651,2087 | ||
d40weYtO,22073,55683 | ||
e51SwiuY,34897,83296 | ||
f62neNuP,83296,16881 | ||
g73cHXkp,31699,35479 | ||
h84zkDun,2087,79731 | ||
i95lnEYI,30605,11888 | ||
l06ZOFYe,16881,14874 | ||
m17SRAfD,41163,67823 | ||
n28iJMQY,14874,22073 | ||
o39IMzKR,10032,10032 | ||
p40DmNLp,55683,34897 | ||
q51KzCBl,79731,30605 | ||
r62IxZHo,35479,31699 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
#![feature(generic_const_exprs)] | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use rand::{rngs::OsRng, Rng}; | ||
|
||
use summa_solvency::{ | ||
circuits::{ | ||
univariate_grand_sum::UnivariateGrandSum, | ||
utils::{ | ||
full_prover, generate_setup_artifacts, open_grand_sums, open_user_points, | ||
verify_grand_sum_openings, verify_user_inclusion, | ||
}, | ||
}, | ||
cryptocurrency::Cryptocurrency, | ||
entry::Entry, | ||
utils::parse_csv_to_entries, | ||
}; | ||
|
||
fn bench_kzg<const K: u32, const N_USERS: usize, const N_CURRENCIES: usize, const N_POINTS: usize>( | ||
name: &str, | ||
csv_path: &str, | ||
) where | ||
[(); N_CURRENCIES + 1]:, | ||
{ | ||
let mut c = Criterion::default().sample_size(10); | ||
|
||
// Initialize an empty circuit | ||
let circuit = UnivariateGrandSum::<N_USERS, N_CURRENCIES>::init_empty(); | ||
let (params, pk, vk) = generate_setup_artifacts(K, None, circuit.clone()).unwrap(); | ||
|
||
let range_check_bench_name = format!("<{}> range check", name); | ||
let opening_grand_sum_bench_name = format!("<{}> opening grand sum", name); | ||
let opening_user_bench_name = format!("<{}> opening user inclusion", name); | ||
let verifying_grand_sum_bench_name = format!("<{}> verifying grand sum", name); | ||
let verifying_user_bench_name = format!("<{}> verifying user inclusion", name); | ||
|
||
let mut entries: Vec<Entry<N_CURRENCIES>> = vec![Entry::init_empty(); N_USERS]; | ||
let mut cryptos = vec![Cryptocurrency::init_empty(); N_CURRENCIES]; | ||
let _ = | ||
parse_csv_to_entries::<&str, N_CURRENCIES>(csv_path, &mut entries, &mut cryptos).unwrap(); | ||
|
||
c.bench_function(&range_check_bench_name, |b| { | ||
b.iter_batched( | ||
|| circuit.clone(), // Setup function: clone the circuit for each iteration | ||
|circuit| { | ||
full_prover(¶ms, &pk, circuit, vec![vec![]]); | ||
}, | ||
criterion::BatchSize::SmallInput, // Choose an appropriate batch size | ||
); | ||
}); | ||
|
||
let (zk_snark_proof, advice_polys, omega) = full_prover(¶ms, &pk, circuit, vec![vec![]]); | ||
|
||
c.bench_function(&opening_grand_sum_bench_name, |b| { | ||
b.iter_batched( | ||
|| 1..N_CURRENCIES + 1, | ||
|balance_column_range| { | ||
open_grand_sums::<N_CURRENCIES>( | ||
&advice_polys.advice_polys, | ||
&advice_polys.advice_blinds, | ||
¶ms, | ||
balance_column_range, | ||
) | ||
}, | ||
criterion::BatchSize::SmallInput, | ||
); | ||
}); | ||
|
||
// Generate a random user index | ||
let get_random_user_index = || { | ||
let user_range: std::ops::Range<usize> = 0..N_USERS; | ||
OsRng.gen_range(user_range) as u16 | ||
}; | ||
|
||
c.bench_function(&opening_user_bench_name, |b| { | ||
b.iter_batched( | ||
|| (get_random_user_index(), 0..N_CURRENCIES + 1), | ||
|(user_index, column_range)| { | ||
open_user_points::<N_CURRENCIES>( | ||
&advice_polys.advice_polys, | ||
&advice_polys.advice_blinds, | ||
¶ms, | ||
column_range, | ||
omega, | ||
user_index, | ||
) | ||
}, | ||
criterion::BatchSize::SmallInput, | ||
); | ||
}); | ||
|
||
// Open grand sum for benchmark verifying grand sum | ||
let balance_column_range = 1..N_CURRENCIES + 1; | ||
let grand_sums_batch_proof = open_grand_sums::<N_CURRENCIES>( | ||
&advice_polys.advice_polys, | ||
&advice_polys.advice_blinds, | ||
¶ms, | ||
balance_column_range.clone(), | ||
); | ||
|
||
c.bench_function(&verifying_grand_sum_bench_name, |b| { | ||
b.iter_batched( | ||
|| { | ||
( | ||
grand_sums_batch_proof.clone(), | ||
u64::try_from(advice_polys.advice_polys[0].len()).unwrap(), | ||
balance_column_range.clone(), | ||
) | ||
}, | ||
|(grand_sums_batch_proof, poly_degree, balance_column_range)| { | ||
verify_grand_sum_openings::<N_CURRENCIES>( | ||
¶ms, | ||
&zk_snark_proof, | ||
grand_sums_batch_proof, | ||
poly_degree, | ||
balance_column_range, | ||
) | ||
}, | ||
criterion::BatchSize::SmallInput, | ||
); | ||
}); | ||
|
||
// Open user inclusion for benchmark verifying user inclusion | ||
let column_range = 0..N_CURRENCIES + 1; | ||
let omega = vk.get_domain().get_omega(); | ||
let user_index = get_random_user_index(); | ||
let openings_batch_proof = open_user_points::<N_CURRENCIES>( | ||
&advice_polys.advice_polys, | ||
&advice_polys.advice_blinds, | ||
¶ms, | ||
column_range.clone(), | ||
omega.clone(), | ||
user_index.clone(), | ||
); | ||
|
||
c.bench_function(&verifying_user_bench_name, |b| { | ||
b.iter_batched( | ||
|| (column_range.clone(), omega.clone(), user_index.clone()), | ||
|(column_range, omega, user_index)| { | ||
verify_user_inclusion::<N_POINTS>( | ||
¶ms, | ||
&zk_snark_proof, | ||
&openings_batch_proof, | ||
column_range, | ||
omega, | ||
user_index, | ||
); | ||
}, | ||
criterion::BatchSize::SmallInput, | ||
); | ||
}); | ||
} | ||
|
||
fn criterion_benchmark(_c: &mut Criterion) { | ||
bench_kzg::<17, 16, 2, 3>( | ||
"K = 17, N_USER = 16, N_CURRENCIES = 2", | ||
"../csv/entry_16.csv", | ||
); | ||
bench_kzg::<17, 64, 2, 3>( | ||
"K = 17, N_USER = 64, N_CURRENCIES = 2", | ||
"../csv/entry_64.csv", | ||
); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters