Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/crypto/src/commitments/kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,22 @@ impl<const N: usize, F: IsPrimeField<RepresentativeType = UnsignedInteger<N>>, P
/// The commitment is p(s) g1, evaluated as \sum_i c_i srs.powers_main_group[i], where c_i are the coefficients
/// of the polynomial.
fn commit(&self, p: &Polynomial<FieldElement<F>>) -> Self::Commitment {
// Guard against SRS underprovisioning: if the polynomial degree exceeds the
// available SRS powers, limit MSM inputs to the SRS size to avoid out-of-bounds
// slicing. Callers should ensure the SRS has at least as many powers as the
// number of polynomial coefficients.
let coeffs_to_use = p
.coefficients
.len()
.min(self.srs.powers_main_group.len());

let coefficients: Vec<_> = p
.coefficients
.iter()
.take(coeffs_to_use)
.map(|coefficient| coefficient.representative())
.collect();

msm(
&coefficients,
&self.srs.powers_main_group[..coefficients.len()],
Expand Down