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

DO NOT MERGE: GLV Implementation #211

Open
wants to merge 50 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
6daad35
wip: migrating GLV to arkworks
missac213 Aug 23, 2022
8453824
Merge branch 'main' into feat/move-glv
bhgomes Aug 23, 2022
7e5579a
Merge branch 'main' into feat/move-glv
bhgomes Aug 23, 2022
2c2d170
Delete glv.rs
missac213 Aug 24, 2022
87929e5
wip: benchmarking glv
missac213 Aug 24, 2022
3af01f5
feat: add glv to arkworks
missac213 Aug 26, 2022
c80103f
chore: fix dependency
Aug 26, 2022
ec67a88
Merge branch 'main' into feat/move-glv
bhgomes Aug 29, 2022
b929ab1
Merge branch 'main' into feat/move-glv
bhgomes Aug 30, 2022
e683342
Merge branch 'main' into feat/move-glv
bhgomes Aug 31, 2022
a655107
Merge branch 'main' into feat/move-glv
bhgomes Sep 6, 2022
05bab1b
sage scripts precompute beta and the short basis for bls and bn
SupremoUGH Sep 7, 2022
adc1c9b
Merge branch 'main' into feat/move-glv
bhgomes Sep 7, 2022
b69430b
local changes before pull
SupremoUGH Sep 8, 2022
146858d
Merge branch 'feat/move-glv' of https://github.com/Manta-Network/mant…
SupremoUGH Sep 8, 2022
50e5462
fmt
SupremoUGH Sep 8, 2022
b261c4d
Merge branch 'main' into feat/move-glv
bhgomes Sep 8, 2022
9863c79
Tests for BLS and BN
SupremoUGH Sep 8, 2022
dd7647e
Merge branch 'feat/move-glv' of https://github.com/Manta-Network/mant…
SupremoUGH Sep 8, 2022
1b462a7
merge with latest commit
SupremoUGH Sep 8, 2022
80ff693
sort
SupremoUGH Sep 8, 2022
e9ddac1
reorganized files
SupremoUGH Sep 8, 2022
749d5c7
Simultaneous multiplication algorithm
SupremoUGH Sep 9, 2022
a13f37c
small correction
SupremoUGH Sep 9, 2022
4a8c1fa
small correction
SupremoUGH Sep 9, 2022
5f50d5e
wip: commit save point
SupremoUGH Sep 9, 2022
c7b337c
HasGLV Trait
SupremoUGH Sep 9, 2022
3aad887
HasGLV trait generates the GLV parameters
SupremoUGH Sep 12, 2022
534120f
Moved precomputed values folder
SupremoUGH Sep 12, 2022
14b1838
Moved precomputed folder
SupremoUGH Sep 12, 2022
5bcabb1
clean-up
SupremoUGH Sep 12, 2022
02a0083
changelog
SupremoUGH Sep 12, 2022
5d4a1fe
switched from Fileread to include
SupremoUGH Sep 12, 2022
74635da
comments addressed
SupremoUGH Sep 12, 2022
e6c546d
some comments addressed
SupremoUGH Sep 19, 2022
698e3e6
all comments addressed
SupremoUGH Sep 19, 2022
8d05967
some comments addressed
SupremoUGH Sep 20, 2022
8c4689f
Comments addressed
SupremoUGH Sep 20, 2022
6831e2a
load parameters from file directly
SupremoUGH Sep 20, 2022
bb26a96
removed unnecessary features
SupremoUGH Sep 20, 2022
0359db2
Merge branch 'main' into feat/move-glv
bhgomes Oct 3, 2022
74dc04c
wip: commit save point
SupremoUGH Oct 20, 2022
93fc201
comments addressed
SupremoUGH Oct 20, 2022
7c4c6da
cargo sort
SupremoUGH Oct 20, 2022
71db28a
clippy
SupremoUGH Oct 21, 2022
7cf7e0e
Merge branch 'main' into feat/move-glv
bhgomes Oct 27, 2022
93f2765
Update CHANGELOG.md
bhgomes Oct 27, 2022
8a17ad8
wip: commit save point
SupremoUGH Dec 5, 2022
c0ac0b0
Merge branch 'main' into feat/move-glv
bhgomes Dec 7, 2022
4de3f7c
Merge branch 'main' into feat/move-glv
bhgomes Jan 10, 2023
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]
### Added
- [\#211](https://github.com/Manta-Network/manta-rs/pull/211) GLV scalar multiplication implementation
- [\#286](https://github.com/Manta-Network/manta-rs/pull/286) MantaPay v1.0.0

### Changed
- [\#293](https://github.com/Manta-Network/manta-rs/pull/293) Add decimals argument to AssetMetadata display
Expand All @@ -30,7 +32,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [0.5.7] - 2022-11-04
### Added
- [\#262](https://github.com/Manta-Network/manta-rs/pull/262) Added exporting seed phrase and multiple networks support for signer.
- [#276](https://github.com/Manta-Network/manta-rs/pull/276) New circuits part 1: manta-crypto abstractions
- [\#276](https://github.com/Manta-Network/manta-rs/pull/276) New circuits part 1: manta-crypto abstractions

### Changed
- [\#274](https://github.com/Manta-Network/manta-rs/pull/274) Update TS client installer script to use release 0.5.6.
Expand Down
1 change: 1 addition & 0 deletions manta-benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ name = "to_public"
harness = false

[dependencies]
criterion = { version = "0.3.4", default-features = false }
SupremoUGH marked this conversation as resolved.
Show resolved Hide resolved
getrandom = { version = "0.2.8", 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"] }
Expand Down
33 changes: 20 additions & 13 deletions manta-benchmark/benches/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@

use core::iter::repeat_with;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use manta_benchmark::ecc;
use manta_benchmark::{ecc, glv::GLVMutiplicationSetup, Benchmark};
use manta_crypto::{
arkworks::bls12_381::{G1Affine, G1Projective},
arkworks::bls12_381::{G1Affine as BLSAffine, G1Projective as BLSProjective},
rand::OsRng,
};

#[inline]
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 mut lhs = black_box(ecc::sample_affine_point::<BLSAffine, _>(&mut rng));
let rhs = black_box(ecc::sample_affine_point(&mut rng));
group.bench_function("affine-affine addition", |b| {
b.iter(|| {
Expand All @@ -41,7 +41,7 @@ fn affine_affine_addition(c: &mut Criterion) {
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 mut lhs = black_box(ecc::sample_projective_point::<BLSProjective, _>(&mut rng));
let rhs = black_box(ecc::sample_affine_point(&mut rng));
group.bench_function("projective-affine addition", |b| {
b.iter(|| {
Expand All @@ -54,8 +54,8 @@ fn projective_affine_addition(c: &mut Criterion) {
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));
let mut lhs = black_box(ecc::sample_projective_point::<BLSProjective, _>(&mut rng));
let rhs = black_box(ecc::sample_projective_point::<BLSProjective, _>(&mut rng));
group.bench_function("projective-projective addition", |b| {
b.iter(|| {
let _ = black_box(ecc::projective_projective_add_assign(&mut lhs, rhs));
Expand All @@ -67,8 +67,8 @@ fn projective_projective_addition(c: &mut Criterion) {
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));
let point = black_box(ecc::sample_affine_point::<BLSAffine, _>(&mut rng));
let scalar = black_box(ecc::sample_scalar::<BLSAffine, _>(&mut rng));
group.bench_function("affine-scalar multiplication", |b| {
b.iter(|| {
let _ = black_box(ecc::affine_scalar_mul(&point, scalar));
Expand All @@ -80,8 +80,8 @@ fn affine_scalar_multiplication(c: &mut Criterion) {
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));
let mut point = black_box(ecc::sample_projective_point::<BLSProjective, _>(&mut rng));
let scalar = black_box(ecc::sample_scalar::<BLSAffine, _>(&mut rng));
group.bench_function("projective-scalar multiplication", |b| {
b.iter(|| {
let _ = black_box(ecc::projective_scalar_mul_assign(&mut point, scalar));
Expand All @@ -93,7 +93,7 @@ fn projective_scalar_multiplication(c: &mut Criterion) {
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));
let point = black_box(ecc::sample_projective_point::<BLSProjective, _>(&mut rng));
group.bench_function("projective to affine normalization", |b| {
b.iter(|| {
let _ = black_box(ecc::projective_to_affine_normalization(&point));
Expand All @@ -105,7 +105,7 @@ fn projective_to_affine_normalization(c: &mut Criterion) {
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))
let points = repeat_with(|| ecc::sample_projective_point::<BLSProjective, _>(&mut rng))
.take(1 << 16)
.collect::<Vec<_>>();
let points_slice = black_box(points.as_slice());
Expand All @@ -122,7 +122,7 @@ fn batch_vector_projective_to_affine_normalization(c: &mut Criterion) {
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))
let points = repeat_with(|| ecc::sample_projective_point::<BLSProjective, _>(&mut rng))
.take(1 << 16)
.collect::<Vec<_>>();
let points_slice = black_box(points.as_slice());
Expand All @@ -135,6 +135,12 @@ fn naive_vector_projective_to_affine_normalization(c: &mut Criterion) {
});
}

#[inline]
fn glv_scalar_multiplication(c: &mut Criterion) {
SupremoUGH marked this conversation as resolved.
Show resolved Hide resolved
black_box(GLVMutiplicationSetup::<BLSAffine, _>::setup(&mut OsRng, ()))
.define_benchmark(&mut c.benchmark_group("bench"));
}

criterion_group!(
ecc,
affine_affine_addition,
Expand All @@ -145,5 +151,6 @@ criterion_group!(
projective_to_affine_normalization,
batch_vector_projective_to_affine_normalization,
naive_vector_projective_to_affine_normalization,
glv_scalar_multiplication,
);
criterion_main!(ecc);
76 changes: 76 additions & 0 deletions manta-benchmark/src/glv.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// 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/>.

//! Benchmark trait

use crate::Benchmark;
use core::marker::PhantomData;
use criterion::black_box;
use manta_crypto::{
arkworks::{
ec::{AffineCurveExt, ProjectiveCurve},
ff::UniformRand,
glv::{GLVParameters, HasGLV},
},
rand::RngCore,
};

/// GLV Multiplication Setup
pub struct GLVMutiplicationSetup<C, M>
where
C: AffineCurveExt + HasGLV<M>,
{
/// GLV Parameters
glv_parameters: GLVParameters<C>,

/// Scalar
scalar: C::ScalarField,

/// Curve Point
point: C,

/// Type Parameter Marker
__: PhantomData<M>,
}

impl<C, M> Benchmark for GLVMutiplicationSetup<C, M>
where
C: AffineCurveExt + HasGLV<M>,
{
const NAME: &'static str = "GLV scalar multiplication";

type Parameters = ();
type Output = C;

#[inline]
fn setup<R>(rng: &mut R, (): Self::Parameters) -> Self
where
R: RngCore + ?Sized,
{
Self {
glv_parameters: C::glv_parameters(),
scalar: C::ScalarField::rand(rng),
point: C::Projective::rand(rng).into_affine(),
__: PhantomData,
}
}

#[inline]
fn benchmark(&self) -> Self::Output {
self.glv_parameters
.scalar_mul(&black_box(self.point), &black_box(self.scalar))
}
}
3 changes: 1 addition & 2 deletions manta-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ serde = [

# Standard Library
std = [
"ark-bls12-381?/std",
"ark-bn254?/std",
"ark-ec?/std",
"ark-ed-on-bls12-381?/std",
"ark-ed-on-bn254?/std",
Expand Down Expand Up @@ -88,6 +86,7 @@ ark-std = { version = "0.3.0", optional = true, default-features = false }
derivative = { version = "2.2.0", default-features = false, features = ["use_core"] }
ed25519-dalek = { version = "1.0.1", optional = true, default-features = false, features = ["u64_backend"] }
manta-util = { path = "../manta-util", default-features = false, features = ["alloc"] }
num-bigint = { version = "0.4.3", optional = true, default-features = false }
num-integer = { version = "0.1.45", optional = true, default-features = false }
rand = { version = "0.8.4", optional = true, default-features = false, features = ["alloc"] }
rand_chacha = { version = "0.3.1", optional = true, default-features = false }
Expand Down
72 changes: 72 additions & 0 deletions manta-crypto/src/arkworks/ec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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/>.

//! Arkworks Elliptic Curves Backend

#[doc(inline)]
pub use ark_ec::*;

/// Affine Curve Extension
pub trait AffineCurveExt: AffineCurve {
/// Returns the `x` coordinate of `self`.
fn x(&self) -> &Self::BaseField;

/// Returns the `y` coordinate of `self`.
fn y(&self) -> &Self::BaseField;

/// Builds [`Self`] from `x` and `y`.
fn from_xy_unchecked(x: Self::BaseField, y: Self::BaseField) -> Self;
}

impl<P> AffineCurveExt for short_weierstrass_jacobian::GroupAffine<P>
where
P: SWModelParameters,
{
#[inline]
fn x(&self) -> &Self::BaseField {
&self.x
}

#[inline]
fn y(&self) -> &Self::BaseField {
&self.y
}

#[inline]
fn from_xy_unchecked(x: Self::BaseField, y: Self::BaseField) -> Self {
Self::new(x, y, false)
}
}

impl<P> AffineCurveExt for twisted_edwards_extended::GroupAffine<P>
where
P: TEModelParameters,
{
#[inline]
fn x(&self) -> &Self::BaseField {
&self.x
}

#[inline]
fn y(&self) -> &Self::BaseField {
&self.y
}

#[inline]
fn from_xy_unchecked(x: Self::BaseField, y: Self::BaseField) -> Self {
Self::new(x, y)
}
}
Loading