From 8d7d02c4bb4558b2dbb62a36d00147736d0bc6ed Mon Sep 17 00:00:00 2001 From: viktorking7 <140458814+viktorking7@users.noreply.github.com> Date: Wed, 24 Sep 2025 16:44:21 +0200 Subject: [PATCH] Update kzg.rs --- crates/crypto/src/commitments/kzg.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/crypto/src/commitments/kzg.rs b/crates/crypto/src/commitments/kzg.rs index ea3ee6721..759e021ea 100644 --- a/crates/crypto/src/commitments/kzg.rs +++ b/crates/crypto/src/commitments/kzg.rs @@ -166,11 +166,22 @@ impl>, 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>) -> 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()],