diff --git a/AllTests-mainnet.md b/AllTests-mainnet.md index 9c5a3c14c..7047850f6 100644 --- a/AllTests-mainnet.md +++ b/AllTests-mainnet.md @@ -536,6 +536,11 @@ OK: 5/5 Fail: 0/5 Skip: 0/5 + EIP7594: Extended Sample Count OK ``` OK: 1/1 Fail: 0/1 Skip: 0/1 +## EIP-7594 Unit Tests +```diff ++ EIP-7594: Compute Matrix OK +``` +OK: 1/1 Fail: 0/1 Skip: 0/1 ## EL Configuration ```diff + Empty config file OK @@ -1119,4 +1124,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2 OK: 9/9 Fail: 0/9 Skip: 0/9 ---TOTAL--- -OK: 760/765 Fail: 0/765 Skip: 5/765 +OK: 761/766 Fail: 0/766 Skip: 5/766 diff --git a/beacon_chain/spec/eip7594_helpers.nim b/beacon_chain/spec/eip7594_helpers.nim index 1eb205188..dc9213ec5 100644 --- a/beacon_chain/spec/eip7594_helpers.nim +++ b/beacon_chain/spec/eip7594_helpers.nim @@ -99,6 +99,27 @@ func get_custody_column_list*(node_id: NodeId, sortedColumnIndexList(ColumnIndex(columns_per_subnet), subnet_ids) +# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.5/specs/_features/eip7594/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 not cellsAndProofs.isOk: + return err("Computing Extended Matrix: Issue computing cells and proofs") + + for i in 0.. MAX_TOP_BYTE and + byteIndex mod kzg_abi.BYTES_PER_FIELD_ELEMENT == 0: + blob[byteIndex] = MAX_TOP_BYTE + blobs.add(KzgBlob(bytes: blob)) + blobs + +iterator chunks[T](lst: seq[T], n: int): seq[T] = + ## Iterator that yields N-sized chunks from the list. + for i in countup(0, len(lst) - 1, n): + yield lst[i..min(i + n - 1, len(lst) - 1)] + +suite "EIP-7594 Unit Tests": + test "EIP-7594: Compute Matrix": + proc testComputeExtendedMatrix() = + var + rng = initRand(126) + blob_count = rng.rand(1..(deneb.MAX_BLOB_COMMITMENTS_PER_BLOCK.int)) + let + input_blobs = createSampleKzgBlobs(blob_count, rng.rand(int)) + extended_matrix = compute_matrix(input_blobs) + doAssert extended_matrix.get.len == kzg_abi.CELLS_PER_EXT_BLOB * blob_count + for row in chunks(extended_matrix.get, kzg_abi.CELLS_PER_EXT_BLOB): + doAssert len(row) == kzg_abi.CELLS_PER_EXT_BLOB + testComputeExtendedMatrix() suite "EIP-7594 Sampling Tests": test "EIP7594: Extended Sample Count": @@ -43,4 +97,6 @@ suite "EIP-7594 Sampling Tests": for (allowed_failures, extendedSampleCount) in tests: check: get_extended_sample_count( samplesPerSlot, allowed_failures) == extendedSampleCount - testExtendedSampleCount() \ No newline at end of file + testExtendedSampleCount() + +doAssert freeTrustedSetup().isOk \ No newline at end of file