Skip to content

Commit

Permalink
Merge pull request #2629 from o1-labs/dw/move-inner-prod-field-helpers
Browse files Browse the repository at this point in the history
Poly_commitment/utils: move inner_prod into field_helpers
  • Loading branch information
dannywillems authored Sep 26, 2024
2 parents 43c73b0 + af03d19 commit 347899a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
8 changes: 0 additions & 8 deletions poly-commitment/src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,6 @@ pub fn combine_evaluations<G: CommitmentCurve>(
acc
}

pub fn inner_prod<F: Field>(xs: &[F], ys: &[F]) -> F {
let mut res = F::zero();
for (&x, y) in xs.iter().zip(ys) {
res += &(x * y);
}
res
}

#[cfg(feature = "ocaml_types")]
pub mod caml {
// polynomial commitment
Expand Down
10 changes: 6 additions & 4 deletions poly-commitment/src/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

use crate::{
commitment::{
b_poly, b_poly_coefficients, combine_commitments, inner_prod, shift_scalar,
squeeze_prechallenge, BatchEvaluationProof, BlindedCommitment, CommitmentCurve, EndoCurve,
Evaluation,
b_poly, b_poly_coefficients, combine_commitments, shift_scalar, squeeze_prechallenge,
BatchEvaluationProof, BlindedCommitment, CommitmentCurve, EndoCurve, Evaluation,
},
error::CommitmentError,
evaluation_proof::{combine_polys, Challenges, OpeningProof},
Expand All @@ -20,7 +19,10 @@ use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use blake2::{Blake2b512, Digest};
use groupmap::GroupMap;
use mina_poseidon::{sponge::ScalarChallenge, FqSponge};
use o1_utils::{field_helpers::pows, math, ExtendedDensePolynomial};
use o1_utils::{
field_helpers::{inner_prod, pows},
math, ExtendedDensePolynomial,
};
use rand::{CryptoRng, RngCore};
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
Expand Down
9 changes: 9 additions & 0 deletions utils/src/field_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,12 @@ pub fn product<F: Field>(xs: impl Iterator<Item = F>) -> F {
}
res
}

/// COmpute the inner product of two slices of field elements.
pub fn inner_prod<F: Field>(xs: &[F], ys: &[F]) -> F {
let mut res = F::zero();
for (&x, y) in xs.iter().zip(ys) {
res += &(x * y);
}
res
}

0 comments on commit 347899a

Please sign in to comment.