Skip to content

Commit

Permalink
conditional compilation with specialization feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Achim Schneider committed Nov 30, 2022
1 parent d996417 commit c394b07
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 12 additions & 1 deletion ec/src/models/short_weierstrass/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,16 @@ impl<P: SWCurveConfig> ScalarMul for Projective<P> {
}
}

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

#[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],
Expand All @@ -643,6 +652,8 @@ impl<P: SWCurveConfig> VariableBaseMSM for Projective<P> {
}
}

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

impl<P: SWCurveConfig, T: Borrow<Affine<P>>> core::iter::Sum<T> for Projective<P> {
fn sum<I: Iterator<Item = T>>(iter: I) -> Self {
iter.fold(Projective::zero(), |sum, x| sum + x.borrow())
Expand Down
8 changes: 0 additions & 8 deletions ec/src/models/short_weierstrass/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ pub trait SWCurveConfig: super::CurveConfig {
res
}

/// Default implementation for multi scalar multiplication
fn msm_bigint(
bases: &[Affine<Self>],
bigints: &[<Self::ScalarField as PrimeField>::BigInt],
) -> Projective<Self> {
VariableBaseMSM::msm_bigint(bases, bigints)
}

/// If uncompressed, serializes both x and y coordinates as well as a bit for whether it is
/// infinity. If compressed, serializes x coordinate with two bits to encode whether y is
/// positive, negative, or infinity.
Expand Down

0 comments on commit c394b07

Please sign in to comment.