diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 5877675ea..ea8634603 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -1546,8 +1546,8 @@ proc tryReconstructingDataColumns* (self: BeaconNode, # Reconstruct data column sidecars from recovered blobs let reconstructedDataColumns = get_data_column_sidecars(signed_block, recovered_cps.get) debugEcho "Reconstructed Data Columns len" - debugEcho reconstructedDataColumns.get.len - for data_column in reconstructedDataColumns.get: + debugEcho reconstructedDataColumns.len + for data_column in reconstructedDataColumns: if data_column.index notin custodiedColumnIndices: continue diff --git a/beacon_chain/spec/datatypes/eip7594.nim b/beacon_chain/spec/datatypes/eip7594.nim index 99fce6238..b785df39a 100644 --- a/beacon_chain/spec/datatypes/eip7594.nim +++ b/beacon_chain/spec/datatypes/eip7594.nim @@ -27,6 +27,8 @@ const # The number of cells in an extended blob | # RANDOM_CHALLENGE_KZG_CELL_BATCH_DOMAIN = 'RCKZGCBATCH__V1_' KZG_COMMITMENTS_INCLUSION_PROOF_DEPTH* = 4 + KZG_COMMITMENTS_INCLUSION_PROOF_DEPTH_GINDEX* = 27 + type BLSFieldElement* = KzgBytes32 diff --git a/beacon_chain/spec/eip7594_helpers.nim b/beacon_chain/spec/eip7594_helpers.nim index 71ec90306..7b87ed462 100644 --- a/beacon_chain/spec/eip7594_helpers.nim +++ b/beacon_chain/spec/eip7594_helpers.nim @@ -247,97 +247,124 @@ proc compute_signed_block_header(signed_block: deneb.SignedBeaconBlock | signature: signed_block.signature ) -# https://github.com/ethereum/consensus-specs/blob/bb8f3caafc92590cdcf2d14974adb602db9b5ca3/specs/_features/eip7594/das-core.md#get_data_column_sidecars -proc get_data_column_sidecars*(signed_block: deneb.TrustedSignedBeaconBlock | - deneb.SignedBeaconBlock | - electra.TrustedSignedBeaconBlock | - electra.SignedBeaconBlock, +# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.6/specs/_features/eip7594/das-core.md#get_data_column_sidecars +proc get_data_column_sidecars*(signed_beacon_block: deneb.TrustedSignedBeaconBlock | + electra.TrustedSignedBeaconBlock, cellsAndProofs: seq[CellsAndProofs]): - Result[seq[DataColumnSidecar], string] = - # Given a signed block and the cells/proofs associated with each blob - # in the block, assemble the sidecars which can be distributed to peers. + seq[DataColumnSidecar] = + ## Given a trusted signed beacon block and the cells/proofs associated + ## with each data column (thereby blob as well) corresponding to the block, + ## this function assembles the sidecars which can be distributed to + ## the peers post data column reconstruction at every slot start. + ## + ## Note: this function only accepts `TrustedSignedBeaconBlock` as + ## during practice we would be computing cells and proofs from + ## data columns only after retrieving them from the database, where + ## they we were already verified and persisted. + template blck(): auto = signed_beacon_block.message + let + beacon_block_header = + BeaconBlockHeader( + slot: blck.slot, + proposer_index: blck.proposer_index, + parent_root: blck.parent_root, + state_root: blck.state_root, + body_root: hash_tree_root(blck.body)) + + signed_beacon_block_header = + SignedBeaconBlockHeader( + message: beacon_block_header, + signature: signed_beacon_block.signature.toValidatorSig) + var - blck = signed_block.message - signed_beacon_block_header = - compute_signed_block_header(signed_block) - kzg_incl_proof: array[4, Eth2Digest] - - var sidecars = newSeqOfCap[DataColumnSidecar](CELLS_PER_EXT_BLOB) - - if cellsAndProofs.len == 0: - return ok(sidecars) + sidecars = + newSeqOfCap[DataColumnSidecar](kzg_abi.CELLS_PER_EXT_BLOB) for column_index in 0..