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 the default implementation of msm #528

Merged
merged 24 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
18 changes: 18 additions & 0 deletions ec/src/models/short_weierstrass/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,24 @@ impl<P: SWCurveConfig> ScalarMul for Projective<P> {
}
}

#[cfg(feature = "specialization")]
pub trait CustomMSM: SWCurveConfig {
fn msm_bigint(
bases: &[Affine<Self>],
bigints: &[<Self::ScalarField as PrimeField>::BigInt],
) -> Projective<Self>;
}
achimcc marked this conversation as resolved.
Show resolved Hide resolved

#[cfg(feature = "specialization")]
impl<P: SWCurveConfig> VariableBaseMSM for Projective<P> where P: CustomMSM {
fn msm_bigint(
bases: &[Self::MulBase],
bigints: &[<Self::ScalarField as PrimeField>::BigInt],
) -> Self {
P::msm_bigint(bases, bigints)
}
}

impl<P: SWCurveConfig> VariableBaseMSM for Projective<P> {}

impl<P: SWCurveConfig, T: Borrow<Affine<P>>> core::iter::Sum<T> for Projective<P> {
Expand Down
4 changes: 2 additions & 2 deletions ec/src/models/short_weierstrass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use ark_serialize::{
};
use ark_std::io::{Read, Write};

use ark_ff::fields::Field;
use ark_ff::{fields::Field, PrimeField};

use crate::{AffineRepr, Group};
use crate::{scalar_mul::variable_base::VariableBaseMSM, AffineRepr, Group};

use num_traits::Zero;

Expand Down
1 change: 1 addition & 0 deletions test-templates/src/msm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use ark_ec::{
ScalarMul,
};
use ark_ff::{PrimeField, UniformRand};
use ark_std::vec::Vec;

fn naive_var_base_msm<G: ScalarMul>(bases: &[G::MulBase], scalars: &[G::ScalarField]) -> G {
let mut acc = G::zero();
Expand Down