-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add proving and verifying benchmark * fix: remove let bindings for clippy false positives Co-authored-by: Brandon H. Gomes <bhgomes@pm.me>
- Loading branch information
Boyuan Feng
authored
May 12, 2022
1 parent
21b6fd2
commit 57e3de1
Showing
19 changed files
with
504 additions
and
57 deletions.
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
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,40 @@ | ||
[package] | ||
name = 'manta-benchmark' | ||
version = '0.4.0' | ||
edition = "2021" | ||
authors = ["Manta Network <contact@manta.network>"] | ||
readme = 'README.md' | ||
license-file = "LICENSE" | ||
repository = "https://github.com/Manta-Network/manta-rs" | ||
homepage = "https://github.com/Manta-Network" | ||
documentation = "https://github.com/Manta-Network/manta-rs" | ||
categories = [""] | ||
keywords = [""] | ||
description = "Benchmark for Manta." | ||
publish = false | ||
|
||
[package.metadata.docs.rs] | ||
# To build locally: | ||
# RUSTDOCFLAGS="--cfg doc_cfg" cargo +nightly doc --all-features --open | ||
all-features = true | ||
rustdoc-args = ["--cfg", "doc_cfg"] | ||
|
||
[[bench]] | ||
name = "mint" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "private_transfer" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "reclaim" | ||
harness = false | ||
|
||
[dependencies] | ||
manta-accounting = { path = "../manta-accounting", default-features = false, features = ["test"] } | ||
manta-crypto = { path = "../manta-crypto", default-features = false, features = ["test"] } | ||
manta-pay = { path = "../manta-pay", default-features = false, features = ["groth16", "test"] } | ||
|
||
[dev-dependencies] | ||
criterion = { version = "0.3.4", default-features = false } |
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 @@ | ||
../LICENSE |
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 @@ | ||
# manta-benchmark |
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,61 @@ | ||
// Copyright 2019-2022 Manta Network. | ||
// This file is part of manta-rs. | ||
// | ||
// manta-rs is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// manta-rs is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with manta-rs. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use manta_benchmark::payment; | ||
use manta_crypto::rand::{OsRng, Rand}; | ||
use manta_pay::parameters::{generate_parameters, SEED}; | ||
|
||
pub fn prove(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("bench"); | ||
let (proving_context, _verifying_context, parameters, utxo_accumulator_model) = | ||
generate_parameters(SEED).unwrap(); | ||
let mut rng = OsRng; | ||
group.bench_function("mint prove", |b| { | ||
let asset = black_box(rng.gen()); | ||
b.iter(|| { | ||
payment::prove_mint( | ||
&proving_context.mint, | ||
¶meters, | ||
&utxo_accumulator_model, | ||
asset, | ||
&mut rng, | ||
); | ||
}) | ||
}); | ||
} | ||
|
||
pub fn verify(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("bench"); | ||
let (proving_context, verifying_context, parameters, utxo_accumulator_model) = | ||
generate_parameters(SEED).unwrap(); | ||
let mut rng = OsRng; | ||
let mint = black_box(payment::prove_mint( | ||
&proving_context.mint, | ||
¶meters, | ||
&utxo_accumulator_model, | ||
rng.gen(), | ||
&mut rng, | ||
)); | ||
group.bench_function("mint verify", |b| { | ||
b.iter(|| { | ||
payment::assert_valid_proof(&verifying_context.mint, &mint); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(mint, prove, verify); | ||
criterion_main!(mint); |
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,58 @@ | ||
// Copyright 2019-2022 Manta Network. | ||
// This file is part of manta-rs. | ||
// | ||
// manta-rs is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// manta-rs is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with manta-rs. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use manta_benchmark::payment::{self, assert_valid_proof}; | ||
use manta_crypto::rand::OsRng; | ||
use manta_pay::parameters::{generate_parameters, SEED}; | ||
|
||
fn prove(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("bench"); | ||
let mut rng = OsRng; | ||
let (proving_context, _, parameters, utxo_accumulator_model) = | ||
generate_parameters(SEED).unwrap(); | ||
group.bench_function("private transfer prove", |b| { | ||
b.iter(|| { | ||
let _ = payment::prove_private_transfer( | ||
&proving_context, | ||
¶meters, | ||
&utxo_accumulator_model, | ||
&mut rng, | ||
); | ||
}) | ||
}); | ||
} | ||
|
||
fn verify(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("bench"); | ||
let mut rng = OsRng; | ||
let (proving_context, verifying_context, parameters, utxo_accumulator_model) = | ||
generate_parameters(SEED).unwrap(); | ||
let private_transfer = black_box(payment::prove_private_transfer( | ||
&proving_context, | ||
¶meters, | ||
&utxo_accumulator_model, | ||
&mut rng, | ||
)); | ||
group.bench_function("private transfer verify", |b| { | ||
b.iter(|| { | ||
assert_valid_proof(&verifying_context.private_transfer, &private_transfer); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(private_transfer, prove, verify); | ||
criterion_main!(private_transfer); |
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,58 @@ | ||
// Copyright 2019-2022 Manta Network. | ||
// This file is part of manta-rs. | ||
// | ||
// manta-rs is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// manta-rs is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with manta-rs. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use manta_benchmark::payment::{self, assert_valid_proof}; | ||
use manta_crypto::rand::OsRng; | ||
use manta_pay::parameters::{generate_parameters, SEED}; | ||
|
||
fn prove(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("bench"); | ||
let mut rng = OsRng; | ||
let (proving_context, _, parameters, utxo_accumulator_model) = | ||
generate_parameters(SEED).unwrap(); | ||
group.bench_function("reclaim prove", |b| { | ||
b.iter(|| { | ||
let _ = payment::prove_reclaim( | ||
&proving_context, | ||
¶meters, | ||
&utxo_accumulator_model, | ||
&mut rng, | ||
); | ||
}) | ||
}); | ||
} | ||
|
||
fn verify(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("bench"); | ||
let mut rng = OsRng; | ||
let (proving_context, verifying_context, parameters, utxo_accumulator_model) = | ||
generate_parameters(SEED).unwrap(); | ||
let reclaim = black_box(payment::prove_reclaim( | ||
&proving_context, | ||
¶meters, | ||
&utxo_accumulator_model, | ||
&mut rng, | ||
)); | ||
group.bench_function("reclaim verify", |b| { | ||
b.iter(|| { | ||
assert_valid_proof(&verifying_context.reclaim, &reclaim); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(reclaim, prove, verify); | ||
criterion_main!(reclaim); |
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,17 @@ | ||
// Copyright 2019-2022 Manta Network. | ||
// This file is part of manta-rs. | ||
// | ||
// manta-rs is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// manta-rs is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with manta-rs. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
pub mod payment; |
Oops, something went wrong.