Skip to content

Optimize validate_data_columns #7326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: unstable
Choose a base branch
from
Open
Changes from all 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
53 changes: 21 additions & 32 deletions beacon_node/beacon_chain/src/kzg_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use std::sync::Arc;
use types::beacon_block_body::KzgCommitments;
use types::data_column_sidecar::{Cell, DataColumn, DataColumnSidecarError};
use types::{
Blob, BlobSidecar, BlobSidecarList, ChainSpec, ColumnIndex, DataColumnSidecar,
DataColumnSidecarList, EthSpec, Hash256, KzgCommitment, KzgProof, SignedBeaconBlock,
SignedBeaconBlockHeader, SignedBlindedBeaconBlock,
Blob, BlobSidecar, BlobSidecarList, ChainSpec, DataColumnSidecar, DataColumnSidecarList,
EthSpec, Hash256, KzgCommitment, KzgProof, SignedBeaconBlock, SignedBeaconBlockHeader,
SignedBlindedBeaconBlock,
};

/// Converts a blob ssz List object to an array to be used with the kzg
Expand Down Expand Up @@ -79,38 +79,27 @@ pub fn validate_data_columns<'a, E: EthSpec, I>(
where
I: Iterator<Item = &'a Arc<DataColumnSidecar<E>>> + Clone,
{
let cells = data_column_iter
.clone()
.flat_map(|data_column| data_column.column.iter().map(ssz_cell_to_crypto_cell::<E>))
.collect::<Result<Vec<_>, KzgError>>()?;
let mut cells = Vec::new();
let mut proofs = Vec::new();
let mut column_indices = Vec::new();
let mut commitments = Vec::new();

let proofs = data_column_iter
.clone()
.flat_map(|data_column| {
data_column
.kzg_proofs
.iter()
.map(|&proof| Bytes48::from(proof))
})
.collect::<Vec<_>>();
for data_column in data_column_iter {
let col_index = data_column.index;

let column_indices = data_column_iter
.clone()
.flat_map(|data_column| {
let col_index = data_column.index;
data_column.column.iter().map(move |_| col_index)
})
.collect::<Vec<ColumnIndex>>();
for cell in &data_column.column {
cells.push(ssz_cell_to_crypto_cell::<E>(cell)?);
column_indices.push(col_index);
}

let commitments = data_column_iter
.clone()
.flat_map(|data_column| {
data_column
.kzg_commitments
.iter()
.map(|&commitment| Bytes48::from(commitment))
})
.collect::<Vec<_>>();
for &proof in &data_column.kzg_proofs {
proofs.push(Bytes48::from(proof));
}

for &commitment in &data_column.kzg_commitments {
commitments.push(Bytes48::from(commitment));
}
}

kzg.verify_cell_proof_batch(&cells, &proofs, column_indices, &commitments)
}
Expand Down
Loading