# beacon_chain # Copyright (c) 2018-2025 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 std/[algorithm, sequtils], results, eth/p2p/discoveryv5/[node], kzg4844/[kzg], ssz_serialization/[ proofs, types], ./crypto, ./[helpers, digest], ./datatypes/[fulu] type CellBytes = array[fulu.CELLS_PER_EXT_BLOB, Cell] ProofBytes = array[fulu.CELLS_PER_EXT_BLOB, KzgProof] # https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.10/specs/fulu/das-core.md#compute_columns_for_custody_group iterator compute_columns_for_custody_group(custody_group: CustodyIndex): ColumnIndex = for i in 0'u64 ..< COLUMNS_PER_GROUP: yield ColumnIndex(NUMBER_OF_CUSTODY_GROUPS * i + custody_group) func handle_custody_groups(node_id: NodeId, custody_group_count: CustodyIndex): HashSet[CustodyIndex] = # Decouples the custody group computation from # `get_custody_groups`, in order to later use this custody # group list across various types of output types var custody_groups: HashSet[CustodyIndex] current_id = node_id while custody_groups.lenu64 < custody_group_count: var hashed_bytes: array[8, byte] let current_id_bytes = current_id.toBytesLE() hashed_current_id = eth2digest(current_id_bytes) hashed_bytes[0..7] = hashed_current_id.data.toOpenArray(0,7) let custody_group = bytes_to_uint64(hashed_bytes) mod NUMBER_OF_CUSTODY_GROUPS custody_groups.incl custody_group inc current_id custody_groups # https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.10/specs/fulu/das-core.md#get_custody_groups func get_custody_groups*(node_id: NodeId, custody_group_count: CustodyIndex): seq[CustodyIndex] = let custody_groups = node_id.handle_custody_groups(custody_group_count) var groups = custody_groups.toSeq() groups.sort() groups func resolve_columns_from_custody_groups*(node_id: NodeId, custody_group_count: CustodyIndex): seq[ColumnIndex] = let custody_groups = node_id.get_custody_groups(custody_group_count) var flattened = newSeqOfCap[ColumnIndex](COLUMNS_PER_GROUP * custody_groups.len) for group in custody_groups: for index in compute_columns_for_custody_group(group): flattened.add index flattened func resolve_column_sets_from_custody_groups*(node_id: NodeId, custody_group_count: CustodyIndex): HashSet[ColumnIndex] = node_id.resolve_columns_from_custody_groups(custody_group_count).toHashSet() # https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.10/specs/fulu/das-core.md#compute_matrix proc compute_matrix*(blobs: seq[KzgBlob]): Result[seq[MatrixEntry], cstring] = ## `compute_matrix` helper demonstrates the relationship ## between blobs and the `MatrixEntries` var extended_matrix: seq[MatrixEntry] for blbIdx, blob in blobs.pairs: let cellsAndProofs = computeCellsAndKzgProofs(blob) if cellsAndProofs.isErr: return err("Computing Extended Matrix: Issue computing cells and proofs") for i in 0..