Skip to content

Commit

Permalink
Commitment implements Mul<F>
Browse files Browse the repository at this point in the history
  • Loading branch information
swasilyev committed Feb 28, 2025
1 parent d411b69 commit 3ca0fdc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
19 changes: 11 additions & 8 deletions src/pcs/id/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use ark_ff::Zero;
use ark_poly::Polynomial;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_std::vec::Vec;
Expand Down Expand Up @@ -28,23 +27,27 @@ impl<F: PrimeField> Sub<Self> for WrappedPolynomial<F> {
type Output = WrappedPolynomial<F>;

fn sub(self, other: WrappedPolynomial<F>) -> Self::Output {
let mut temp = self.0;
temp -= &other.0; //TODO
WrappedPolynomial(temp)
WrappedPolynomial(self.0 - other.0)
}
}

impl<F: PrimeField> core::iter::Sum<Self> for WrappedPolynomial<F> {
impl<F: PrimeField> Sum<Self> for WrappedPolynomial<F> {
fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
iter.reduce(|a, b| a + b).unwrap()
}
}

impl<F: PrimeField> Mul<F> for WrappedPolynomial<F> {
type Output = WrappedPolynomial<F>;

fn mul(self, by: F) -> Self {
(&self).mul(by)
}
}

impl<F: PrimeField> Commitment<F> for WrappedPolynomial<F> {
fn mul(&self, by: F) -> Self {
let mut temp = Poly::zero(); //TODO
temp += (by, &self.0);
WrappedPolynomial(temp)
WrappedPolynomial(&self.0 * by)
}

fn combine(coeffs: &[F], commitments: &[Self]) -> Self {
Expand Down
8 changes: 8 additions & 0 deletions src/pcs/kzg/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ use crate::utils::ec::small_multiexp_affine;
#[derive(Clone, Debug, PartialEq, Eq, CanonicalSerialize, CanonicalDeserialize)]
pub struct KzgCommitment<E: Pairing>(pub E::G1Affine);

impl<E: Pairing> Mul<E::ScalarField> for KzgCommitment<E> {
type Output = Self;

fn mul(self, by: E::ScalarField) -> Self {
(&self).mul(by)
}
}

impl<E: Pairing> Commitment<E::ScalarField> for KzgCommitment<E> {
fn mul(&self, by: E::ScalarField) -> KzgCommitment<E> {
KzgCommitment(self.0.mul(by).into())
Expand Down
3 changes: 2 additions & 1 deletion src/pcs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ark_poly::Evaluations;
use ark_serialize::*;
use ark_std::fmt::Debug;
use ark_std::iter::Sum;
use ark_std::ops::{Add, Sub};
use ark_std::ops::{Add, Mul, Sub};
use ark_std::rand::Rng;
use ark_std::vec::Vec;

Expand All @@ -20,6 +20,7 @@ pub trait Commitment<F: PrimeField>:
+ Clone
+ Debug
+ Add<Self, Output = Self>
+ Mul<F, Output=Self>
+ Sub<Self, Output = Self>
+ Sum<Self>
+ CanonicalSerialize
Expand Down

0 comments on commit 3ca0fdc

Please sign in to comment.