fix: get dc sidecar

This commit is contained in:
Agnish Ghosh 2024-07-05 15:56:03 +05:30
parent fab427d65f
commit 086d3f1fdc
No known key found for this signature in database
GPG Key ID: 7BDDA05D1B25E9F8
1 changed files with 9 additions and 15 deletions

View File

@ -215,18 +215,12 @@ proc get_data_column_sidecars*(signed_block: deneb.SignedBeaconBlock |
electra.SignedBeaconBlock, electra.SignedBeaconBlock,
blobs: seq[KzgBlob]): blobs: seq[KzgBlob]):
Result[seq[DataColumnSidecar], cstring] = Result[seq[DataColumnSidecar], cstring] =
var var
sidecar: DataColumnSidecar
blck = signed_block.message blck = signed_block.message
signed_beacon_block_header = compute_signed_block_header(signed_block) signed_beacon_block_header = compute_signed_block_header(signed_block)
cellsAndProofs: seq[KzgCellsAndKzgProofs] cellsAndProofs: seq[KzgCellsAndKzgProofs]
kzg_incl_proof: array[4, Eth2Digest] kzg_incl_proof: array[4, Eth2Digest]
blck.body.build_proof(
11.GeneralizedIndex,
kzg_incl_proof).expect("Valid gindex")
for blob in blobs: for blob in blobs:
let let
computed_cell = computeCellsAndProofs(blob) computed_cell = computeCellsAndProofs(blob)
@ -249,7 +243,7 @@ proc get_data_column_sidecars*(signed_block: deneb.SignedBeaconBlock |
for j in 0..<int(MAX_BLOB_COMMITMENTS_PER_BLOCK): for j in 0..<int(MAX_BLOB_COMMITMENTS_PER_BLOCK):
proofs[i].add(cellsAndProofs[i].proofs[j]) proofs[i].add(cellsAndProofs[i].proofs[j])
var sidecars: seq[DataColumnSidecar] var sidecars: newSeqOfCap[DataColumnSidecar](NUMBER_OF_COLUMNS)
for columnIndex in 0..<NUMBER_OF_COLUMNS: for columnIndex in 0..<NUMBER_OF_COLUMNS:
var column: DataColumn var column: DataColumn
@ -260,16 +254,16 @@ proc get_data_column_sidecars*(signed_block: deneb.SignedBeaconBlock |
for rowIndex in 0..<blobCount: for rowIndex in 0..<blobCount:
kzgProofOfColumn[rowIndex] = proofs[rowIndex][columnIndex] kzgProofOfColumn[rowIndex] = proofs[rowIndex][columnIndex]
sidecar = DataColumnSidecar( var sidecar = DataColumnSidecar(
index: ColumnIndex(columnIndex), index: ColumnIndex(columnIndex),
column: column, column: column,
kzgCommitments: blck.body.blob_kzg_commitments, kzgCommitments: blck.body.blob_kzg_commitments,
kzgProofs: kzgProofOfColumn, kzgProofs: kzgProofOfColumn,
signed_block_header: signed_beacon_block_header, signed_block_header: signed_beacon_block_header)
kzg_commitments_inclusion_proof: kzg_incl_proof blck.body.build_proof(
) kzg_commitment_inclusion_proof_gindex(columnIndex),
sidecar.kzg_commitment_inclusion_proof).expect("Valid gindex")
sidecars.add(sidecar) sidecars.add(sidecar)
ok(sidecars) ok(sidecars)
# Helper function to `verifyCellKzgProofBatch` at https://github.com/ethereum/c-kzg-4844/blob/das/bindings/nim/kzg_ex.nim#L170 # Helper function to `verifyCellKzgProofBatch` at https://github.com/ethereum/c-kzg-4844/blob/das/bindings/nim/kzg_ex.nim#L170
@ -327,12 +321,12 @@ proc verify_data_column_sidecar_kzg_proofs*(sidecar: DataColumnSidecar): Result[
# https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/p2p-interface.md#verify_data_column_sidecar_inclusion_proof # https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/p2p-interface.md#verify_data_column_sidecar_inclusion_proof
func verify_data_column_sidecar_inclusion_proof*(sidecar: DataColumnSidecar): Result[void, string] = func verify_data_column_sidecar_inclusion_proof*(sidecar: DataColumnSidecar): Result[void, string] =
# Verify if the given KZG commitments are included in the beacon block # Verify if the given KZG commitments are included in the beacon block
let gindex = 11.GeneralizedIndex let gindex = kzg_commitment_inclusion_proof_gindex(sidecar.index)
if not is_valid_merkle_branch( if not is_valid_merkle_branch(
hash_tree_root(sidecar.kzg_commitments), hash_tree_root(sidecar.kzg_commitments),
sidecar.kzg_commitments_inclusion_proof, sidecar.kzg_commitments_inclusion_proof,
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH, KZG_COMMITMENT_INCLUSION_PROOF_DEPTH,
gindex, get_subtree_index(gindex),
sidecar.signed_block_header.message.body_root): sidecar.signed_block_header.message.body_root):
return err("DataColumnSidecar: inclusion proof not valid") return err("DataColumnSidecar: inclusion proof not valid")