Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kate/benches/reconstruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn sample_cells_from_matrix(matrix: &DMatrix<ArkScalar>, columns: Option<&[u16]>
let position = Position::new(row_pos, col_idx);
debug_assert!(*row_idx < col_view.len());
let data = col_view[*row_idx].to_bytes();
DataCell::new(position, data.unwrap())
DataCell::new(position, data.unwrap().to_vec())
})
.collect::<Vec<_>>()
})
Expand Down
32 changes: 16 additions & 16 deletions kate/recovery/src/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub fn decode_app_extrinsics(
.filter(|cell| !cell.data.is_empty())
{
None => app_data.extend(vec![0; CHUNK_SIZE]),
Some(cell) => app_data.extend(cell.data),
Some(cell) => app_data.extend(cell.data.clone()),
}
}

Expand Down Expand Up @@ -897,19 +897,19 @@ mod tests {
let cells = vec![
DataCell {
position: Position { row: 0, col: 0 },
data: coded[0].to_bytes().unwrap(),
data: coded[0].to_bytes().unwrap().to_vec(),
},
DataCell {
position: Position { row: 4, col: 0 },
data: coded[4].to_bytes().unwrap(),
data: coded[4].to_bytes().unwrap().to_vec(),
},
DataCell {
position: Position { row: 6, col: 0 },
data: coded[6].to_bytes().unwrap(),
data: coded[6].to_bytes().unwrap().to_vec(),
},
DataCell {
position: Position { row: 2, col: 0 },
data: coded[2].to_bytes().unwrap(),
data: coded[2].to_bytes().unwrap().to_vec(),
},
];

Expand All @@ -935,19 +935,19 @@ mod tests {
let cells = vec![
DataCell {
position: Position { row: 0, col: 0 },
data: coded[0].to_bytes().unwrap(),
data: coded[0].to_bytes().unwrap().to_vec(),
},
DataCell {
position: Position { row: 0, col: 0 },
data: coded[0].to_bytes().unwrap(),
data: coded[0].to_bytes().unwrap().to_vec(),
},
DataCell {
position: Position { row: 6, col: 0 },
data: coded[6].to_bytes().unwrap(),
data: coded[6].to_bytes().unwrap().to_vec(),
},
DataCell {
position: Position { row: 2, col: 0 },
data: coded[2].to_bytes().unwrap(),
data: coded[2].to_bytes().unwrap().to_vec(),
},
];

Expand All @@ -968,15 +968,15 @@ mod tests {
let cells = vec![
DataCell {
position: Position { row: 4, col: 0 },
data: coded[4].to_bytes().unwrap(),
data: coded[4].to_bytes().unwrap().to_vec(),
},
DataCell {
position: Position { row: 6, col: 0 },
data: coded[6].to_bytes().unwrap(),
data: coded[6].to_bytes().unwrap().to_vec(),
},
DataCell {
position: Position { row: 2, col: 0 },
data: coded[2].to_bytes().unwrap(),
data: coded[2].to_bytes().unwrap().to_vec(),
},
];

Expand All @@ -997,19 +997,19 @@ mod tests {
let cells = vec![
DataCell {
position: Position { row: 0, col: 0 },
data: coded[0].to_bytes().unwrap(),
data: coded[0].to_bytes().unwrap().to_vec(),
},
DataCell {
position: Position { row: 5, col: 0 },
data: coded[4].to_bytes().unwrap(),
data: coded[4].to_bytes().unwrap().to_vec(),
},
DataCell {
position: Position { row: 6, col: 0 },
data: coded[6].to_bytes().unwrap(),
data: coded[6].to_bytes().unwrap().to_vec(),
},
DataCell {
position: Position { row: 2, col: 0 },
data: coded[2].to_bytes().unwrap(),
data: coded[2].to_bytes().unwrap().to_vec(),
},
];

Expand Down
47 changes: 29 additions & 18 deletions kate/recovery/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use alloc::string::String;
/// Position and data of a cell in extended matrix
#[derive(Default, Debug, Clone, Constructor)]
pub struct DataCell {
/// SingleCell's position
/// Cell's position
pub position: Position,
/// SingleCell's data
pub data: [u8; 32],
/// Cell's data
pub data: Vec<u8>,
}

/// Position and content of a cell in extended matrix
Expand Down Expand Up @@ -281,25 +281,36 @@ impl TryFrom<Cell> for SingleCell {

/// Merges cells data per row.
/// Cells are sorted before merge.
pub fn rows(dimensions: Dimensions, cells: &[&SingleCell]) -> Vec<(RowIndex, Vec<u8>)> {
pub fn rows(dimensions: Dimensions, cells: &[&Cell]) -> Vec<(RowIndex, Vec<u8>)> {
let mut sorted_cells = cells.to_vec();

sorted_cells
.sort_by(|a, b| (a.position.row, a.position.col).cmp(&(b.position.row, b.position.col)));
sorted_cells.sort_by(|a, b| {
(a.position().row, a.position().col).cmp(&(b.position().row, b.position().col))
});

let mut rows = BTreeMap::new();
for cell in sorted_cells {
rows.entry(RowIndex(cell.position.row))
.or_insert_with(Vec::default)
let row_index = RowIndex(cell.position().row);
rows.entry(row_index)
.or_insert_with(Vec::new)
.extend(cell.data());
}

rows.retain(|_, row| row.len() == dimensions.row_byte_size());
rows.into_iter().collect::<Vec<(_, _)>>()
rows.into_iter().collect()
}

impl From<SingleCell> for DataCell {
fn from(cell: SingleCell) -> Self {
DataCell {
position: cell.position,
data: cell.data().to_vec(),
}
}
}

impl From<MultiProofCell> for DataCell {
fn from(cell: MultiProofCell) -> Self {
DataCell {
position: cell.position,
data: cell.data(),
Expand Down Expand Up @@ -336,13 +347,13 @@ mod tests {
let dimensions = Dimensions::new(1, 2).unwrap();

let cell_variants = vec![
cell(position(1, 1), content([3; 32])).into(),
cell(position(1, 0), content([2; 32])).into(),
cell(position(0, 0), content([0; 32])).into(),
cell(position(0, 1), content([1; 32])).into(),
Cell::from(cell(position(1, 1), content([3; 32]))),
Cell::from(cell(position(1, 0), content([2; 32]))),
Cell::from(cell(position(0, 0), content([0; 32]))),
Cell::from(cell(position(0, 1), content([1; 32]))),
];

let cells: Vec<&SingleCell> = cell_variants.iter().collect();
let cells: Vec<&Cell> = cell_variants.iter().collect();
let mut rows = rows(dimensions, &cells);
rows.sort_by_key(|(key, _)| key.0);

Expand All @@ -363,12 +374,12 @@ mod tests {
let dimensions = Dimensions::new(1, 2).unwrap();

let cell_variants = vec![
cell(position(1, 1), content([3; 32])).into(),
cell(position(0, 0), content([0; 32])).into(),
cell(position(0, 1), content([1; 32])).into(),
Cell::from(cell(position(1, 1), content([3; 32]))),
Cell::from(cell(position(0, 0), content([0; 32]))),
Cell::from(cell(position(0, 1), content([1; 32]))),
];

let cells: Vec<&SingleCell> = cell_variants.iter().collect();
let cells: Vec<&Cell> = cell_variants.iter().collect();
let mut rows = rows(dimensions, &cells);
rows.sort_by_key(|(key, _)| key.0);

Expand Down
4 changes: 2 additions & 2 deletions kate/src/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ mod tests {
let position = Position::new(row_pos, col_idx);
debug_assert!(*row_idx < col_view.len());
let data = col_view[*row_idx].to_bytes();
DataCell::new(position, data.unwrap())
DataCell::new(position, data.unwrap().to_vec())
})
.collect::<Vec<_>>()
})
Expand Down Expand Up @@ -1083,7 +1083,7 @@ get erasure coded to ensure redundancy."#;
let col: usize = position.col.into();
let row = usize::try_from(position.row).unwrap();
let data = matrix.get((row, col)).map(ArkScalar::to_bytes).unwrap();
DataCell::new(position, data.unwrap())
DataCell::new(position, data.unwrap().to_vec())
})
.collect::<Vec<_>>();
let data = &decode_app_extrinsics(&index, dimensions, cells, xt.app_id).unwrap()[0];
Expand Down
3 changes: 2 additions & 1 deletion kate/src/gridgen/tests/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ get erasure coded to ensure redundancy."#;
.get((pos.row as usize, pos.col as usize))
.unwrap()
.to_bytes()
.unwrap(),
.unwrap()
.to_vec(),
})
.collect::<Vec<_>>();
let data = &decode_app_extrinsics(&grid.lookup, bdims, cells, xt.app_id).unwrap()[0];
Expand Down
3 changes: 2 additions & 1 deletion kate/src/gridgen/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ fn sample_cells(grid: &EvaluationGrid, columns: Option<Vec<usize>>) -> Vec<DataC
.evals
.get((y, *x))
.and_then(|s: &ArkScalar| s.to_bytes().ok())
.unwrap();
.unwrap()
.to_vec();
// SAFETY: `y` and `x` can be casted safetly becasue `x < g_cols (u16)` and `y
// < g_rows(u16)`
let position = Position::from((y as u32, *x as u16));
Expand Down
Loading