diff --git a/Cargo.toml b/Cargo.toml index b1ae0542..7a02acec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,8 @@ members = [ "consensus/carnot-engine", "consensus/cryptarchia-engine", "ledger/cryptarchia-ledger", - "tests", "nomos-da/kzgrs", + "tests", + "nomos-da/kzgrs", + "nomos-da/kzgrs-backend", ] resolver = "2" diff --git a/nomos-da/kzgrs-backend/src/common.rs b/nomos-da/kzgrs-backend/src/common.rs new file mode 100644 index 00000000..4b52c1e8 --- /dev/null +++ b/nomos-da/kzgrs-backend/src/common.rs @@ -0,0 +1,49 @@ +#[derive(Clone)] +pub struct Chunk(Vec); +pub struct Row(Vec); +pub struct Column(Vec); +struct ChunksMatrix(Vec); + +impl Chunk { + pub fn as_bytes(&self) -> Vec { + self.0.to_vec() + } + + pub const fn empty() -> Self { + Self(vec![]) + } +} + +impl Row { + pub fn as_bytes(&self) -> Vec { + self.0.iter().map(Chunk::as_bytes).flatten().collect() + } +} + +impl Column { + pub fn as_bytes(&self) -> Vec { + self.0.iter().map(Chunk::as_bytes).flatten().collect() + } +} + +impl FromIterator for Column { + fn from_iter>(iter: T) -> Self { + Self(iter.into_iter().collect()) + } +} + +impl ChunksMatrix { + pub fn columns(&self) -> impl Iterator + '_ { + let size = self.0.first().map(|r| r.0.len()).unwrap_or(0); + (0..size).map(|i| { + self.0 + .iter() + .map(|row| row.0.get(i).cloned().unwrap_or_else(Chunk::empty)) + .collect::() + }) + } + + pub fn transposed(&self) -> Self { + Self(self.columns().map(|c| Row(c.0)).collect()) + } +} diff --git a/nomos-da/kzgrs/src/rs.rs b/nomos-da/kzgrs/src/rs.rs index 902f04dd..304ca683 100644 --- a/nomos-da/kzgrs/src/rs.rs +++ b/nomos-da/kzgrs/src/rs.rs @@ -88,8 +88,7 @@ pub fn points_to_bytes(points: &[Fr]) -> Vec { } points .iter() - .map(point_to_buff::) - .flatten() + .flat_map(point_to_buff::) .collect() }