Skip to content

Commit c161b9b

Browse files
committed
Implement compute_extended_matrix
1 parent c47d5f3 commit c161b9b

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

specs/_features/eip7594/das-core.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- [Helper functions](#helper-functions)
1919
- [`get_custody_columns`](#get_custody_columns)
2020
- [`compute_extended_data`](#compute_extended_data)
21+
- [`compute_extended_matrix`](#compute_extended_matrix)
2122
- [`recover_matrix`](#recover_matrix)
2223
- [`get_data_column_sidecars`](#get_data_column_sidecars)
2324
- [Custody](#custody)
@@ -112,13 +113,20 @@ def get_custody_columns(node_id: NodeID, custody_subnet_count: uint64) -> Sequen
112113
]
113114
```
114115

115-
#### `compute_extended_data`
116+
#### `compute_extended_matrix`
116117

117118
```python
118-
def compute_extended_data(data: Sequence[BLSFieldElement]) -> Sequence[BLSFieldElement]:
119-
# TODO
120-
# pylint: disable=unused-argument
121-
...
119+
def compute_extended_matrix(blobs: Sequence[Blob]) -> ExtendedMatrix:
120+
"""
121+
Return the full ``ExtendedMatrix``.
122+
123+
This helper demonstrates the relationship between blobs and ``ExtendedMatrix``.
124+
The data structure for storing cells is implementation-dependent.
125+
"""
126+
extended_matrix = []
127+
for blob in blobs:
128+
extended_matrix.extend(compute_cells(blob))
129+
return ExtendedMatrix(extended_matrix)
122130
```
123131

124132
#### `recover_matrix`
@@ -128,7 +136,7 @@ def recover_matrix(cells_dict: Dict[Tuple[BlobIndex, CellID], Cell], blob_count:
128136
"""
129137
Return the recovered ``ExtendedMatrix``.
130138
131-
This helper demonstrate how to apply ``recover_polynomial``.
139+
This helper demonstrates how to apply ``recover_polynomial``.
132140
The data structure for storing cells is implementation-dependent.
133141
"""
134142
extended_matrix = []
@@ -208,7 +216,7 @@ A node runs a background peer discovery process, maintaining at least `TARGET_NU
208216

209217
## Extended data
210218

211-
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.
219+
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`.
212220

213221
## Column gossip
214222

tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@
99
)
1010

1111

12+
@with_eip7594_and_later
13+
@spec_test
14+
@single_phase
15+
def test_compute_extended_matrix(spec):
16+
rng = random.Random(5566)
17+
18+
blob_count = 2
19+
input_blobs = [get_sample_blob(spec, rng=rng) for _ in range(blob_count)]
20+
extended_matrix = spec.compute_extended_matrix(input_blobs)
21+
assert len(extended_matrix) == spec.CELLS_PER_BLOB * blob_count
22+
23+
rows = [extended_matrix[i:(i + spec.CELLS_PER_BLOB)] for i in range(0, len(extended_matrix), spec.CELLS_PER_BLOB)]
24+
assert len(rows) == blob_count
25+
assert len(rows[0]) == spec.CELLS_PER_BLOB
26+
27+
for blob_index, row in enumerate(rows):
28+
extended_blob = []
29+
for cell in row:
30+
extended_blob.extend(cell)
31+
blob_part = extended_blob[0:len(extended_blob) // 2]
32+
blob = b''.join([spec.bls_field_to_bytes(x) for x in blob_part])
33+
assert blob == input_blobs[blob_index]
34+
35+
1236
@with_eip7594_and_later
1337
@spec_test
1438
@single_phase

0 commit comments

Comments
 (0)