From 3a40a82a57332bf990e5f1e0019b828a49ab2986 Mon Sep 17 00:00:00 2001 From: Hanting Zhang Date: Thu, 2 May 2024 09:17:33 +0000 Subject: [PATCH] add ingonyama grumpkin --- Cargo.toml | 2 +- src/provider/bn256_grumpkin.rs | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index deb0f7b34..94064e66c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,7 @@ rayon-scan = "0.1.0" # grumpkin-msm has been patched to support MSMs for the pasta curve cycle # see: https://github.com/lurk-lab/grumpkin-msm/pull/3 grumpkin-msm = { git = "https://github.com/lurk-lab/grumpkin-msm", branch = "dev" } -ingonyama-grumpkin-msm = { git = "https://github.com/lurk-lab/ingonyama-grumpkin-msm", optional = true } +ingonyama-grumpkin-msm = { git = "https://github.com/lurk-lab/ingonyama-grumpkin-msm", branch = "add-grumpkin-curve", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2.0", default-features = false, features = ["js"] } diff --git a/src/provider/bn256_grumpkin.rs b/src/provider/bn256_grumpkin.rs index 77e8d2612..bf586c775 100644 --- a/src/provider/bn256_grumpkin.rs +++ b/src/provider/bn256_grumpkin.rs @@ -7,8 +7,6 @@ use crate::{ use digest::{ExtendableOutput, Update}; use ff::{FromUniformBytes, PrimeField}; use group::{cofactor::CofactorCurveAffine, Curve, Group as AnotherGroup}; -#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] -use grumpkin_msm::grumpkin as grumpkin_msm; // Remove this when https://github.com/zcash/pasta_curves/issues/41 resolves use halo2curves::{bn256::G2Affine, CurveAffine, CurveExt}; use num_bigint::BigInt; @@ -48,6 +46,19 @@ fn bn256_msm(points: &[bn256::Affine], scalars: &[bn256::Scalar]) -> bn256::Poin } } +#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] +fn grumpkin_msm(points: &[grumpkin::Affine], scalars: &[grumpkin::Scalar]) -> grumpkin::Point { + cfg_if::cfg_if! { + if #[cfg(feature = "cuda")] { + let stream = ingonyama_grumpkin_msm::Config::new(); + let cfg = ingonyama_grumpkin_msm::default_config(&stream.stream); + ingonyama_grumpkin_msm::grumpkin_msm(&points, &scalars, &cfg) + } else { + grumpkin_msm::grumpkin(points, scalars) + } + } +} + #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] impl_traits!( bn256,