diff --git a/CHANGELOG.md b/CHANGELOG.md index 7904a03f6..08d1b511e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -196,6 +196,7 @@ - [\#357](https://github.com/arkworks-rs/algebra/pull/357) (`ark-poly`) Speedup division by vanishing polynomials for dense polynomials. - [\#445](https://github.com/arkworks-rs/algebra/pull/445) (`ark-ec`) Use 2-NAF for ate pairing in MNT4/6 curves. - [\#509](https://github.com/arkworks-rs/algebra/pull/509) (`ark-ff`, `ark-ff-macros`) Support prime fields with (64 * k)-bit modulus. +- [\#567](https://github.com/arkworks-rs/algebra/pull/567) (`ark-ec`) Allow to overwrite the default implementation of the `msm` function for TwistedEdwards form provided by the `VariableBaseMSM` trait by a specialized version in `TECurveConfig`. ### Bugfixes diff --git a/ec/src/models/twisted_edwards/group.rs b/ec/src/models/twisted_edwards/group.rs index e69728714..d82d70a2e 100644 --- a/ec/src/models/twisted_edwards/group.rs +++ b/ec/src/models/twisted_edwards/group.rs @@ -488,4 +488,8 @@ impl ScalarMul for Projective

{ } } -impl VariableBaseMSM for Projective

{} +impl VariableBaseMSM for Projective

{ + fn msm(bases: &[Self::MulBase], bigints: &[Self::ScalarField]) -> Result { + P::msm(bases, bigints) + } +} diff --git a/ec/src/models/twisted_edwards/mod.rs b/ec/src/models/twisted_edwards/mod.rs index 315951b2a..7bda50f83 100644 --- a/ec/src/models/twisted_edwards/mod.rs +++ b/ec/src/models/twisted_edwards/mod.rs @@ -4,7 +4,7 @@ use ark_serialize::{ }; use ark_std::io::{Read, Write}; -use crate::{AffineRepr, Group}; +use crate::{scalar_mul::variable_base::VariableBaseMSM, AffineRepr, Group}; use num_traits::Zero; use ark_ff::fields::Field; @@ -85,6 +85,16 @@ pub trait TECurveConfig: super::CurveConfig { res } + /// Default implementation for multi scalar multiplication + fn msm( + bases: &[Affine], + scalars: &[Self::ScalarField], + ) -> Result, usize> { + (bases.len() == scalars.len()) + .then(|| VariableBaseMSM::msm_unchecked(bases, scalars)) + .ok_or(usize::min(bases.len(), scalars.len())) + } + /// If uncompressed, serializes both x and y coordinates. /// If compressed, serializes y coordinate with a bit to encode whether x is positive. #[inline]