Skip to content

Commit

Permalink
rewrite with generic msm fail on G's type
Browse files Browse the repository at this point in the history
  • Loading branch information
PatStiles committed Mar 8, 2024
1 parent add4616 commit cedb7e4
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 288 deletions.
17 changes: 6 additions & 11 deletions crypto/src/commitments/kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use lambdaworks_math::{
cyclic_group::IsGroup,
elliptic_curve::traits::IsPairing,
errors::DeserializationError,
field::{element::FieldElement, traits::IsPrimeField},
field::{element::FieldElement, traits::{IsPrimeField, IsField}},
msm::pippenger::msm,
polynomial::Polynomial,
traits::{AsBytes, Deserializable},
Expand Down Expand Up @@ -136,12 +136,12 @@ where
}

#[derive(Clone)]
pub struct KateZaveruchaGoldberg<F: IsPrimeField, P: IsPairing> {
pub struct KateZaveruchaGoldberg<F: IsField, P: IsPairing> {
srs: StructuredReferenceString<P::G1Point, P::G2Point>,
phantom: PhantomData<F>,
}

impl<F: IsPrimeField, P: IsPairing> KateZaveruchaGoldberg<F, P> {
impl<F: IsField, P: IsPairing> KateZaveruchaGoldberg<F, P> {
pub fn new(srs: StructuredReferenceString<P::G1Point, P::G2Point>) -> Self {
Self {
srs,
Expand All @@ -150,20 +150,15 @@ impl<F: IsPrimeField, P: IsPairing> KateZaveruchaGoldberg<F, P> {
}
}

impl<const N: usize, F: IsPrimeField<RepresentativeType = UnsignedInteger<N>>, P: IsPairing>
impl<const N: usize, F: IsField<BaseType = UnsignedInteger<N>> + IsPrimeField<RepresentativeType = UnsignedInteger<N>>, P: IsPairing>
IsCommitmentScheme<F> for KateZaveruchaGoldberg<F, P>
{
type Commitment = P::G1Point;

fn commit(&self, p: &Polynomial<FieldElement<F>>) -> Self::Commitment {
let coefficients: Vec<_> = p
.coefficients
.iter()
.map(|coefficient| coefficient.representative())
.collect();
msm(
&coefficients,
&self.srs.powers_main_group[..coefficients.len()],
&p.coefficients,
&self.srs.powers_main_group[..p.coefficients.len()],
)
.expect("`points` is sliced by `cs`'s length")
}
Expand Down
251 changes: 0 additions & 251 deletions math/src/gpu/icicle.rs

This file was deleted.

6 changes: 1 addition & 5 deletions math/src/gpu/icicle/bls12_381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ mod test {
let lambda_scalars = vec![eight; LEN];
let lambda_points = (0..LEN).map(|_| point_times_5()).collect::<Vec<_>>();
let expected = msm(
&lambda_scalars
.clone()
.into_iter()
.map(|x| x.representative())
.collect::<Vec<_>>(),
&lambda_scalars,
&lambda_points,
)
.unwrap();
Expand Down
Loading

0 comments on commit cedb7e4

Please sign in to comment.