add: testing init for peerdas eip

This commit is contained in:
Agnish Ghosh 2024-06-13 16:19:15 +05:30
parent d8acc16918
commit 2615514909
No known key found for this signature in database
GPG Key ID: 7E927C221EBA4F6E
4 changed files with 70 additions and 16 deletions

View File

@ -9,7 +9,7 @@
import "."/[base, deneb], kzg4844 import "."/[base, deneb], kzg4844
export base, kzg4844 export base
const const
FIELD_ELEMENTS_PER_EXT_BLOB* = 2 * kzg_abi.FIELD_ELEMENTS_PER_BLOB FIELD_ELEMENTS_PER_EXT_BLOB* = 2 * kzg_abi.FIELD_ELEMENTS_PER_BLOB

View File

@ -14,6 +14,7 @@ import
ssz_serialization/proofs, ssz_serialization/proofs,
chronicles, chronicles,
./[beacon_time, crypto], ./[beacon_time, crypto],
kzg4844/kzg_ex,
eth/p2p/discoveryv5/[node], eth/p2p/discoveryv5/[node],
./helpers, ./helpers,
./datatypes/[eip7594, deneb] ./datatypes/[eip7594, deneb]
@ -67,14 +68,15 @@ proc get_custody_columns*(node_id: NodeId, custody_subnet_count: uint64): Result
proc compute_extended_matrix* (blobs: seq[KzgBlob]): Result[ExtendedMatrix, cstring] = proc compute_extended_matrix* (blobs: seq[KzgBlob]): Result[ExtendedMatrix, cstring] =
# This helper demonstrates the relationship between blobs and `ExtendedMatrix` # This helper demonstrates the relationship between blobs and `ExtendedMatrix`
var extended_matrix: ExtendedMatrix var extended_matrix: ExtendedMatrix
for blob in blobs: for i in 0..<blobs.len:
let res = computeCells(blob) debugEcho "Checkpoint 1"
let res = computeCells(blobs[i])
debugEcho "Checkpoint 2"
if res.isErr: if res.isErr:
return err("Error computing kzg cells and kzg proofs") return err("Error computing kzg cells and kzg proofs")
debugEcho "Checkpoint 3"
discard extended_matrix.add(res.get()) discard extended_matrix.add(res.get())
debugEcho "Checkpoint 4"
ok(extended_matrix) ok(extended_matrix)
# https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/das-core.md#recover_matrix # https://github.com/ethereum/consensus-specs/blob/5f48840f4d768bf0e0a8156a3ed06ec333589007/specs/_features/eip7594/das-core.md#recover_matrix
@ -117,7 +119,7 @@ proc get_data_column_sidecars*(signed_block: deneb.SignedBeaconBlock, blobs: seq
var signed_block_header: deneb.SignedBeaconBlockHeader var signed_block_header: deneb.SignedBeaconBlockHeader
var blck = signed_block.message var blck = signed_block.message
var cellsAndProofs: seq[KzgCellsAndKzgProofs] = @[] var cellsAndProofs: seq[KzgCellsAndKzgProofs]
for blob in blobs: for blob in blobs:
let let
@ -137,7 +139,7 @@ proc get_data_column_sidecars*(signed_block: deneb.SignedBeaconBlock, blobs: seq
cells[i].add(cellsAndProofs[i].cells[0]) cells[i].add(cellsAndProofs[i].cells[0])
proofs[i].add(cellsAndProofs[i].proofs[1]) proofs[i].add(cellsAndProofs[i].proofs[1])
var sidecars: seq[DataColumnSidecar] = @[] var sidecars: seq[DataColumnSidecar]
for columnIndex in 0..<NUMBER_OF_COLUMNS: for columnIndex in 0..<NUMBER_OF_COLUMNS:
var column: DataColumn var column: DataColumn
@ -206,14 +208,6 @@ proc verify_data_column_sidecar_kzg_proofs*(sidecar: DataColumnSidecar): Result[
let res = verifyCellKzgProofBatch(kzgCommits, rowIndices, colIndices, sidecarCol, kzgProofs) let res = verifyCellKzgProofBatch(kzgCommits, rowIndices, colIndices, sidecarCol, kzgProofs)
# # KZG batch verifies that the cells match the corresponding commitments and KZG proofs
# let res = validate_data_column_sidecar(
# kzgCommits,
# rowIndices,
# colIndices,
# sidecarCol,
# kzgProofs)
if res.isErr(): if res.isErr():
return err("DataColumnSidecar: validation failed") return err("DataColumnSidecar: validation failed")

View File

@ -26,6 +26,7 @@ import # Unit test
./test_datatypes, ./test_datatypes,
./test_deposit_snapshots, ./test_deposit_snapshots,
./test_discovery, ./test_discovery,
./test_eip7594_helpers,
./test_engine_authentication, ./test_engine_authentication,
./test_el_manager, ./test_el_manager,
./test_el_conf, ./test_el_conf,

View File

@ -0,0 +1,59 @@
# 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: [].}
{.used.}
# Uncategorized helper functions from the spec
import
unittest2,
random,
std/[algorithm, macros, tables, sysrand],
stew/results,
stint,
kzg4844/[kzg_abi, kzg_ex],
ssz_serialization/proofs,
chronicles,
../beacon_chain/spec/beacon_time,
eth/p2p/discoveryv5/[node],
./consensus_spec/[os_ops, fixtures_utils],
../beacon_chain/spec/[helpers, eip7594_helpers],
../beacon_chain/spec/datatypes/[eip7594, deneb]
from std/sequtils import anyIt, mapIt, toSeq
from std/strutils import rsplit
block:
template sourceDir: string = currentSourcePath.rsplit(DirSep, 1)[0]
doAssert Kzg.loadTrustedSetup(
sourceDir &
"/../vendor/nim-kzg4844/kzg4844/csources/src/trusted_setup.txt").isOk
const MAX_TOP_BYTE = 114
proc createSampleKzgBlobs(n: int): Result[seq[KzgBlob], cstring] =
var blob: KzgBlob
var blobs: seq[KzgBlob]
for i in 0..<n:
discard urandom(blob)
for i in 0..<blob.len:
if blob[i] > MAX_TOP_BYTE and i %% kzg_abi.BYTES_PER_FIELD_ELEMENT == 0:
blob[i] = MAX_TOP_BYTE
blobs.add(blob)
ok(blobs)
suite "EIP-7594 Unit Tests":
test "EIP-7594: Compute Extended Matrix":
proc testComputeExtendedMatrix() =
let blob_count = 2
let input_blobs = createSampleKzgBlobs(blob_count)
let extended_matrix = compute_extended_matrix(input_blobs.get)
doAssert extended_matrix.get.len == kzg_abi.CELLS_PER_EXT_BLOB * blob_count
testComputeExtendedMatrix()