Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/benchmark #63

Merged
merged 10 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resolver = "2"
members = [
"manta-accounting",
"manta-benchmark",
"manta-crypto",
"manta-pay",
"manta-util",
Expand Down
3 changes: 1 addition & 2 deletions manta-accounting/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,10 @@ impl<I, V> From<Asset<I, V>> for (I, V) {

impl Sample for Asset {
#[inline]
fn sample<R>(distribution: (), rng: &mut R) -> Self
fn sample<R>(_: (), rng: &mut R) -> Self
where
R: CryptoRng + RngCore + ?Sized,
{
let _ = distribution;
Self::new(rng.gen(), rng.gen())
}
}
Expand Down
40 changes: 40 additions & 0 deletions manta-benchmark/Cargo.toml
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 }
1 change: 1 addition & 0 deletions manta-benchmark/LICENSE
1 change: 1 addition & 0 deletions manta-benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# manta-benchmark
61 changes: 61 additions & 0 deletions manta-benchmark/benches/mint.rs
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,
&parameters,
&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,
&parameters,
&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);
58 changes: 58 additions & 0 deletions manta-benchmark/benches/private_transfer.rs
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,
&parameters,
&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,
&parameters,
&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);
58 changes: 58 additions & 0 deletions manta-benchmark/benches/reclaim.rs
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,
&parameters,
&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,
&parameters,
&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);
17 changes: 17 additions & 0 deletions manta-benchmark/src/lib.rs
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;
Loading