From 2ca822e6ecfb5c465540b7f15593df5c71118fba Mon Sep 17 00:00:00 2001 From: gusto Date: Tue, 20 Aug 2024 13:15:16 +0300 Subject: [PATCH] ColumnIndex in DaBlob (#693) * ColumnIndex in DaBlob * Use u16 for column index --- nomos-cli/src/da/network/adapters/mock.rs | 3 +++ nomos-da/kzgrs-backend/src/common/blob.rs | 2 ++ nomos-da/kzgrs-backend/src/common/mod.rs | 1 + nomos-da/kzgrs-backend/src/dispersal.rs | 3 +++ nomos-da/kzgrs-backend/src/verifier.rs | 3 +++ nomos-da/network/core/src/protocols/dispersal/mod.rs | 1 + nomos-da/network/core/src/protocols/sampling/mod.rs | 1 + .../data-availability/tests/src/verifier_integration.rs | 3 +++ 8 files changed, 17 insertions(+) diff --git a/nomos-cli/src/da/network/adapters/mock.rs b/nomos-cli/src/da/network/adapters/mock.rs index 059d5aa5..b5fa131a 100644 --- a/nomos-cli/src/da/network/adapters/mock.rs +++ b/nomos-cli/src/da/network/adapters/mock.rs @@ -45,6 +45,9 @@ impl DaDispersal for MockExecutorDispersalAdapter { for (i, column) in encoded_data.extended_data.columns().enumerate() { let blob = DaBlob { column: column.clone(), + column_idx: i + .try_into() + .expect("Column index shouldn't overflow the target type"), column_commitment: encoded_data.column_commitments[i], aggregated_column_commitment: encoded_data.aggregated_column_commitment, aggregated_column_proof: encoded_data.aggregated_column_proofs[i], diff --git a/nomos-da/kzgrs-backend/src/common/blob.rs b/nomos-da/kzgrs-backend/src/common/blob.rs index 479401a0..d40332d1 100644 --- a/nomos-da/kzgrs-backend/src/common/blob.rs +++ b/nomos-da/kzgrs-backend/src/common/blob.rs @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize}; use sha3::{Digest, Sha3_256}; // internal use super::build_blob_id; +use super::ColumnIndex; use crate::common::Column; use crate::common::Commitment; use crate::common::{ @@ -15,6 +16,7 @@ use crate::common::{ #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DaBlob { pub column: Column, + pub column_idx: ColumnIndex, #[serde( serialize_with = "serialize_canonical", deserialize_with = "deserialize_canonical" diff --git a/nomos-da/kzgrs-backend/src/common/mod.rs b/nomos-da/kzgrs-backend/src/common/mod.rs index 6545ddb9..d0cb622a 100644 --- a/nomos-da/kzgrs-backend/src/common/mod.rs +++ b/nomos-da/kzgrs-backend/src/common/mod.rs @@ -19,6 +19,7 @@ pub struct Row(pub Vec); #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Column(pub Vec); pub struct ChunksMatrix(pub Vec); +pub type ColumnIndex = u16; pub const NOMOS_DA_DST: &[u8] = b"NOMOS_DA_AVAIL"; diff --git a/nomos-da/kzgrs-backend/src/dispersal.rs b/nomos-da/kzgrs-backend/src/dispersal.rs index 72fc1b70..43c3e184 100644 --- a/nomos-da/kzgrs-backend/src/dispersal.rs +++ b/nomos-da/kzgrs-backend/src/dispersal.rs @@ -105,6 +105,9 @@ mod tests { let verifier = &verifiers[i]; let da_blob = DaBlob { column, + column_idx: i + .try_into() + .expect("Column index shouldn't overflow the target type"), column_commitment: encoded_data.column_commitments[i], aggregated_column_commitment: encoded_data.aggregated_column_commitment, aggregated_column_proof: encoded_data.aggregated_column_proofs[i], diff --git a/nomos-da/kzgrs-backend/src/verifier.rs b/nomos-da/kzgrs-backend/src/verifier.rs index 9ec22d2e..a9ba30d2 100644 --- a/nomos-da/kzgrs-backend/src/verifier.rs +++ b/nomos-da/kzgrs-backend/src/verifier.rs @@ -223,6 +223,9 @@ mod test { let verifier = &verifiers[i]; let da_blob = DaBlob { column, + column_idx: i + .try_into() + .expect("Column index shouldn't overflow the target type"), column_commitment: encoded_data.column_commitments[i], aggregated_column_commitment: encoded_data.aggregated_column_commitment, aggregated_column_proof: encoded_data.aggregated_column_proofs[i], diff --git a/nomos-da/network/core/src/protocols/dispersal/mod.rs b/nomos-da/network/core/src/protocols/dispersal/mod.rs index 9ea4c5e0..90b18d96 100644 --- a/nomos-da/network/core/src/protocols/dispersal/mod.rs +++ b/nomos-da/network/core/src/protocols/dispersal/mod.rs @@ -127,6 +127,7 @@ pub mod test { .send(( 0, DaBlob { + column_idx: 0, column: Column(vec![]), column_commitment: Default::default(), aggregated_column_commitment: Default::default(), diff --git a/nomos-da/network/core/src/protocols/sampling/mod.rs b/nomos-da/network/core/src/protocols/sampling/mod.rs index f3f01e2e..b76bdc1e 100644 --- a/nomos-da/network/core/src/protocols/sampling/mod.rs +++ b/nomos-da/network/core/src/protocols/sampling/mod.rs @@ -97,6 +97,7 @@ mod test { Blob { blob_id: vec![], data: bincode::serialize(&DaBlob { + column_idx: 0, column: Column(vec![]), column_commitment: Default::default(), aggregated_column_commitment: Default::default(), diff --git a/nomos-services/data-availability/tests/src/verifier_integration.rs b/nomos-services/data-availability/tests/src/verifier_integration.rs index dc29d6bf..36a35d01 100644 --- a/nomos-services/data-availability/tests/src/verifier_integration.rs +++ b/nomos-services/data-availability/tests/src/verifier_integration.rs @@ -261,6 +261,9 @@ fn test_verifier() { let da_blob = DaBlob { column: column.clone(), + column_idx: i + .try_into() + .expect("Column index shouldn't overflow the target type"), column_commitment: encoded_data.column_commitments[i], aggregated_column_commitment: encoded_data.aggregated_column_commitment, aggregated_column_proof: encoded_data.aggregated_column_proofs[i],