From ddbec179b88df3a9468d2be014c8ea6579e4361c Mon Sep 17 00:00:00 2001 From: Gus Gutoski Date: Tue, 26 Sep 2023 12:40:55 -0400 Subject: [PATCH 1/3] add failing test --- primitives/tests/advz.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/primitives/tests/advz.rs b/primitives/tests/advz.rs index 6e9dca012..8c2d4b1ab 100644 --- a/primitives/tests/advz.rs +++ b/primitives/tests/advz.rs @@ -13,7 +13,7 @@ mod vid; fn round_trip() { // play with these items let vid_sizes = [(2, 3), (5, 9)]; - let byte_lens = [2, 16, 32, 47, 48, 49, 64, 100, 400]; + let byte_lens = [0, 1, 2, 16, 32, 47, 48, 49, 64, 100, 400]; // more items as a function of the above let supported_degree = vid_sizes.iter().max_by_key(|v| v.0).unwrap().0; From 492c96d22178a01d603512af0b9fec3421dced1f Mon Sep 17 00:00:00 2001 From: Gus Gutoski Date: Tue, 26 Sep 2023 13:36:58 -0400 Subject: [PATCH 2/3] allow zero-length payload --- primitives/src/pcs/univariate_kzg/mod.rs | 6 ++++-- primitives/src/vid/advz.rs | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/primitives/src/pcs/univariate_kzg/mod.rs b/primitives/src/pcs/univariate_kzg/mod.rs index fbb822305..3a0a1cadc 100644 --- a/primitives/src/pcs/univariate_kzg/mod.rs +++ b/primitives/src/pcs/univariate_kzg/mod.rs @@ -353,12 +353,14 @@ where ) -> Result, PCSError> { // First, pad to power_of_two, since Toeplitz mul only works for 2^k let mut padded_coeffs: Vec = poly_coeffs.to_vec(); - let padded_degree = (padded_coeffs.len() - 1) + let padded_degree = padded_coeffs + .len() + .saturating_sub(1) .checked_next_power_of_two() .ok_or_else(|| { PCSError::InvalidParameters(ark_std::format!( "Next power of two overflows! Got: {}", - (padded_coeffs.len() - 1) + padded_coeffs.len().saturating_sub(1) )) })?; let padded_len = padded_degree + 1; diff --git a/primitives/src/vid/advz.rs b/primitives/src/vid/advz.rs index e56ed201c..b5b811b05 100644 --- a/primitives/src/vid/advz.rs +++ b/primitives/src/vid/advz.rs @@ -275,7 +275,11 @@ where /// Same as [`VidScheme::disperse`] except `payload` is a slice of /// field elements. pub fn disperse_from_elems(&self, payload: &[P::Evaluation]) -> VidResult> { - let num_polys = (payload.len() - 1) / self.payload_chunk_size + 1; + let num_polys = if payload.is_empty() { + 0 + } else { + (payload.len() - 1) / self.payload_chunk_size + 1 + }; let domain = P::multi_open_rou_eval_domain(self.payload_chunk_size, self.num_storage_nodes) .map_err(vid)?; From 798700771a90c16ee327404dda5bb742d6566d21 Mon Sep 17 00:00:00 2001 From: Gus Gutoski Date: Tue, 26 Sep 2023 13:40:28 -0400 Subject: [PATCH 3/3] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b431f5889..970fa8033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and follow [semantic versioning](https://semver.org/) for our releases. ### Fixed - [#243](https://github.com/EspressoSystems/jellyfish/pull/243) fixes bug in MerkleTreeGadget implementation for SparseRescueMerkleTree. +- [#377](https://github.com/EspressoSystems/jellyfish/pull/377) fix: VID ADVZ allow zero-length payload ### Added