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

Allow to overwrite default impl of msm in TwistedEdwards form #567

Merged
merged 3 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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