Skip to content

Commit

Permalink
Implement compute_extended_matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
hwwhww committed Feb 1, 2024
1 parent c47d5f3 commit 91dbbb3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
23 changes: 15 additions & 8 deletions specs/_features/eip7594/das-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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`
Expand All @@ -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 = []
Expand Down Expand Up @@ -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

Expand Down
24 changes: 24 additions & 0 deletions tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 91dbbb3

Please sign in to comment.