Add `RowIndex`, `ColumnIndex` custom types in crypto doc

This commit is contained in:
Hsiao-Wei Wang 2024-01-19 18:51:36 +08:00
parent 2cc7c8798d
commit 665e6faff7
No known key found for this signature in database
GPG Key ID: AE3D6B174F971DE4
4 changed files with 22 additions and 22 deletions

View File

@ -45,7 +45,6 @@ We define the following Python custom types for type hinting and readability:
| `DataColumn` | `List[Cell, MAX_BLOBS_PER_BLOCK]` | The data of each column in EIP7594 |
| `ExtendedMatrix` | `List[Cell, MAX_BLOBS_PER_BLOCK * NUMBER_OF_COLUMNS]` | The full data with blobs and one-dimensional erasure coding extension |
| `FlatExtendedMatrix` | `List[BLSFieldElement, MAX_BLOBS_PER_BLOCK * FIELD_ELEMENTS_PER_BLOB * NUMBER_OF_COLUMNS]` | The flattened format of `ExtendedMatrix` |
| `LineIndex` | `uint64` | The index of the rows or columns in `FlatExtendedMatrix` matrix |
## Configuration
@ -68,11 +67,10 @@ We define the following Python custom types for type hinting and readability:
#### `get_custody_lines`
```python
def get_custody_lines(node_id: NodeID, custody_size: uint64) -> Sequence[LineIndex]:
def get_custody_lines(node_id: NodeID, custody_size: uint64) -> Sequence[ColumnIndex]:
assert custody_size <= NUMBER_OF_COLUMNS
all_items = list(range(NUMBER_OF_COLUMNS))
line_index = node_id % NUMBER_OF_COLUMNS
return [LineIndex(all_items[(line_index + i) % len(all_items)]) for i in range(custody_size)]
column_index = node_id % NUMBER_OF_COLUMNS
return [ColumnIndex((column_index + i) % NUMBER_OF_COLUMNS) for i in range(custody_size)]
```
#### `compute_extended_data`

View File

@ -13,7 +13,7 @@
- [Configuration](#configuration)
- [Containers](#containers)
- [`DataColumnSidecar`](#datacolumnsidecar)
- [`DataColumnIdentifier`](#datacolumnidentifier)
- [`DataColumnIndexentifier`](#dataColumnIndexentifier)
- [Helpers](#helpers)
- [`verify_data_column_sidecar_kzg_proof`](#verify_data_column_sidecar_kzg_proof)
- [`verify_data_column_sidecar_inclusion_proof`](#verify_data_column_sidecar_inclusion_proof)
@ -49,7 +49,7 @@
```python
class DataColumnSidecar(Container):
index: LineIndex # Index of column in extended matrix
index: ColumnIndex # Index of column in extended matrix
column: DataColumn
kzg_commitments: List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK]
kzg_proofs: List[KZGProof, MAX_BLOB_COMMITMENTS_PER_BLOCK]
@ -57,12 +57,12 @@ class DataColumnSidecar(Container):
kzg_commitments_inclusion_proof: Vector[Bytes32, KZG_COMMITMENTS_INCLUSION_PROOF_DEPTH]
```
#### `DataColumnIdentifier`
#### `DataColumnIndexentifier`
```python
class DataColumnIdentifier(Container):
class DataColumnIndexentifier(Container):
block_root: Root
index: LineIndex
index: ColumnIndex
```
### Helpers
@ -74,14 +74,14 @@ def verify_data_column_sidecar_kzg_proof(sidecar: DataColumnSidecar) -> bool:
"""
Verify if the proofs are correct
"""
row_ids = [LineIndex(i) for i in range(len(sidecar.column))]
row_ids = [RowIndex(i) for i in range(len(sidecar.column))]
assert len(sidecar.column) == len(sidecar.kzg_commitments) == len(sidecar.kzg_proofs)
# KZG batch verifies that the cells match the corresponding commitments and proofs
return verify_cell_proof_batch(
row_commitments=sidecar.kzg_commitments,
row_ids=row_ids, # all rows
column_ids=[sidecar.index],
row_indices=row_ids, # all rows
column_indices=[sidecar.index],
datas=sidecar.column,
proofs=sidecar.kzg_proofs,
)
@ -107,7 +107,7 @@ def verify_data_column_sidecar_inclusion_proof(sidecar: DataColumnSidecar) -> bo
##### `compute_subnet_for_data_column_sidecar`
```python
def compute_subnet_for_data_column_sidecar(column_index: LineIndex) -> SubnetID:
def compute_subnet_for_data_column_sidecar(column_index: ColumnIndex) -> SubnetID:
return SubnetID(column_index % DATA_COLUMN_SIDECAR_SUBNET_COUNT)
```
@ -167,7 +167,7 @@ Request Content:
```
(
DataColumnIdentifier
DataColumnIndexentifier
)
```

View File

@ -60,6 +60,8 @@ Public functions MUST accept raw bytes as input and perform the required cryptog
| `PolynomialCoeff` | `List[BLSFieldElement, 2 * FIELD_ELEMENTS_PER_BLOB]` | A polynomial in coefficient form |
| `Cell` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The unit of blob data that can come with their own KZG proofs |
| `CellID` | `uint64` | Cell identifier |
| `RowIndex` | `uint64` | Row identifier |
| `ColumnIndex` | `uint64` | Column identifier |
## Constants
@ -415,8 +417,8 @@ def verify_cell_proof(commitment: KZGCommitment,
```python
def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment],
row_ids: Sequence[int],
column_ids: Sequence[int],
row_indices: Sequence[RowIndex],
column_indices: Sequence[ColumnIndex],
cells: Sequence[Cell],
proofs: Sequence[KZGProof]) -> bool:
"""
@ -432,11 +434,11 @@ def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment],
"""
# Get commitments via row IDs
commitments = [row_commitments[row_id] for row_id in row_ids]
commitments = [row_commitments[row_index] for row_index in row_indices]
return all(
verify_kzg_proof_multi_impl(commitment, coset_for_cell(column_id), cell, proof)
for commitment, column_id, cell, proof in zip(commitments, column_ids, cells, proofs)
verify_kzg_proof_multi_impl(commitment, coset_for_cell(column_index), cell, proof)
for commitment, column_index, cell, proof in zip(commitments, column_indices, cells, proofs)
)
```

View File

@ -50,8 +50,8 @@ def test_verify_cell_proof_batch(spec):
assert spec.verify_cell_proof_batch(
row_commitments=[commitment],
row_ids=[0],
column_ids=[0, 1],
row_indices=[0],
column_indices=[0, 1],
cells=cells[0:1],
proofs=proofs,
)