diff --git a/nomos-da/kzgrs/benches/rs.rs b/nomos-da/kzgrs/benches/rs.rs index 3ed0ff81..36cefd24 100644 --- a/nomos-da/kzgrs/benches/rs.rs +++ b/nomos-da/kzgrs/benches/rs.rs @@ -28,7 +28,7 @@ fn rs_encode(bencher: Bencher, size: usize) { }) } -#[divan::bench(args = [3224], sample_size = 10, sample_count = 100)] +#[divan::bench(args = [16399, 32798, 65565, 131099, 262167, 524241, 1048606], sample_size = 10, sample_count = 100)] fn rs_decode(bencher: Bencher, size: usize) { bencher .with_inputs(move || { diff --git a/nomos-da/kzgrs/src/common.rs b/nomos-da/kzgrs/src/common.rs index 4ebf4d38..e3bc209d 100644 --- a/nomos-da/kzgrs/src/common.rs +++ b/nomos-da/kzgrs/src/common.rs @@ -58,6 +58,8 @@ pub enum KzgRsError { PolyCommitError(#[from] ark_poly_commit::Error), #[error("BLST error: {0}")] BlstError(BlstError), + #[error("Denominator polynomial cannot be zero")] + DivisionByZeroPolynomial, } /// Transform chunks of bytes (of size `CHUNK_SIZE`) into `Fr` which are considered evaluations of a diff --git a/nomos-da/kzgrs/src/kzg.rs b/nomos-da/kzgrs/src/kzg.rs index 0dc73aa8..2f9bf825 100644 --- a/nomos-da/kzgrs/src/kzg.rs +++ b/nomos-da/kzgrs/src/kzg.rs @@ -5,7 +5,7 @@ use ark_ec::pairing::Pairing; use ark_poly::univariate::DensePolynomial; use ark_poly::{DenseUVPolynomial, EvaluationDomain, GeneralEvaluationDomain}; use ark_poly_commit::kzg10::{Commitment, Powers, Proof, UniversalParams, KZG10}; -use num_traits::One; +use num_traits::{One, Zero}; use std::borrow::Cow; use std::ops::{Mul, Neg}; @@ -33,6 +33,10 @@ pub fn generate_element_proof( domain: GeneralEvaluationDomain, ) -> Result, KzgRsError> { let u = domain.element(element_index); + if u.is_zero() { + return Err(KzgRsError::DivisionByZeroPolynomial); + }; + // Instead of evaluating over the polynomial, we can reuse the evaluation points from the rs encoding // let v = polynomial.evaluate(&u); let v = evaluations.evals[element_index];