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: add ec benchmark #147

Merged
merged 17 commits into from
Jul 6, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Added
- [\#144](https://github.com/Manta-Network/manta-rs/pull/144) Add new release PR template for future releases
- [\#145](https://github.com/Manta-Network/manta-rs/pull/145) Add `cargo-hakari` and `cargo-nextest` to speed up CI pipeline
- [\#147](https://github.com/Manta-Network/manta-rs/pull/147) Add benchmarks for Arkworks elliptic curve operations

### Changed
- [\#152](https://github.com/Manta-Network/manta-rs/pull/152) Make `format` and `docs` as prerequisites for the rest of the CI pipeline
Expand Down
10 changes: 1 addition & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
[workspace]
resolver = "2"
members = [
"manta-accounting",
"manta-benchmark",
"manta-crypto",
"manta-parameters",
"manta-pay",
"manta-util",
"manta-workspace-hack",
]
members = ["manta-*"]
2 changes: 1 addition & 1 deletion manta-accounting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ futures = { version = "0.3.21", optional = true, default-features = false, featu
indexmap = { version = "1.8.0", optional = true, default-features = false }
manta-crypto = { path = "../manta-crypto", default-features = false }
manta-util = { path = "../manta-util", default-features = false, features = ["alloc"] }
manta-workspace-hack = { version = "0.1.0", path = "../manta-workspace-hack" }
parking_lot = { version = "0.12.0", optional = true, default-features = false }
rand_chacha = { version = "0.3.1", optional = true, default-features = false }
statrs = { version = "0.15.0", optional = true, default-features = false }
manta-workspace-hack = { version = "0.1.0", path = "../manta-workspace-hack" }

[dev-dependencies]
manta-crypto = { path = "../manta-crypto", default-features = false, features = ["getrandom"] }
13 changes: 10 additions & 3 deletions manta-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ maintenance = { status = "actively-developed" }
[lib]
crate-type = ["cdylib", "lib"]

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

[[bench]]
name = "mint"
harness = false
Expand All @@ -40,15 +44,18 @@ name = "reclaim"
harness = false

[dependencies]
getrandom = { version = "0.2.6", features = ["js"] }
instant = { version = "0.1.12", features = [ "wasm-bindgen" ] }
ark-bls12-381 = { version = "0.3.0", default-features = false }
ark-ec = { version = "0.3.0", default-features = false }
ark-ff = { version = "0.3.0", default-features = false }
getrandom = { version = "0.2.6", default-features = false, features = ["js"] }
instant = { version = "0.1.12", default-features = false, features = [ "wasm-bindgen" ] }
manta-accounting = { path = "../manta-accounting", default-features = false, features = ["test"] }
manta-crypto = { path = "../manta-crypto", default-features = false, features = ["getrandom", "test"] }
manta-pay = { path = "../manta-pay", default-features = false, features = ["groth16", "test"] }
manta-workspace-hack = { version = "0.1.0", path = "../manta-workspace-hack" }
wasm-bindgen = { version = "0.2.81", default-features = false }
wasm-bindgen-test = { version = "0.3.30", default-features = false }
web-sys = { version = "0.3.58", default-features = false, features = ["console"] }
manta-workspace-hack = { version = "0.1.0", path = "../manta-workspace-hack" }

[dev-dependencies]
criterion = { version = "0.3.4", default-features = false }
139 changes: 139 additions & 0 deletions manta-benchmark/benches/ecc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// 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/>.

//! Elliptic Curve Cryptography Benchmarks

use ark_bls12_381::{G1Affine, G1Projective};
use core::iter::repeat_with;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use manta_benchmark::ecc;
use manta_crypto::rand::OsRng;

fn affine_affine_addition(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let mut rng = OsRng;
let mut lhs = black_box(ecc::sample_affine_point::<G1Affine, _>(&mut rng));
let rhs = black_box(ecc::sample_affine_point(&mut rng));
group.bench_function("affine-affine addition", |b| {
b.iter(|| {
let _ = black_box(ecc::affine_affine_add_assign(&mut lhs, &rhs));
})
});
}

fn projective_affine_addition(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let mut rng = OsRng;
let mut lhs = black_box(ecc::sample_projective_point::<G1Projective, _>(&mut rng));
let rhs = black_box(ecc::sample_affine_point(&mut rng));
group.bench_function("projective-affine addition", |b| {
b.iter(|| {
let _ = black_box(ecc::projective_affine_add_assign(&mut lhs, &rhs));
})
});
}

fn projective_projective_addition(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let mut rng = OsRng;
let mut lhs = black_box(ecc::sample_projective_point::<G1Projective, _>(&mut rng));
let rhs = black_box(ecc::sample_projective_point::<G1Projective, _>(&mut rng));
group.bench_function("projective-projective addition", |b| {
b.iter(|| {
let _ = black_box(ecc::projective_projective_add_assign(&mut lhs, rhs));
})
});
}

fn affine_scalar_multiplication(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let mut rng = OsRng;
let point = black_box(ecc::sample_affine_point::<G1Affine, _>(&mut rng));
let scalar = black_box(ecc::sample_scalar::<G1Affine, _>(&mut rng));
group.bench_function("affine-scalar multiplication", |b| {
b.iter(|| {
let _ = black_box(ecc::affine_scalar_mul(&point, scalar));
})
});
}

fn projective_scalar_multiplication(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let mut rng = OsRng;
let mut point = black_box(ecc::sample_projective_point::<G1Projective, _>(&mut rng));
let scalar = black_box(ecc::sample_scalar::<G1Affine, _>(&mut rng));
group.bench_function("projective-scalar multiplication", |b| {
b.iter(|| {
let _ = black_box(ecc::projective_scalar_mul_assign(&mut point, scalar));
})
});
}

fn projective_to_affine_normalization(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let mut rng = OsRng;
let point = black_box(ecc::sample_projective_point::<G1Projective, _>(&mut rng));
group.bench_function("projective to affine normalization", |b| {
b.iter(|| {
let _ = black_box(ecc::projective_to_affine_normalization(&point));
})
});
}

fn batch_vector_projective_to_affine_normalization(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let mut rng = OsRng;
let points = repeat_with(|| ecc::sample_projective_point::<G1Projective, _>(&mut rng))
.take(1 << 16)
.collect::<Vec<_>>();
let points_slice = black_box(points.as_slice());
group.bench_function("batch vector of projective to affine normalization", |b| {
b.iter(|| {
let _ = black_box(ecc::batch_vector_projective_to_affine_normalization(
points_slice,
));
})
});
}

fn naive_vector_projective_to_affine_normalization(c: &mut Criterion) {
let mut group = c.benchmark_group("bench");
let mut rng = OsRng;
let points = repeat_with(|| ecc::sample_projective_point::<G1Projective, _>(&mut rng))
.take(1 << 16)
.collect::<Vec<_>>();
let points_slice = black_box(points.as_slice());
group.bench_function("naive vector of projective to affine normalization", |b| {
b.iter(|| {
let _ = black_box(ecc::naive_vector_projective_to_affine_normalization(
points_slice,
));
})
});
}

criterion_group!(
ecc,
affine_affine_addition,
projective_affine_addition,
projective_projective_addition,
affine_scalar_multiplication,
projective_scalar_multiplication,
projective_to_affine_normalization,
batch_vector_projective_to_affine_normalization,
naive_vector_projective_to_affine_normalization,
);
criterion_main!(ecc);
2 changes: 2 additions & 0 deletions manta-benchmark/benches/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with manta-rs. If not, see <http://www.gnu.org/licenses/>.

//! Mint Benchmarks

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use manta_accounting::transfer::test::assert_valid_proof;
use manta_crypto::rand::{OsRng, Rand};
Expand Down
2 changes: 2 additions & 0 deletions manta-benchmark/benches/private_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with manta-rs. If not, see <http://www.gnu.org/licenses/>.

//! Private Transfer Benchmarks

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use manta_accounting::transfer::test::assert_valid_proof;
use manta_crypto::rand::OsRng;
Expand Down
2 changes: 2 additions & 0 deletions manta-benchmark/benches/reclaim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with manta-rs. If not, see <http://www.gnu.org/licenses/>.

//! Reclaim Benchmarks

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use manta_accounting::transfer::test::assert_valid_proof;
use manta_crypto::rand::OsRng;
Expand Down
Loading