-
Notifications
You must be signed in to change notification settings - Fork 995
Fix data_columns sorting when reconstructing blobs #8509
Description
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:
lighthouse/beacon_node/beacon_chain/src/kzg_utils.rs
Lines 390 to 396 in 90dd5bb
| 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.
lighthouse/beacon_node/beacon_chain/src/kzg_utils.rs
Lines 334 to 345 in 90dd5bb
| 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)