diff --git a/specs/_features/eip7594/das-core.md b/specs/_features/eip7594/das-core.md index a1565f4f76..98b8a624f3 100644 --- a/specs/_features/eip7594/das-core.md +++ b/specs/_features/eip7594/das-core.md @@ -17,7 +17,7 @@ - [`DataColumnSidecar`](#datacolumnsidecar) - [Helper functions](#helper-functions) - [`get_custody_columns`](#get_custody_columns) - - [`compute_extended_data`](#compute_extended_data) + - [`compute_extended_matrix`](#compute_extended_matrix) - [`recover_matrix`](#recover_matrix) - [`get_data_column_sidecars`](#get_data_column_sidecars) - [Custody](#custody) @@ -112,13 +112,20 @@ def get_custody_columns(node_id: NodeID, custody_subnet_count: uint64) -> Sequen ] ``` -#### `compute_extended_data` +#### `compute_extended_matrix` ```python -def compute_extended_data(data: Sequence[BLSFieldElement]) -> Sequence[BLSFieldElement]: - # TODO - # pylint: disable=unused-argument - ... +def compute_extended_matrix(blobs: Sequence[Blob]) -> ExtendedMatrix: + """ + Return the full ``ExtendedMatrix``. + + This helper demonstrates the relationship between blobs and ``ExtendedMatrix``. + The data structure for storing cells is implementation-dependent. + """ + extended_matrix = [] + for blob in blobs: + extended_matrix.extend(compute_cells(blob)) + return ExtendedMatrix(extended_matrix) ``` #### `recover_matrix` @@ -128,7 +135,7 @@ def recover_matrix(cells_dict: Dict[Tuple[BlobIndex, CellID], Cell], blob_count: """ Return the recovered ``ExtendedMatrix``. - This helper demonstrate how to apply ``recover_polynomial``. + This helper demonstrates how to apply ``recover_polynomial``. The data structure for storing cells is implementation-dependent. """ extended_matrix = [] @@ -208,7 +215,7 @@ A node runs a background peer discovery process, maintaining at least `TARGET_NU ## Extended data -In this construction, we extend the blobs using a one-dimensional erasure coding extension. The matrix comprises maximum `MAX_BLOBS_PER_BLOCK` rows and fixed `NUMBER_OF_COLUMNS` columns, with each row containing a `Blob` and its corresponding extension. +In this construction, we extend the blobs using a one-dimensional erasure coding extension. The matrix comprises maximum `MAX_BLOBS_PER_BLOCK` rows and fixed `NUMBER_OF_COLUMNS` columns, with each row containing a `Blob` and its corresponding extension. `compute_extended_matrix` demonstrates the relationship between blobs and custom type `ExtendedMatrix`. ## Column gossip diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py index 15ed6536f8..24011fcdd7 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py @@ -9,6 +9,30 @@ ) +@with_eip7594_and_later +@spec_test +@single_phase +def test_compute_extended_matrix(spec): + rng = random.Random(5566) + + blob_count = 2 + input_blobs = [get_sample_blob(spec, rng=rng) for _ in range(blob_count)] + extended_matrix = spec.compute_extended_matrix(input_blobs) + assert len(extended_matrix) == spec.CELLS_PER_BLOB * blob_count + + rows = [extended_matrix[i:(i + spec.CELLS_PER_BLOB)] for i in range(0, len(extended_matrix), spec.CELLS_PER_BLOB)] + assert len(rows) == blob_count + assert len(rows[0]) == spec.CELLS_PER_BLOB + + for blob_index, row in enumerate(rows): + extended_blob = [] + for cell in row: + extended_blob.extend(cell) + blob_part = extended_blob[0:len(extended_blob) // 2] + blob = b''.join([spec.bls_field_to_bytes(x) for x in blob_part]) + assert blob == input_blobs[blob_index] + + @with_eip7594_and_later @spec_test @single_phase