From 8308c29f948f7a44bb145485920a28bc2cd6755b Mon Sep 17 00:00:00 2001 From: Srinath Setty Date: Thu, 26 May 2022 17:27:19 +0530 Subject: [PATCH] use pasta_msm crate for MSM (#75) * use pasta_msm crate for MSM * add repr-c to pasta_curves * add +stable * update pasta-msm version --- .github/workflows/rust.yml | 2 +- Cargo.toml | 3 ++- src/pasta.rs | 17 +++-------------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9c2fc63..95e2e3f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -20,7 +20,7 @@ jobs: - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --release --verbose + run: cargo +stable test --release --verbose - name: Check Rustfmt Code Style run: cargo fmt --all -- --check - name: Check clippy warnings diff --git a/Cargo.toml b/Cargo.toml index d872494..f0db640 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,8 @@ rand_core = { version = "0.5", default-features = false } rand_chacha = "0.3" itertools = "0.9.0" subtle = "2.4" -pasta_curves = "0.3.1" +pasta_curves = { version = "^0.3.1", features = ["repr-c"] } +pasta-msm = "0.1.1" neptune = { version = "6.1", default-features = false } generic-array = "0.14.4" bellperson-nonnative = { version = "0.3.0", default-features = false, features = ["wasm"] } diff --git a/src/pasta.rs b/src/pasta.rs index e68b980..e4474ff 100644 --- a/src/pasta.rs +++ b/src/pasta.rs @@ -3,7 +3,6 @@ use crate::{ poseidon::PoseidonRO, traits::{ChallengeTrait, CompressedGroup, Group}, }; -use core::ops::Mul; use digest::{ExtendableOutput, Input}; use ff::Field; use merlin::Transcript; @@ -11,7 +10,7 @@ use num_bigint::BigInt; use num_traits::Num; use pasta_curves::{ self, - arithmetic::{CurveAffine, CurveExt, Group as Grp}, + arithmetic::{CurveAffine, CurveExt}, group::{Curve, GroupEncoding}, pallas, vesta, Ep, Eq, }; @@ -46,12 +45,7 @@ impl Group for pallas::Point { scalars: &[Self::Scalar], bases: &[Self::PreprocessedGroupElement], ) -> Self { - // Unoptimized. - scalars - .iter() - .zip(bases) - .map(|(scalar, base)| base.mul(scalar)) - .fold(Ep::group_zero(), |acc, x| acc + x) + pasta_msm::pallas(bases, scalars) } fn compress(&self) -> Self::CompressedGroupElement { @@ -136,12 +130,7 @@ impl Group for vesta::Point { scalars: &[Self::Scalar], bases: &[Self::PreprocessedGroupElement], ) -> Self { - // Unoptimized. - scalars - .iter() - .zip(bases) - .map(|(scalar, base)| base.mul(scalar)) - .fold(Eq::group_zero(), |acc, x| acc + x) + pasta_msm::vesta(bases, scalars) } fn compress(&self) -> Self::CompressedGroupElement {