pub trait ScalarMul:
PrimeGroup
+ Add<Self::MulBase, Output = Self>
+ AddAssign<Self::MulBase>
+ for<'a> Add<&'a Self::MulBase, Output = Self>
+ for<'a> AddAssign<&'a Self::MulBase>
+ Sub<Self::MulBase, Output = Self>
+ SubAssign<Self::MulBase>
+ for<'a> Sub<&'a Self::MulBase, Output = Self>
+ for<'a> SubAssign<&'a Self::MulBase>
+ From<Self::MulBase> {
type MulBase: Send + Sync + Copy + Eq + Hash + Mul<Self::ScalarField, Output = Self> + for<'a> Mul<&'a Self::ScalarField, Output = Self> + 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§
const NEGATION_IS_CHEAP: bool
Required Associated Types§
type MulBase: Send + Sync + Copy + Eq + Hash + Mul<Self::ScalarField, Output = Self> + for<'a> Mul<&'a Self::ScalarField, Output = Self> + Neg<Output = Self::MulBase> + From<Self>
Required Methods§
fn batch_convert_to_mul_base(bases: &[Self]) -> Vec<Self::MulBase>
Provided Methods§
Sourcefn batch_mul(self, v: &[Self::ScalarField]) -> Vec<Self::MulBase>
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);
Sourcefn batch_mul_with_preprocessing(
table: &BatchMulPreprocessing<Self>,
v: &[Self::ScalarField],
) -> Vec<Self::MulBase>
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.