Skip to content

Commit

Permalink
Fix verify_kzg_proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
povi committed May 15, 2024
1 parent 251cd79 commit 3f53d36
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 16 additions & 15 deletions eip_7594/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,23 +80,21 @@ pub fn verify_kzg_proofs<P: Preset>(data_column_sidecar: &DataColumnSidecar<P>)
}
);

let mut row_ids = Vec::new();
for i in 0..column.len() {
row_ids.push(i as u64);
}
let (row_indices, col_indices): (Vec<_>, Vec<_>) = column
.iter()
.zip(0_u64..)
.map(|(_, row_index)| (row_index, index))
.unzip();

let kzg_settings = load_kzg_settings()?;

// let trusted_setup_file = std::path::Path::new("../kzg_utils/src/trusted_setup.txt");
// let kzg_settings = KzgSettings::load_trusted_setup_file(trusted_setup_file).unwrap();

let column = column
.clone()
.into_iter()
.map(|a| CKzgCell::from_bytes(a.as_bytes()).map_err(Into::into))
.collect::<Result<Vec<_>>>()?;

let commitment = kzg_commitments
let commitments = kzg_commitments
.iter()
.map(|a| Bytes48::from_bytes(a.as_bytes()).map_err(Into::into))
.collect::<Result<Vec<_>>>()?;
Expand All @@ -106,11 +104,11 @@ pub fn verify_kzg_proofs<P: Preset>(data_column_sidecar: &DataColumnSidecar<P>)
.map(|a| Bytes48::from_bytes(&a.as_bytes()).map_err(Into::into))
.collect::<Result<Vec<_>>>()?;

Ok(CKzgProof::verify_cell_proof_batch(
commitment.as_slice(),
&row_ids,
&[*index],
&column[..],
Ok(CKzgProof::verify_cell_kzg_proof_batch(
commitments.as_slice(),
&row_indices,
&col_indices,
column.as_slice(),
&kzg_proofs,
&kzg_settings,
)?)
Expand Down Expand Up @@ -203,6 +201,7 @@ pub fn compute_extended_matrix(blobs: Vec<CKzgBlob>) -> Result<ExtendedMatrix> {
Ok(array)
}

/*
fn recover_matrix(
cells_dict: &HashMap<(BlobIndex, CellID), CKzgCell>,
blob_count: usize,
Expand All @@ -221,7 +220,7 @@ fn recover_matrix(
.iter()
.map(|&cell_id| cells_dict[&(blob_index as u64, cell_id)])
.collect();
let full_polynomial = CKzgCell::recover_polynomial(&cell_ids, &cells, &kzg_settings)?;
let full_polynomial = CKzgCell::recover_all_cells(&cell_ids, &cells, &kzg_settings)?;
extended_matrix.push(full_polynomial);
}
let mut array = [CKzgCell::default(); (MAX_BLOBS_PER_BLOCK * NumberOfColumns::U64) as usize];
Expand Down Expand Up @@ -255,7 +254,7 @@ pub fn get_data_column_sidecars<P: Preset>(
let cells_and_proofs = c_kzg_blobs
.into_iter()
.map(|blob| {
CKzgCell::compute_cells_and_proofs(&blob, &kzg_settings).map_err(Into::into)
CKzgCell::compute_cells_and_kzg_proofs(&blob, &kzg_settings).map_err(Into::into)
})
.collect::<Result<Vec<_>>>()?;
Expand Down Expand Up @@ -304,6 +303,7 @@ pub fn get_data_column_sidecars<P: Preset>(
Ok(vec![])
}
*/

fn kzg_commitment_inclusion_proof<P: Preset>(
body: &(impl PostDenebBeaconBlockBody<P> + ?Sized),
Expand Down Expand Up @@ -356,6 +356,7 @@ fn load_kzg_settings() -> Result<KzgSettings> {
.chunks_exact(BYTES_PER_G2)
.map(|chunk| TryInto::<[u8; BYTES_PER_G2]>::try_into(chunk).map_err(Into::into))
.collect::<Result<Vec<_>>>()?,
0,
)
.map_err(|error| anyhow!(error))
}
Expand Down

0 comments on commit 3f53d36

Please sign in to comment.