2024-05-27 12:36:58 +00:00
|
|
|
# beacon_chain
|
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
# Uncategorized helper functions from the spec
|
|
|
|
import
|
2024-05-29 22:21:32 +00:00
|
|
|
std/[algorithm, macros, tables],
|
2024-05-29 08:32:56 +00:00
|
|
|
stew/results,
|
2024-06-26 06:56:37 +00:00
|
|
|
ssz_serialization/[
|
|
|
|
proofs,
|
|
|
|
types],
|
2024-05-27 12:36:58 +00:00
|
|
|
chronicles,
|
|
|
|
./[beacon_time, crypto],
|
2024-06-13 10:49:15 +00:00
|
|
|
kzg4844/kzg_ex,
|
2024-05-27 12:36:58 +00:00
|
|
|
eth/p2p/discoveryv5/[node],
|
|
|
|
./helpers,
|
2024-06-25 20:52:03 +00:00
|
|
|
|
2024-05-28 08:29:31 +00:00
|
|
|
./datatypes/[eip7594, deneb]
|
2024-05-27 12:36:58 +00:00
|
|
|
|
2024-06-27 14:01:04 +00:00
|
|
|
|
2024-07-06 20:36:13 +00:00
|
|
|
type
|
|
|
|
CellBytes = array[eip7594.CELLS_PER_EXT_BLOB, Cell]
|
|
|
|
ProofBytes = array[eip7594.CELLS_PER_EXT_BLOB, KzgProof]
|
|
|
|
|
2024-05-27 12:36:58 +00:00
|
|
|
proc sortedColumnIndices*(columnsPerSubnet: ColumnIndex, subnetIds: HashSet[uint64]): seq[ColumnIndex] =
|
|
|
|
var res: seq[ColumnIndex] = @[]
|
|
|
|
for i in 0 ..< columnsPerSubnet:
|
|
|
|
for subnetId in subnetIds:
|
|
|
|
let index = DATA_COLUMN_SIDECAR_SUBNET_COUNT * i + subnetId
|
|
|
|
result.add(ColumnIndex(index))
|
|
|
|
res.sort()
|
|
|
|
res
|
|
|
|
|
2024-07-06 23:05:06 +00:00
|
|
|
proc get_custody_column_subnet*(node_id: NodeId,
|
|
|
|
custody_subnet_count: uint64):
|
|
|
|
Result[HashSet[uint64], cstring] =
|
2024-06-25 20:34:06 +00:00
|
|
|
# fetches the subnets for custody column for the current node
|
2024-05-28 08:29:31 +00:00
|
|
|
# assert custody_subnet_count <= DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
|
|
|
if not (custody_subnet_count <= DATA_COLUMN_SIDECAR_SUBNET_COUNT):
|
|
|
|
return err("Eip7594: Custody subnet count exceeds the DATA_COLUMN_SIDECAR_SUBNET_COUNT")
|
|
|
|
|
2024-05-29 22:21:32 +00:00
|
|
|
var
|
|
|
|
subnet_ids: HashSet[uint64]
|
|
|
|
current_id = node_id
|
2024-05-28 08:29:31 +00:00
|
|
|
|
|
|
|
while subnet_ids.len < int(custody_subnet_count):
|
2024-06-07 07:40:28 +00:00
|
|
|
|
|
|
|
var subnet_id_bytes: array[8, byte]
|
|
|
|
subnet_id_bytes[0..7] = current_id.toBytesLE().toOpenArray(0,7)
|
|
|
|
|
|
|
|
var subnet_id = bytes_to_uint64(subnet_id_bytes) mod
|
2024-05-29 22:21:32 +00:00
|
|
|
DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
2024-05-27 12:36:58 +00:00
|
|
|
|
2024-05-28 08:29:31 +00:00
|
|
|
if subnet_id notin subnet_ids:
|
|
|
|
subnet_ids.incl(subnet_id)
|
2024-05-27 12:36:58 +00:00
|
|
|
|
2024-05-28 08:29:31 +00:00
|
|
|
if current_id == UInt256.high.NodeId:
|
|
|
|
# Overflow prevention
|
|
|
|
current_id = NodeId(StUint[256].zero)
|
|
|
|
current_id += NodeId(StUint[256].one)
|
2024-05-27 12:36:58 +00:00
|
|
|
|
2024-05-28 08:29:31 +00:00
|
|
|
# assert len(subnet_ids) == len(set(subnet_ids))
|
|
|
|
if not (subnet_ids.len == subnet_ids.len):
|
|
|
|
return err("Eip7594: Subnet ids are not unique")
|
2024-05-27 12:36:58 +00:00
|
|
|
|
2024-06-25 20:34:06 +00:00
|
|
|
ok(subnet_ids)
|
|
|
|
|
|
|
|
# https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/das-core.md#get_custody_columns
|
2024-07-06 23:05:06 +00:00
|
|
|
proc get_custody_columns*(node_id: NodeId,
|
|
|
|
custody_subnet_count: uint64):
|
|
|
|
Result[seq[ColumnIndex], cstring] =
|
2024-06-25 20:34:06 +00:00
|
|
|
|
|
|
|
let subnet_ids = get_custody_column_subnet(node_id, custody_subnet_count).get
|
|
|
|
|
2024-05-28 08:29:31 +00:00
|
|
|
# columns_per_subnet = NUMBER_OF_COLUMNS // DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
|
|
|
let columns_per_subnet = NUMBER_OF_COLUMNS div DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
|
|
|
|
|
|
|
ok(sortedColumnIndices(ColumnIndex(columns_per_subnet), subnet_ids))
|
2024-05-27 12:36:58 +00:00
|
|
|
|
2024-05-29 08:32:56 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/das-core.md#compute_extended_matrix
|
2024-05-28 08:29:31 +00:00
|
|
|
proc compute_extended_matrix* (blobs: seq[KzgBlob]): Result[ExtendedMatrix, cstring] =
|
|
|
|
# This helper demonstrates the relationship between blobs and `ExtendedMatrix`
|
|
|
|
var extended_matrix: ExtendedMatrix
|
2024-06-13 10:49:15 +00:00
|
|
|
for i in 0..<blobs.len:
|
|
|
|
debugEcho "Checkpoint 1"
|
|
|
|
let res = computeCells(blobs[i])
|
|
|
|
debugEcho "Checkpoint 2"
|
2024-05-29 08:32:56 +00:00
|
|
|
if res.isErr:
|
|
|
|
return err("Error computing kzg cells and kzg proofs")
|
2024-06-13 10:49:15 +00:00
|
|
|
debugEcho "Checkpoint 3"
|
2024-05-29 08:32:56 +00:00
|
|
|
discard extended_matrix.add(res.get())
|
2024-06-13 10:49:15 +00:00
|
|
|
debugEcho "Checkpoint 4"
|
2024-05-28 08:29:31 +00:00
|
|
|
ok(extended_matrix)
|
2024-05-31 07:45:03 +00:00
|
|
|
|
2024-05-29 08:32:56 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/das-core.md#recover_matrix
|
2024-07-06 23:05:06 +00:00
|
|
|
proc recover_matrix*(cells_dict: Table[(BlobIndex, CellID), Cell],
|
|
|
|
blobCount: uint64):
|
|
|
|
Result[ExtendedMatrix, cstring] =
|
2024-05-28 08:29:31 +00:00
|
|
|
# This helper demonstrates how to apply recover_all_cells
|
|
|
|
# The data structure for storing cells is implementation-dependent
|
|
|
|
|
|
|
|
var extended_matrix: ExtendedMatrix
|
|
|
|
|
|
|
|
for blobIndex in 0'u64..<blobCount:
|
2024-06-13 11:18:28 +00:00
|
|
|
var
|
|
|
|
cellIds: seq[CellID] = @[]
|
|
|
|
blIdx: BlobIndex
|
|
|
|
cellId: CellID
|
2024-05-28 08:29:31 +00:00
|
|
|
let key = (blIdx, cellId)
|
|
|
|
|
|
|
|
for key, cell in pairs(cells_dict):
|
|
|
|
if blIdx == blobIndex:
|
|
|
|
cellIds.add(cellId)
|
|
|
|
|
2024-06-11 09:42:09 +00:00
|
|
|
var cells: seq[Cell]
|
2024-05-28 08:29:31 +00:00
|
|
|
for cellId in cellIds:
|
|
|
|
var interim_key = (BlobIndex(blobIndex), cellId)
|
|
|
|
|
|
|
|
if cells_dict.hasKey(interim_key):
|
|
|
|
try:
|
|
|
|
let cell = cells_dict[interim_key]
|
|
|
|
cells.add(cell)
|
|
|
|
except:
|
|
|
|
debug "DataColumn: Key not found in Cell Dictionary", interim_key
|
|
|
|
|
2024-05-31 07:45:03 +00:00
|
|
|
let allCellsForRow = recoverAllCells(cellIds, cells)
|
2024-05-29 22:21:32 +00:00
|
|
|
let check = extended_matrix.add(allCellsForRow.get())
|
|
|
|
doAssert check == true, "DataColumn: Could not add cells to the extended matrix"
|
2024-05-28 08:29:31 +00:00
|
|
|
|
2024-05-29 08:32:56 +00:00
|
|
|
ok(extended_matrix)
|
2024-05-27 12:36:58 +00:00
|
|
|
|
2024-07-06 23:05:06 +00:00
|
|
|
proc recover_matrix*(partial_matrix: seq[MatrixEntry],
|
|
|
|
blobCount: int):
|
|
|
|
Result[seq[MatrixEntry], cstring] =
|
2024-06-13 14:45:00 +00:00
|
|
|
# This helper demonstrates how to apply recover_cells_and_kzg_proofs
|
|
|
|
# The data structure for storing cells is implementation-dependent
|
|
|
|
|
|
|
|
var extended_matrix: seq[MatrixEntry]
|
|
|
|
for blob_index in 0..<blobCount:
|
|
|
|
var
|
|
|
|
cell_indices: seq[CellID]
|
|
|
|
cells: seq[Cell]
|
|
|
|
proofs: seq[KzgProof]
|
|
|
|
|
|
|
|
for e in partial_matrix:
|
|
|
|
if e.row_index == uint64(blob_index):
|
|
|
|
cell_indices.add(e.column_index)
|
|
|
|
cells.add(e.cell)
|
|
|
|
proofs.add(e.kzg_proof)
|
|
|
|
|
2024-06-26 10:35:58 +00:00
|
|
|
proc recover_blobs*(
|
|
|
|
data_columns: seq[DataColumnSidecar],
|
|
|
|
columnCount: int,
|
|
|
|
blck: deneb.SignedBeaconBlock |
|
|
|
|
electra.SignedBeaconBlock |
|
|
|
|
ForkySignedBeaconBlock):
|
|
|
|
Result[seq[KzgBlob], cstring] =
|
|
|
|
|
|
|
|
# This helper recovers blobs from the data column sidecars
|
|
|
|
if not (data_columns.len != 0):
|
|
|
|
return err("DataColumnSidecar: Length should not be 0")
|
|
|
|
|
2024-07-03 16:20:52 +00:00
|
|
|
var blobCount = data_columns[0].column.len
|
2024-06-26 10:35:58 +00:00
|
|
|
for data_column in data_columns:
|
|
|
|
if not (blobCount == data_column.column.len):
|
|
|
|
return err ("DataColumns do not have the same length")
|
|
|
|
|
|
|
|
var recovered_blobs = newSeqOfCap[KzgBlob](blobCount)
|
|
|
|
|
|
|
|
for blobIdx in 0 ..< blobCount:
|
|
|
|
var
|
|
|
|
cell_ids = newSeqOfCap[CellID](columnCount)
|
|
|
|
ckzgCells = newSeqOfCap[KzgCell](columnCount)
|
|
|
|
|
|
|
|
for data_column in data_columns:
|
|
|
|
cell_ids.add(data_column.index)
|
|
|
|
|
|
|
|
let
|
|
|
|
column = data_column.column
|
|
|
|
cell = column[blobIdx]
|
|
|
|
|
|
|
|
# Transform the cell as a ckzg cell
|
|
|
|
var ckzgCell: Cell
|
|
|
|
for i in 0 ..< int(FIELD_ELEMENTS_PER_CELL):
|
2024-07-03 16:20:52 +00:00
|
|
|
var start = 32 * i
|
|
|
|
for j in 0 ..< 32:
|
|
|
|
ckzgCell[start + j] = cell[start+j]
|
2024-06-26 10:35:58 +00:00
|
|
|
|
|
|
|
ckzgCells.add(ckzgCell)
|
|
|
|
|
|
|
|
# Recovering the blob
|
|
|
|
let recovered_cells = recoverAllCells(cell_ids, ckzgCells)
|
|
|
|
if not recovered_cells.isOk:
|
2024-07-03 16:20:52 +00:00
|
|
|
return err ("Recovering all cells for blob failed")
|
2024-06-26 10:35:58 +00:00
|
|
|
|
|
|
|
let recovered_blob_res = cellsToBlob(recovered_cells.get)
|
|
|
|
if not recovered_blob_res.isOk:
|
2024-07-03 16:20:52 +00:00
|
|
|
return err ("Cells to blob for blob failed")
|
2024-06-26 10:35:58 +00:00
|
|
|
|
|
|
|
recovered_blobs.add(recovered_blob_res.get)
|
|
|
|
|
|
|
|
ok(recovered_blobs)
|
|
|
|
|
2024-07-04 11:19:55 +00:00
|
|
|
proc compute_signed_block_header(signed_block: deneb.SignedBeaconBlock |
|
|
|
|
electra.SignedBeaconBlock):
|
|
|
|
SignedBeaconBlockHeader =
|
|
|
|
let blck = signed_block.message
|
|
|
|
let 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)
|
|
|
|
)
|
|
|
|
result = SignedBeaconBlockHeader(
|
|
|
|
message: block_header,
|
|
|
|
signature: signed_block.signature
|
|
|
|
)
|
|
|
|
|
2024-05-29 08:32:56 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/das-core.md#get_data_column_sidecars
|
2024-07-04 11:19:55 +00:00
|
|
|
proc get_data_column_sidecars*(signed_block: deneb.SignedBeaconBlock |
|
|
|
|
electra.SignedBeaconBlock,
|
|
|
|
blobs: seq[KzgBlob]):
|
2024-07-06 07:54:51 +00:00
|
|
|
Result[seq[DataColumnSidecar], string] =
|
2024-07-05 10:26:03 +00:00
|
|
|
var
|
2024-06-24 12:02:06 +00:00
|
|
|
blck = signed_block.message
|
2024-07-04 11:19:55 +00:00
|
|
|
signed_beacon_block_header = compute_signed_block_header(signed_block)
|
2024-07-04 06:21:54 +00:00
|
|
|
kzg_incl_proof: array[4, Eth2Digest]
|
2024-06-26 06:56:37 +00:00
|
|
|
|
2024-07-06 19:13:24 +00:00
|
|
|
var sidecars = newSeqOfCap[DataColumnSidecar](CELLS_PER_EXT_BLOB)
|
|
|
|
|
2024-07-06 07:54:51 +00:00
|
|
|
if blobs.len == 0:
|
2024-07-06 21:31:32 +00:00
|
|
|
debugEcho "Checkpoint 3"
|
2024-07-06 19:13:24 +00:00
|
|
|
return ok(sidecars)
|
2024-07-06 07:54:51 +00:00
|
|
|
|
2024-07-06 23:05:06 +00:00
|
|
|
var
|
|
|
|
cells = newSeqOfCap[CellBytes](blobs.len)
|
|
|
|
proofs = newSeqOfCap[ProofBytes](blobs.len)
|
|
|
|
|
|
|
|
debugEcho "Cells len"
|
|
|
|
debugEcho cells.len
|
|
|
|
debugEcho cells[0].len
|
|
|
|
debugEcho cells[0][0].len
|
|
|
|
|
|
|
|
debugEcho "Proofs len"
|
|
|
|
debugEcho proofs.len
|
|
|
|
debugEcho proofs[0].len
|
|
|
|
debugEcho proofs[0][0].len
|
|
|
|
|
|
|
|
for i in 0..<blobs.len:
|
2024-05-28 08:29:31 +00:00
|
|
|
let
|
2024-07-06 23:05:06 +00:00
|
|
|
cell_and_proof = computeCellsAndProofs(blobs[i])
|
2024-07-06 21:31:32 +00:00
|
|
|
debugEcho "Checkpoint 4"
|
2024-07-06 07:54:51 +00:00
|
|
|
if cell_and_proof.isErr():
|
2024-07-06 16:24:29 +00:00
|
|
|
return err("EIP7549: Could not compute cells")
|
2024-05-28 08:29:31 +00:00
|
|
|
|
2024-07-06 23:05:06 +00:00
|
|
|
cells[i] = cell_and_proof.get.cells
|
|
|
|
proofs[i] = cell_and_proof.get.proofs
|
2024-07-06 21:31:32 +00:00
|
|
|
|
|
|
|
debugEcho "Checkpoint 5"
|
2024-07-04 09:15:23 +00:00
|
|
|
|
2024-07-06 23:05:06 +00:00
|
|
|
|
|
|
|
let blobCount = blobs.len
|
|
|
|
debugEcho "BlobCount"
|
|
|
|
debugEcho blobCount
|
|
|
|
|
|
|
|
# for i in 0..<blobCount:
|
|
|
|
# for j in 0..<int(CELLS_PER_EXT_BLOB):
|
|
|
|
# for k in 0..<2048:
|
|
|
|
# cells[i][j][k] = (cellsAndProofs[i].cells[j][k])
|
|
|
|
|
|
|
|
# for i in 0..<blobCount:
|
|
|
|
# for j in 0..<int(CELLS_PER_EXT_BLOB):
|
|
|
|
# for k in 0..<48:
|
|
|
|
# proofs[i][j][k] = (cellsAndProofs[i].proofs[j][k])
|
2024-05-28 08:29:31 +00:00
|
|
|
|
2024-07-06 21:31:32 +00:00
|
|
|
debugEcho "Checkpoint 7"
|
|
|
|
|
2024-07-06 07:54:51 +00:00
|
|
|
for columnIndex in 0..<CELLS_PER_EXT_BLOB:
|
2024-05-28 08:29:31 +00:00
|
|
|
var column: DataColumn
|
2024-07-06 07:54:51 +00:00
|
|
|
var kzgProofOfColumn: KzgProofs
|
|
|
|
|
2024-05-28 08:29:31 +00:00
|
|
|
for rowIndex in 0..<blobCount:
|
2024-05-29 08:32:56 +00:00
|
|
|
column[rowIndex] = cells[rowIndex][columnIndex]
|
2024-07-06 07:54:51 +00:00
|
|
|
|
2024-05-28 08:29:31 +00:00
|
|
|
for rowIndex in 0..<blobCount:
|
2024-05-29 08:32:56 +00:00
|
|
|
kzgProofOfColumn[rowIndex] = proofs[rowIndex][columnIndex]
|
2024-05-28 08:29:31 +00:00
|
|
|
|
2024-07-05 10:26:03 +00:00
|
|
|
var sidecar = DataColumnSidecar(
|
2024-07-03 18:15:20 +00:00
|
|
|
index: ColumnIndex(columnIndex),
|
2024-05-28 08:29:31 +00:00
|
|
|
column: column,
|
|
|
|
kzgCommitments: blck.body.blob_kzg_commitments,
|
|
|
|
kzgProofs: kzgProofOfColumn,
|
2024-07-05 10:26:03 +00:00
|
|
|
signed_block_header: signed_beacon_block_header)
|
|
|
|
blck.body.build_proof(
|
2024-07-05 17:33:37 +00:00
|
|
|
27.GeneralizedIndex,
|
2024-07-05 10:45:38 +00:00
|
|
|
sidecar.kzg_commitments_inclusion_proof).expect("Valid gindex")
|
2024-07-04 09:15:23 +00:00
|
|
|
sidecars.add(sidecar)
|
2024-07-06 07:54:51 +00:00
|
|
|
ok(sidecars)
|
2024-05-28 08:29:31 +00:00
|
|
|
|
2024-05-29 08:32:56 +00:00
|
|
|
# Helper function to `verifyCellKzgProofBatch` at https://github.com/ethereum/c-kzg-4844/blob/das/bindings/nim/kzg_ex.nim#L170
|
|
|
|
proc validate_data_column_sidecar*(
|
2024-06-25 20:34:06 +00:00
|
|
|
expected_commitments: seq[KzgCommitment],
|
|
|
|
rowIndex: seq[RowIndex],
|
|
|
|
columnIndex: seq[ColumnIndex],
|
|
|
|
column: seq[Cell],
|
2024-05-29 08:32:56 +00:00
|
|
|
proofs: seq[KzgProof]): Result[void, string] =
|
|
|
|
let res = verifyCellKzgProofBatch(expected_commitments, rowIndex, columnIndex, column, proofs).valueOr:
|
|
|
|
return err("DataColumnSidecar: Proof verification error: " & error())
|
|
|
|
|
|
|
|
if not res:
|
|
|
|
return err("DataColumnSidecar: Proof verification failed")
|
|
|
|
|
|
|
|
ok()
|
2024-05-28 08:29:31 +00:00
|
|
|
|
2024-05-29 08:32:56 +00:00
|
|
|
# https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/p2p-interface.md#verify_data_column_sidecar_kzg_proofs
|
|
|
|
proc verify_data_column_sidecar_kzg_proofs*(sidecar: DataColumnSidecar): Result[void, string] =
|
2024-05-28 08:29:31 +00:00
|
|
|
# Verifying if the KZG proofs are correct
|
|
|
|
|
|
|
|
# Check if the data column sidecar index < NUMBER_OF_COLUMNS
|
|
|
|
if not (sidecar.index < NUMBER_OF_COLUMNS):
|
2024-05-29 08:32:56 +00:00
|
|
|
return err("EIP7594: Data column sidecar index exceeds the NUMBER_OF_COLUMNS")
|
2024-05-28 08:29:31 +00:00
|
|
|
|
|
|
|
# Check is the sidecar column length == sidecar.kzg_commitments length == sidecar.kzg_proofs mixInLength
|
2024-05-29 08:32:56 +00:00
|
|
|
if not (sidecar.column.len == sidecar.kzg_commitments.len):
|
|
|
|
return err("EIP7594: Data column sidecar length is not equal to the kzg_commitments length")
|
|
|
|
|
|
|
|
if not (sidecar.kzg_commitments.len == sidecar.kzg_proofs.len):
|
|
|
|
return err("EIP7594: Data column sidecar kzg_commitments length is not equal to the kzg_proofs length")
|
2024-05-28 08:29:31 +00:00
|
|
|
|
|
|
|
# Iterate through the row indices
|
2024-05-29 22:21:32 +00:00
|
|
|
var rowIndices: seq[RowIndex]
|
2024-05-28 08:29:31 +00:00
|
|
|
for i in 0..<sidecar.column.len:
|
|
|
|
rowIndices.add(RowIndex(i))
|
|
|
|
|
|
|
|
# Iterate through the column indices
|
2024-05-29 22:21:32 +00:00
|
|
|
var colIndices: seq[ColumnIndex]
|
|
|
|
for _ in 0..<sidecar.column.len:
|
|
|
|
colIndices.add(sidecar.index * sidecar.column.lenu64)
|
|
|
|
|
|
|
|
let
|
|
|
|
kzgCommits = sidecar.kzg_commitments.asSeq
|
|
|
|
sidecarCol = sidecar.column.asSeq
|
|
|
|
kzgProofs = sidecar.kzg_proofs.asSeq
|
2024-05-28 08:29:31 +00:00
|
|
|
|
2024-07-04 09:15:23 +00:00
|
|
|
let res = validate_data_column_sidecar(kzgCommits, rowIndices, colIndices, sidecarCol, kzgProofs)
|
2024-06-03 06:36:07 +00:00
|
|
|
|
2024-05-29 08:32:56 +00:00
|
|
|
if res.isErr():
|
|
|
|
return err("DataColumnSidecar: validation failed")
|
|
|
|
|
|
|
|
ok()
|
|
|
|
|
|
|
|
# https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/p2p-interface.md#verify_data_column_sidecar_inclusion_proof
|
2024-07-05 09:04:51 +00:00
|
|
|
func verify_data_column_sidecar_inclusion_proof*(sidecar: DataColumnSidecar): Result[void, string] =
|
2024-05-29 08:32:56 +00:00
|
|
|
# Verify if the given KZG commitments are included in the beacon block
|
2024-07-05 17:33:37 +00:00
|
|
|
let gindex = 27.GeneralizedIndex
|
2024-05-29 08:32:56 +00:00
|
|
|
if not is_valid_merkle_branch(
|
|
|
|
hash_tree_root(sidecar.kzg_commitments),
|
|
|
|
sidecar.kzg_commitments_inclusion_proof,
|
2024-07-05 11:46:20 +00:00
|
|
|
4.int,
|
2024-07-05 10:26:03 +00:00
|
|
|
get_subtree_index(gindex),
|
2024-05-29 08:32:56 +00:00
|
|
|
sidecar.signed_block_header.message.body_root):
|
|
|
|
|
|
|
|
return err("DataColumnSidecar: inclusion proof not valid")
|
|
|
|
|
2024-05-29 22:21:32 +00:00
|
|
|
ok()
|