Add `RowIndex`, `ColumnIndex` custom types in crypto doc
This commit is contained in:
parent
2cc7c8798d
commit
665e6faff7
|
@ -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 |
|
| `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 |
|
| `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` |
|
| `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
|
## Configuration
|
||||||
|
|
||||||
|
@ -68,11 +67,10 @@ We define the following Python custom types for type hinting and readability:
|
||||||
#### `get_custody_lines`
|
#### `get_custody_lines`
|
||||||
|
|
||||||
```python
|
```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
|
assert custody_size <= NUMBER_OF_COLUMNS
|
||||||
all_items = list(range(NUMBER_OF_COLUMNS))
|
column_index = node_id % NUMBER_OF_COLUMNS
|
||||||
line_index = node_id % NUMBER_OF_COLUMNS
|
return [ColumnIndex((column_index + i) % NUMBER_OF_COLUMNS) for i in range(custody_size)]
|
||||||
return [LineIndex(all_items[(line_index + i) % len(all_items)]) for i in range(custody_size)]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `compute_extended_data`
|
#### `compute_extended_data`
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
- [Configuration](#configuration)
|
- [Configuration](#configuration)
|
||||||
- [Containers](#containers)
|
- [Containers](#containers)
|
||||||
- [`DataColumnSidecar`](#datacolumnsidecar)
|
- [`DataColumnSidecar`](#datacolumnsidecar)
|
||||||
- [`DataColumnIdentifier`](#datacolumnidentifier)
|
- [`DataColumnIndexentifier`](#dataColumnIndexentifier)
|
||||||
- [Helpers](#helpers)
|
- [Helpers](#helpers)
|
||||||
- [`verify_data_column_sidecar_kzg_proof`](#verify_data_column_sidecar_kzg_proof)
|
- [`verify_data_column_sidecar_kzg_proof`](#verify_data_column_sidecar_kzg_proof)
|
||||||
- [`verify_data_column_sidecar_inclusion_proof`](#verify_data_column_sidecar_inclusion_proof)
|
- [`verify_data_column_sidecar_inclusion_proof`](#verify_data_column_sidecar_inclusion_proof)
|
||||||
|
@ -49,7 +49,7 @@
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class DataColumnSidecar(Container):
|
class DataColumnSidecar(Container):
|
||||||
index: LineIndex # Index of column in extended matrix
|
index: ColumnIndex # Index of column in extended matrix
|
||||||
column: DataColumn
|
column: DataColumn
|
||||||
kzg_commitments: List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK]
|
kzg_commitments: List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK]
|
||||||
kzg_proofs: List[KZGProof, 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]
|
kzg_commitments_inclusion_proof: Vector[Bytes32, KZG_COMMITMENTS_INCLUSION_PROOF_DEPTH]
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `DataColumnIdentifier`
|
#### `DataColumnIndexentifier`
|
||||||
|
|
||||||
```python
|
```python
|
||||||
class DataColumnIdentifier(Container):
|
class DataColumnIndexentifier(Container):
|
||||||
block_root: Root
|
block_root: Root
|
||||||
index: LineIndex
|
index: ColumnIndex
|
||||||
```
|
```
|
||||||
|
|
||||||
### Helpers
|
### Helpers
|
||||||
|
@ -74,14 +74,14 @@ def verify_data_column_sidecar_kzg_proof(sidecar: DataColumnSidecar) -> bool:
|
||||||
"""
|
"""
|
||||||
Verify if the proofs are correct
|
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)
|
assert len(sidecar.column) == len(sidecar.kzg_commitments) == len(sidecar.kzg_proofs)
|
||||||
|
|
||||||
# KZG batch verifies that the cells match the corresponding commitments and proofs
|
# KZG batch verifies that the cells match the corresponding commitments and proofs
|
||||||
return verify_cell_proof_batch(
|
return verify_cell_proof_batch(
|
||||||
row_commitments=sidecar.kzg_commitments,
|
row_commitments=sidecar.kzg_commitments,
|
||||||
row_ids=row_ids, # all rows
|
row_indices=row_ids, # all rows
|
||||||
column_ids=[sidecar.index],
|
column_indices=[sidecar.index],
|
||||||
datas=sidecar.column,
|
datas=sidecar.column,
|
||||||
proofs=sidecar.kzg_proofs,
|
proofs=sidecar.kzg_proofs,
|
||||||
)
|
)
|
||||||
|
@ -107,7 +107,7 @@ def verify_data_column_sidecar_inclusion_proof(sidecar: DataColumnSidecar) -> bo
|
||||||
##### `compute_subnet_for_data_column_sidecar`
|
##### `compute_subnet_for_data_column_sidecar`
|
||||||
|
|
||||||
```python
|
```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)
|
return SubnetID(column_index % DATA_COLUMN_SIDECAR_SUBNET_COUNT)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ Request Content:
|
||||||
|
|
||||||
```
|
```
|
||||||
(
|
(
|
||||||
DataColumnIdentifier
|
DataColumnIndexentifier
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -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 |
|
| `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 |
|
| `Cell` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The unit of blob data that can come with their own KZG proofs |
|
||||||
| `CellID` | `uint64` | Cell identifier |
|
| `CellID` | `uint64` | Cell identifier |
|
||||||
|
| `RowIndex` | `uint64` | Row identifier |
|
||||||
|
| `ColumnIndex` | `uint64` | Column identifier |
|
||||||
|
|
||||||
## Constants
|
## Constants
|
||||||
|
|
||||||
|
@ -415,8 +417,8 @@ def verify_cell_proof(commitment: KZGCommitment,
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment],
|
def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment],
|
||||||
row_ids: Sequence[int],
|
row_indices: Sequence[RowIndex],
|
||||||
column_ids: Sequence[int],
|
column_indices: Sequence[ColumnIndex],
|
||||||
cells: Sequence[Cell],
|
cells: Sequence[Cell],
|
||||||
proofs: Sequence[KZGProof]) -> bool:
|
proofs: Sequence[KZGProof]) -> bool:
|
||||||
"""
|
"""
|
||||||
|
@ -432,11 +434,11 @@ def verify_cell_proof_batch(row_commitments: Sequence[KZGCommitment],
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Get commitments via row IDs
|
# 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(
|
return all(
|
||||||
verify_kzg_proof_multi_impl(commitment, coset_for_cell(column_id), cell, proof)
|
verify_kzg_proof_multi_impl(commitment, coset_for_cell(column_index), cell, proof)
|
||||||
for commitment, column_id, cell, proof in zip(commitments, column_ids, cells, proofs)
|
for commitment, column_index, cell, proof in zip(commitments, column_indices, cells, proofs)
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,8 @@ def test_verify_cell_proof_batch(spec):
|
||||||
|
|
||||||
assert spec.verify_cell_proof_batch(
|
assert spec.verify_cell_proof_batch(
|
||||||
row_commitments=[commitment],
|
row_commitments=[commitment],
|
||||||
row_ids=[0],
|
row_indices=[0],
|
||||||
column_ids=[0, 1],
|
column_indices=[0, 1],
|
||||||
cells=cells[0:1],
|
cells=cells[0:1],
|
||||||
proofs=proofs,
|
proofs=proofs,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue