Skip to content

Commit

Permalink
Allow to overwrite default impl of msm in TwistedEdwards form (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
Achim Schneider authored Dec 29, 2022
1 parent 32201cb commit 1021d10
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion ec/src/models/twisted_edwards/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,8 @@ impl<P: TECurveConfig> ScalarMul for Projective<P> {
}
}

impl<P: TECurveConfig> VariableBaseMSM for Projective<P> {}
impl<P: TECurveConfig> VariableBaseMSM for Projective<P> {
fn msm(bases: &[Self::MulBase], bigints: &[Self::ScalarField]) -> Result<Self, usize> {
P::msm(bases, bigints)
}
}
12 changes: 11 additions & 1 deletion ec/src/models/twisted_edwards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,6 +85,16 @@ pub trait TECurveConfig: super::CurveConfig {
res
}

/// Default implementation for multi scalar multiplication
fn msm(
bases: &[Affine<Self>],
scalars: &[Self::ScalarField],
) -> Result<Projective<Self>, 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]
Expand Down

0 comments on commit 1021d10

Please sign in to comment.