ark_test_curves::scalar_mul

Trait ScalarMul

Source
pub trait ScalarMul:
    PrimeGroup<Output = Self, Output = Self, Output = Self, Output = Self>
    + Add<Self::MulBase>
    + AddAssign<Self::MulBase>
    + for<'a> Add<&'a Self::MulBase>
    + for<'a> AddAssign<&'a Self::MulBase>
    + Sub<Self::MulBase>
    + SubAssign<Self::MulBase>
    + for<'a> Sub<&'a Self::MulBase>
    + for<'a> SubAssign<&'a Self::MulBase>
    + From<Self::MulBase> {
    type MulBase: Send + Sync + Copy + Eq + Hash + Mul<Self::ScalarField, Output = Self, Output = Self> + for<'a> Mul<&'a Self::ScalarField> + Neg<Output = Self::MulBase> + From<Self>;

    const NEGATION_IS_CHEAP: bool;

    // Required method
    fn batch_convert_to_mul_base(bases: &[Self]) -> Vec<Self::MulBase>;

    // Provided methods
    fn batch_mul(self, v: &[Self::ScalarField]) -> Vec<Self::MulBase> { ... }
    fn batch_mul_with_preprocessing(
        table: &BatchMulPreprocessing<Self>,
        v: &[Self::ScalarField],
    ) -> Vec<Self::MulBase> { ... }
}

Required Associated Constants§

Required Associated Types§

Source

type MulBase: Send + Sync + Copy + Eq + Hash + Mul<Self::ScalarField, Output = Self, Output = Self> + for<'a> Mul<&'a Self::ScalarField> + Neg<Output = Self::MulBase> + From<Self>

Required Methods§

Source

fn batch_convert_to_mul_base(bases: &[Self]) -> Vec<Self::MulBase>

Provided Methods§

Source

fn batch_mul(self, v: &[Self::ScalarField]) -> Vec<Self::MulBase>

Compute the vector v[0].G, v[1].G, …, v[n-1].G, given:

  • an element g
  • a list v of n scalars
§Example
use ark_std::{One, UniformRand};
use ark_ec::pairing::Pairing;
use ark_test_curves::bls12_381::G1Projective as G;
use ark_test_curves::bls12_381::Fr;
use ark_ec::scalar_mul::ScalarMul;

// Compute G, s.G, s^2.G, ..., s^9.G
let mut rng = ark_std::test_rng();
let max_degree = 10;
let s = Fr::rand(&mut rng);
let g = G::rand(&mut rng);
let mut powers_of_s = vec![Fr::one()];
let mut cur = s;
for _ in 0..max_degree {
    powers_of_s.push(cur);
    cur *= &s;
}
let powers_of_g = g.batch_mul(&powers_of_s);
let naive_powers_of_g: Vec<G> = powers_of_s.iter().map(|e| g * e).collect();
assert_eq!(powers_of_g, naive_powers_of_g);
Source

fn batch_mul_with_preprocessing( table: &BatchMulPreprocessing<Self>, v: &[Self::ScalarField], ) -> Vec<Self::MulBase>

Compute the vector v[0].G, v[1].G, …, v[n-1].G, given:

  • an element g
  • a list v of n scalars

This method allows the user to provide a precomputed table of multiples of g. A more ergonomic way to call this would be to use BatchMulPreprocessing::batch_mul.

§Example
use ark_std::{One, UniformRand};
use ark_ec::pairing::Pairing;
use ark_test_curves::bls12_381::G1Projective as G;
use ark_test_curves::bls12_381::Fr;
use ark_ec::scalar_mul::*;

// Compute G, s.G, s^2.G, ..., s^9.G
let mut rng = ark_std::test_rng();
let max_degree = 10;
let s = Fr::rand(&mut rng);
let g = G::rand(&mut rng);
let mut powers_of_s = vec![Fr::one()];
let mut cur = s;
for _ in 0..max_degree {
    powers_of_s.push(cur);
    cur *= &s;
}
let table = BatchMulPreprocessing::new(g, powers_of_s.len());
let powers_of_g = G::batch_mul_with_preprocessing(&table, &powers_of_s);
let powers_of_g_2 = table.batch_mul(&powers_of_s);
let naive_powers_of_g: Vec<G> = powers_of_s.iter().map(|e| g * e).collect();
assert_eq!(powers_of_g, naive_powers_of_g);
assert_eq!(powers_of_g_2, naive_powers_of_g);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<P> ScalarMul for ark_test_curves::models::short_weierstrass::Projective<P>
where P: SWCurveConfig,

Source§

impl<P> ScalarMul for ark_test_curves::models::twisted_edwards::Projective<P>
where P: TECurveConfig,

Source§

impl<P> ScalarMul for PairingOutput<P>
where P: Pairing,

Source§

const NEGATION_IS_CHEAP: bool = <P::TargetField>::INVERSE_IS_FAST

Source§

type MulBase = PairingOutput<P>