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 6 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 @@ -5,5 +5,6 @@ members = [
"manta-crypto",
"manta-pay",
"manta-util",
"manta-benchmark",
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved
]

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
42 changes: 42 additions & 0 deletions manta-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[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"]

[dependencies]
anyhow = { version = "1.0.55", default-features = false }
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"] }
rand_chacha = { version = "0.3.1", default-features = false }
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
criterion = { version = "0.3.4", default-features = false }

[[bench]]
name = "bench_mint"
harness = false

[[bench]]
name = "bench_private_transfer"
harness = false

[[bench]]
name = "bench_reclaim"
harness = false
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved
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
99 changes: 99 additions & 0 deletions manta-benchmark/benches/bench_mint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// 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_accounting::asset::AssetId;
use manta_benchmark::{parameters, payment};
use manta_crypto::rand::OsRng;

pub fn bench_mint_prove(c: &mut Criterion) {
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved
let mut group = c.benchmark_group("bench mint prove");
let (proving_context, _verifying_context, parameters, utxo_accumulator_model) =
parameters::get_parameters().unwrap();
let mut rng = OsRng;

group.bench_function("bench mint proof generation", |b| {
let asset_id: u32 = 8;
let asset = AssetId(asset_id).value(100_000);
let asset = black_box(asset);

b.iter(|| {
payment::bench_mint_prove(
&proving_context.mint,
&parameters,
&utxo_accumulator_model,
asset,
&mut rng,
);
})
});
}

pub fn bench_mint_verify(c: &mut Criterion) {
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved
let mut group = c.benchmark_group("bench mint verify");
let (proving_context, verifying_context, parameters, utxo_accumulator_model) =
parameters::get_parameters().unwrap();
let mut rng = OsRng;

let asset_id: u32 = 8;
let asset = AssetId(asset_id).value(100_000);

let mint = payment::bench_mint_prove(
&proving_context.mint,
&parameters,
&utxo_accumulator_model,
asset,
&mut rng,
);
let mint = black_box(mint);

group.bench_function("bench mint verify", |b| {
b.iter(|| {
payment::assert_valid_proof(&verifying_context.mint, &mint);
})
});
}

pub fn bench_mint_prove_and_verify(c: &mut Criterion) {
let mut group = c.benchmark_group("bench mint prove and verify");

let (proving_context, verifying_context, parameters, utxo_accumulator_model) =
parameters::get_parameters().unwrap();
let mut rng = OsRng;

group.bench_function("bench mint prove and verify", |b| {
let asset_id: u32 = 8;
let asset = AssetId(asset_id).value(100_000);
let asset = black_box(asset);

b.iter(|| {
payment::bench_mint_prove_and_verify(
&proving_context.mint,
&verifying_context.mint,
&parameters,
&utxo_accumulator_model,
asset.clone(),
&mut rng,
);
})
});
}
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved

// Note: May use the following two lines to benchmark prove and verify separately.
// criterion_group!(benches, bench_mint_prove);
// criterion_group!(benches, bench_mint_verify);
criterion_group!(benches, bench_mint_prove_and_verify);
criterion_main!(benches);
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved
58 changes: 58 additions & 0 deletions manta-benchmark/benches/bench_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_accounting::asset::AssetId;
use manta_benchmark::{parameters, payment};
use manta_crypto::rand::OsRng;

fn bench_private_transfer(c: &mut Criterion) {
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved
let mut group = c.benchmark_group("bench private transfer");

let mut rng = OsRng;
let (proving_context, verifying_context, parameters, utxo_accumulator_model) =
parameters::get_parameters().unwrap();

let asset_id: u32 = 8;
let asset_0 = AssetId(asset_id).value(10_000);
let asset_1 = AssetId(asset_id).value(20_000);
let asset_0 = black_box(asset_0);
let asset_1 = black_box(asset_1);
let assets = vec![asset_0, asset_1];

let input = (
proving_context,
verifying_context,
parameters,
utxo_accumulator_model,
assets,
);
group.bench_function("bench private transfer", |b| {
b.iter(|| {
payment::bench_private_transfer_wrapper(
&input.0,
&input.1,
&input.2,
&input.3,
input.4.clone(),
&mut rng,
)
})
});
}

criterion_group!(benches, bench_private_transfer);
criterion_main!(benches);
51 changes: 51 additions & 0 deletions manta-benchmark/benches/bench_reclaim.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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_accounting::asset::AssetId;
use manta_benchmark::{parameters, payment};
use manta_crypto::rand::OsRng;

fn bench_reclaim(c: &mut Criterion) {
BoyuanFeng marked this conversation as resolved.
Show resolved Hide resolved
let mut group = c.benchmark_group("bench reclaim");

let mut rng = OsRng;
let (proving_context, verifying_context, parameters, utxo_accumulator_model) =
parameters::get_parameters().unwrap();

group.bench_function("bench reclaim", |b| {
let asset_id: u32 = 8;
let asset_0 = AssetId(asset_id).value(10_000);
let asset_1 = AssetId(asset_id).value(20_000);
let asset_0 = black_box(asset_0);
let asset_1 = black_box(asset_1);
let assets = vec![asset_0, asset_1];

b.iter(|| {
payment::bench_reclaim_wrapper(
&proving_context,
&verifying_context,
&parameters,
&utxo_accumulator_model,
assets.clone(),
&mut rng,
)
})
});
}

criterion_group!(benches, bench_reclaim);
criterion_main!(benches);
18 changes: 18 additions & 0 deletions manta-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 parameters;
pub mod payment;
Loading