Skip to content

Fix data_columns sorting when reconstructing blobs #8509

@0xMushow

Description

@0xMushow

This recent change released in v0.9.0 of the rust-eth-kzg library means that data_columns must be sorted.

Referencing to a similar issue: #7991

The reconstruct_blobs function passes cell_ids to recover_cells_and_compute_kzg_proofs, which requires cell indices to be in ascending order per the spec. Unlike reconstruct_data_columnswhich already sorts:

pub fn reconstruct_data_columns<E: EthSpec>(
kzg: &Kzg,
mut data_columns: Vec<Arc<DataColumnSidecar<E>>>,
spec: &ChainSpec,
) -> Result<DataColumnSidecarList<E>, KzgError> {
// Sort data columns by index to ensure ascending order for KZG operations
data_columns.sort_unstable_by_key(|dc| dc.index);

reconstruct_blobs was iterating over data_columns in whatever order they were passed, potentially violating the KZG recovery precondition.

for data_column in data_columns {
let cell = data_column
.column
.get(row_index)
.ok_or(format!("Missing data column at row index {row_index}"))
.and_then(|cell| {
ssz_cell_to_crypto_cell::<E>(cell).map_err(|e| format!("{e:?}"))
})?;
cells.push(cell);
cell_ids.push(data_column.index);
}

.recover_cells_and_compute_kzg_proofs(&cell_ids, &cells)

Additional Info

According to the specification, indices passed to recover_cells_and_compute_kzg_proofs must be ordered.

# Check that indices are in ascending order
assert cell_indices == sorted(cell_indices)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions