From 3ca1d9531b688c00055af897973522fee8e8f86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex?= Date: Mon, 9 Dec 2024 14:55:46 +0100 Subject: [PATCH 1/2] Update benchmark parameters for rs-decode. (#930) --- nomos-da/kzgrs/benches/rs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 || { From 8c3c4c1bfba6bc19563375d387a6904de1c96836 Mon Sep 17 00:00:00 2001 From: Roman Zajic Date: Mon, 9 Dec 2024 22:27:15 +0800 Subject: [PATCH 2/2] fix: Apply Nomos library code review recommendations (#898) * fix: zero polynomial check * fix: formatting * fix: check for division by zero polynomial earlier in the process * fix: introduce hiding bound and random generator * fix: clippy happy * fix: add randomness to generate_element_proof * fix: clippy happy * fix: include random_v in proof validation * fix: add domain size check for production mode * fix: formatting * fix: skip IDING_BOUND check for tests * fix: exclude HIDING_BOUND in commit params for tests * test: add randomness to batch generate proofs * fix: cleanup - check for minimal domain size - check for hiding bound - randomness added --- nomos-da/kzgrs/src/common.rs | 2 ++ nomos-da/kzgrs/src/kzg.rs | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) 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];