Skip to content

Commit 7b7ada7

Browse files
authored
Merge pull request #3797 from jtraglia/rename-cellid-to-cellindex
Rename `CellID` to `CellIndex`
2 parents c5e9c3c + d137553 commit 7b7ada7

File tree

7 files changed

+205
-204
lines changed

7 files changed

+205
-204
lines changed

specs/_features/eip7594/das-core.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ def compute_extended_matrix(blobs: Sequence[Blob]) -> List[MatrixEntry, MAX_CELL
151151
extended_matrix = []
152152
for blob_index, blob in enumerate(blobs):
153153
cells, proofs = compute_cells_and_kzg_proofs(blob)
154-
for cell_id, (cell, proof) in enumerate(zip(cells, proofs)):
154+
for cell_index, (cell, proof) in enumerate(zip(cells, proofs)):
155155
extended_matrix.append(MatrixEntry(
156156
cell=cell,
157157
kzg_proof=proof,
158158
row_index=blob_index,
159-
column_index=cell_id,
159+
column_index=cell_index,
160160
))
161161
return extended_matrix
162162
```
@@ -174,17 +174,17 @@ def recover_matrix(partial_matrix: Sequence[MatrixEntry],
174174
"""
175175
extended_matrix = []
176176
for blob_index in range(blob_count):
177-
cell_ids = [e.column_index for e in partial_matrix if e.row_index == blob_index]
177+
cell_indices = [e.column_index for e in partial_matrix if e.row_index == blob_index]
178178
cells = [e.cell for e in partial_matrix if e.row_index == blob_index]
179179
proofs = [e.kzg_proof for e in partial_matrix if e.row_index == blob_index]
180180

181-
recovered_cells, recovered_proofs = recover_cells_and_kzg_proofs(cell_ids, cells, proofs)
182-
for cell_id, (cell, proof) in enumerate(zip(recovered_cells, recovered_proofs)):
181+
recovered_cells, recovered_proofs = recover_cells_and_kzg_proofs(cell_indices, cells, proofs)
182+
for cell_index, (cell, proof) in enumerate(zip(recovered_cells, recovered_proofs)):
183183
extended_matrix.append(MatrixEntry(
184184
cell=cell,
185185
kzg_proof=proof,
186186
row_index=blob_index,
187-
column_index=cell_id,
187+
column_index=cell_index,
188188
))
189189
return extended_matrix
190190
```

specs/_features/eip7594/polynomial-commitments-sampling.md

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ The following is a list of the public methods:
7979
| `Coset` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The evaluation domain of a cell |
8080
| `CosetEvals` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The internal representation of a cell (the evaluations over its Coset) |
8181
| `Cell` | `ByteVector[BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_CELL]` | The unit of blob data that can come with its own KZG proof |
82-
| `CellID` | `uint64` | Validation: `x < CELLS_PER_EXT_BLOB` |
82+
| `CellIndex` | `uint64` | Validation: `x < CELLS_PER_EXT_BLOB` |
8383

8484
## Constants
8585

@@ -414,15 +414,15 @@ def verify_kzg_proof_multi_impl(commitment: KZGCommitment,
414414
#### `coset_for_cell`
415415

416416
```python
417-
def coset_for_cell(cell_id: CellID) -> Coset:
417+
def coset_for_cell(cell_index: CellIndex) -> Coset:
418418
"""
419-
Get the coset for a given ``cell_id``
419+
Get the coset for a given ``cell_index``.
420420
"""
421-
assert cell_id < CELLS_PER_EXT_BLOB
421+
assert cell_index < CELLS_PER_EXT_BLOB
422422
roots_of_unity_brp = bit_reversal_permutation(
423423
compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB)
424424
)
425-
return Coset(roots_of_unity_brp[FIELD_ELEMENTS_PER_CELL * cell_id:FIELD_ELEMENTS_PER_CELL * (cell_id + 1)])
425+
return Coset(roots_of_unity_brp[FIELD_ELEMENTS_PER_CELL * cell_index:FIELD_ELEMENTS_PER_CELL * (cell_index + 1)])
426426
```
427427

428428
## Cells
@@ -451,7 +451,7 @@ def compute_cells_and_kzg_proofs(blob: Blob) -> Tuple[
451451
proofs = []
452452

453453
for i in range(CELLS_PER_EXT_BLOB):
454-
coset = coset_for_cell(CellID(i))
454+
coset = coset_for_cell(CellIndex(i))
455455
proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset)
456456
cells.append(coset_evals_to_cell(ys))
457457
proofs.append(proof)
@@ -477,9 +477,9 @@ def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_EXT_BLOB]:
477477
compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB))
478478
extended_data_rbo = bit_reversal_permutation(extended_data)
479479
cells = []
480-
for cell_id in range(CELLS_PER_EXT_BLOB):
481-
start = cell_id * FIELD_ELEMENTS_PER_CELL
482-
end = (cell_id + 1) * FIELD_ELEMENTS_PER_CELL
480+
for cell_index in range(CELLS_PER_EXT_BLOB):
481+
start = cell_index * FIELD_ELEMENTS_PER_CELL
482+
end = (cell_index + 1) * FIELD_ELEMENTS_PER_CELL
483483
cells.append(coset_evals_to_cell(CosetEvals(extended_data_rbo[start:end])))
484484
return cells
485485
```
@@ -490,7 +490,7 @@ def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_EXT_BLOB]:
490490

491491
```python
492492
def verify_cell_kzg_proof(commitment_bytes: Bytes48,
493-
cell_id: CellID,
493+
cell_index: CellIndex,
494494
cell: Cell,
495495
proof_bytes: Bytes48) -> bool:
496496
"""
@@ -499,11 +499,11 @@ def verify_cell_kzg_proof(commitment_bytes: Bytes48,
499499
Public method.
500500
"""
501501
assert len(commitment_bytes) == BYTES_PER_COMMITMENT
502-
assert cell_id < CELLS_PER_EXT_BLOB
502+
assert cell_index < CELLS_PER_EXT_BLOB
503503
assert len(cell) == BYTES_PER_CELL
504504
assert len(proof_bytes) == BYTES_PER_PROOF
505505

506-
coset = coset_for_cell(cell_id)
506+
coset = coset_for_cell(cell_index)
507507

508508
return verify_kzg_proof_multi_impl(
509509
bytes_to_kzg_commitment(commitment_bytes),
@@ -565,7 +565,7 @@ def verify_cell_kzg_proof_batch(row_commitments_bytes: Sequence[Bytes48],
565565
### `construct_vanishing_polynomial`
566566

567567
```python
568-
def construct_vanishing_polynomial(missing_cell_ids: Sequence[CellID]) -> Tuple[
568+
def construct_vanishing_polynomial(missing_cell_indices: Sequence[CellIndex]) -> Tuple[
569569
Sequence[BLSFieldElement],
570570
Sequence[BLSFieldElement]]:
571571
"""
@@ -577,8 +577,8 @@ def construct_vanishing_polynomial(missing_cell_ids: Sequence[CellID]) -> Tuple[
577577

578578
# Compute polynomial that vanishes at all the missing cells (over the small domain)
579579
short_zero_poly = vanishing_polynomialcoeff([
580-
roots_of_unity_reduced[reverse_bits(missing_cell_id, CELLS_PER_EXT_BLOB)]
581-
for missing_cell_id in missing_cell_ids
580+
roots_of_unity_reduced[reverse_bits(missing_cell_index, CELLS_PER_EXT_BLOB)]
581+
for missing_cell_index in missing_cell_indices
582582
])
583583

584584
# Extend vanishing polynomial to full domain using the closed form of the vanishing polynomial over a coset
@@ -592,12 +592,12 @@ def construct_vanishing_polynomial(missing_cell_ids: Sequence[CellID]) -> Tuple[
592592
zero_poly_eval_brp = bit_reversal_permutation(zero_poly_eval)
593593

594594
# Sanity check
595-
for cell_id in range(CELLS_PER_EXT_BLOB):
596-
start = cell_id * FIELD_ELEMENTS_PER_CELL
597-
end = (cell_id + 1) * FIELD_ELEMENTS_PER_CELL
598-
if cell_id in missing_cell_ids:
595+
for cell_index in range(CELLS_PER_EXT_BLOB):
596+
start = cell_index * FIELD_ELEMENTS_PER_CELL
597+
end = (cell_index + 1) * FIELD_ELEMENTS_PER_CELL
598+
if cell_index in missing_cell_indices:
599599
assert all(a == 0 for a in zero_poly_eval_brp[start:end])
600-
else: # cell_id in cell_ids
600+
else: # cell_index in cell_indices
601601
assert all(a != 0 for a in zero_poly_eval_brp[start:end])
602602

603603
return zero_poly_coeff, zero_poly_eval
@@ -606,7 +606,7 @@ def construct_vanishing_polynomial(missing_cell_ids: Sequence[CellID]) -> Tuple[
606606
### `recover_shifted_data`
607607

608608
```python
609-
def recover_shifted_data(cell_ids: Sequence[CellID],
609+
def recover_shifted_data(cell_indices: Sequence[CellIndex],
610610
cells: Sequence[Cell],
611611
zero_poly_eval: Sequence[BLSFieldElement],
612612
zero_poly_coeff: Sequence[BLSFieldElement],
@@ -621,9 +621,9 @@ def recover_shifted_data(cell_ids: Sequence[CellID],
621621
shift_inv = div(BLSFieldElement(1), shift_factor)
622622

623623
extended_evaluation_rbo = [0] * FIELD_ELEMENTS_PER_EXT_BLOB
624-
for cell_id, cell in zip(cell_ids, cells):
625-
start = cell_id * FIELD_ELEMENTS_PER_CELL
626-
end = (cell_id + 1) * FIELD_ELEMENTS_PER_CELL
624+
for cell_index, cell in zip(cell_indices, cells):
625+
start = cell_index * FIELD_ELEMENTS_PER_CELL
626+
end = (cell_index + 1) * FIELD_ELEMENTS_PER_CELL
627627
extended_evaluation_rbo[start:end] = cell
628628
extended_evaluation = bit_reversal_permutation(extended_evaluation_rbo)
629629

@@ -673,7 +673,7 @@ def recover_original_data(eval_shifted_extended_evaluation: Sequence[BLSFieldEle
673673
### `recover_cells_and_kzg_proofs`
674674

675675
```python
676-
def recover_cells_and_kzg_proofs(cell_ids: Sequence[CellID],
676+
def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex],
677677
cells: Sequence[Cell],
678678
proofs_bytes: Sequence[Bytes48]) -> Tuple[
679679
Vector[Cell, CELLS_PER_EXT_BLOB],
@@ -689,14 +689,14 @@ def recover_cells_and_kzg_proofs(cell_ids: Sequence[CellID],
689689
690690
Public method.
691691
"""
692-
assert len(cell_ids) == len(cells) == len(proofs_bytes)
692+
assert len(cell_indices) == len(cells) == len(proofs_bytes)
693693
# Check we have enough cells to be able to perform the reconstruction
694-
assert CELLS_PER_EXT_BLOB / 2 <= len(cell_ids) <= CELLS_PER_EXT_BLOB
694+
assert CELLS_PER_EXT_BLOB / 2 <= len(cell_indices) <= CELLS_PER_EXT_BLOB
695695
# Check for duplicates
696-
assert len(cell_ids) == len(set(cell_ids))
697-
# Check that the cell ids are within bounds
698-
for cell_id in cell_ids:
699-
assert cell_id < CELLS_PER_EXT_BLOB
696+
assert len(cell_indices) == len(set(cell_indices))
697+
# Check that the cell indices are within bounds
698+
for cell_index in cell_indices:
699+
assert cell_index < CELLS_PER_EXT_BLOB
700700
# Check that each cell is the correct length
701701
for cell in cells:
702702
assert len(cell) == BYTES_PER_CELL
@@ -710,11 +710,12 @@ def recover_cells_and_kzg_proofs(cell_ids: Sequence[CellID],
710710
# Convert cells to coset evals
711711
cosets_evals = [cell_to_coset_evals(cell) for cell in cells]
712712

713-
missing_cell_ids = [CellID(cell_id) for cell_id in range(CELLS_PER_EXT_BLOB) if cell_id not in cell_ids]
714-
zero_poly_coeff, zero_poly_eval = construct_vanishing_polynomial(missing_cell_ids)
713+
missing_cell_indices = [CellIndex(cell_index) for cell_index in range(CELLS_PER_EXT_BLOB)
714+
if cell_index not in cell_indices]
715+
zero_poly_coeff, zero_poly_eval = construct_vanishing_polynomial(missing_cell_indices)
715716

716717
eval_shifted_extended_evaluation, eval_shifted_zero_poly, shift_inv = recover_shifted_data(
717-
cell_ids,
718+
cell_indices,
718719
cosets_evals,
719720
zero_poly_eval,
720721
zero_poly_coeff,
@@ -728,9 +729,9 @@ def recover_cells_and_kzg_proofs(cell_ids: Sequence[CellID],
728729
roots_of_unity_extended,
729730
)
730731

731-
for cell_id, coset_evals in zip(cell_ids, cosets_evals):
732-
start = cell_id * FIELD_ELEMENTS_PER_CELL
733-
end = (cell_id + 1) * FIELD_ELEMENTS_PER_CELL
732+
for cell_index, coset_evals in zip(cell_indices, cosets_evals):
733+
start = cell_index * FIELD_ELEMENTS_PER_CELL
734+
end = (cell_index + 1) * FIELD_ELEMENTS_PER_CELL
734735
assert reconstructed_data[start:end] == coset_evals
735736

736737
recovered_cells = [
@@ -740,11 +741,11 @@ def recover_cells_and_kzg_proofs(cell_ids: Sequence[CellID],
740741
polynomial_eval = reconstructed_data[:FIELD_ELEMENTS_PER_BLOB]
741742
polynomial_coeff = polynomial_eval_to_coeff(polynomial_eval)
742743
recovered_proofs = [None] * CELLS_PER_EXT_BLOB
743-
for i, cell_id in enumerate(cell_ids):
744-
recovered_proofs[cell_id] = bytes_to_kzg_proof(proofs_bytes[i])
744+
for i, cell_index in enumerate(cell_indices):
745+
recovered_proofs[cell_index] = bytes_to_kzg_proof(proofs_bytes[i])
745746
for i in range(CELLS_PER_EXT_BLOB):
746747
if recovered_proofs[i] is None:
747-
coset = coset_for_cell(CellID(i))
748+
coset = coset_for_cell(CellIndex(i))
748749
proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset)
749750
assert coset_evals_to_cell(ys) == recovered_cells[i]
750751
recovered_proofs[i] = proof

tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def test_verify_cell_kzg_proof(spec):
3636
commitment = spec.blob_to_kzg_commitment(blob)
3737
cells, proofs = spec.compute_cells_and_kzg_proofs(blob)
3838

39-
cell_id = 0
40-
assert spec.verify_cell_kzg_proof(commitment, cell_id, cells[cell_id], proofs[cell_id])
41-
cell_id = 1
42-
assert spec.verify_cell_kzg_proof(commitment, cell_id, cells[cell_id], proofs[cell_id])
39+
cell_index = 0
40+
assert spec.verify_cell_kzg_proof(commitment, cell_index, cells[cell_index], proofs[cell_index])
41+
cell_index = 1
42+
assert spec.verify_cell_kzg_proof(commitment, cell_index, cells[cell_index], proofs[cell_index])
4343

4444

4545
@with_eip7594_and_later
@@ -77,19 +77,19 @@ def test_recover_cells_and_kzg_proofs(spec):
7777
cells, proofs = spec.compute_cells_and_kzg_proofs(blob)
7878

7979
# Compute the cells we will be recovering from
80-
cell_ids = []
80+
cell_indices = []
8181
# First figure out just the indices of the cells
8282
for i in range(N_SAMPLES):
8383
j = rng.randint(0, spec.CELLS_PER_EXT_BLOB - 1)
84-
while j in cell_ids:
84+
while j in cell_indices:
8585
j = rng.randint(0, spec.CELLS_PER_EXT_BLOB - 1)
86-
cell_ids.append(j)
86+
cell_indices.append(j)
8787
# Now the cells/proofs themselves
88-
known_cells = [cells[cell_id] for cell_id in cell_ids]
89-
known_proofs = [proofs[cell_id] for cell_id in cell_ids]
88+
known_cells = [cells[cell_index] for cell_index in cell_indices]
89+
known_proofs = [proofs[cell_index] for cell_index in cell_indices]
9090

9191
# Recover the missing cells and proofs
92-
recovered_cells, recovered_proofs = spec.recover_cells_and_kzg_proofs(cell_ids, known_cells, known_proofs)
92+
recovered_cells, recovered_proofs = spec.recover_cells_and_kzg_proofs(cell_indices, known_cells, known_proofs)
9393
recovered_data = [x for xs in recovered_cells for x in xs]
9494

9595
# Check that the original data match the non-extended portion of the recovered data

tests/formats/kzg_7594/recover_cells_and_kzg_proofs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ The test data is declared in a `data.yaml` file:
88

99
```yaml
1010
input:
11-
cell_ids: List[CellID] -- the cell identifier for each cell
11+
cell_indices: List[CellIndex] -- the cell indices
1212
cells: List[Cell] -- the partial collection of cells
1313
output: Tuple[List[Cell], List[KZGProof]] -- all cells and proofs
1414
```
1515
16-
- `CellID` is an unsigned 64-bit integer.
16+
- `CellIndex` is an unsigned 64-bit integer.
1717
- `Cell` is a 2048-byte hexadecimal string, prefixed with `0x`.
1818
- `KZGProof` is a 48-byte hexadecimal string, prefixed with `0x`.
1919

2020
All byte(s) fields are encoded as strings, hexadecimal encoding, prefixed with `0x`.
2121

2222
## Condition
2323

24-
The `recover_cells_and_kzg_proofs` handler should recover missing cells and proofs, and the result should match the expected `output`. If any cell is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element), any proof is invalid (e.g. not on the curve or not in the G1 subgroup of the BLS curve), or any `cell_id` is invalid (e.g. greater than the number of cells for an extended blob), it should error, i.e. the output should be `null`.
24+
The `recover_cells_and_kzg_proofs` handler should recover missing cells and proofs, and the result should match the expected `output`. If any cell is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element), any proof is invalid (e.g. not on the curve or not in the G1 subgroup of the BLS curve), or any `cell_index` is invalid (e.g. greater than the number of cells for an extended blob), it should error, i.e. the output should be `null`.

tests/formats/kzg_7594/verify_cell_kzg_proof.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ The test data is declared in a `data.yaml` file:
99
```yaml
1010
input:
1111
commitment: Bytes48 -- the KZG commitment
12-
cell_id: CellID -- the identifier for the cell
12+
cell_index: CellIndex -- the cell index
1313
cell: Cell -- the cell
1414
proof: Bytes48 -- the KZG proof for the cell
1515
output: bool -- true (correct proof) or false (incorrect proof)
1616
```
1717
1818
- `Bytes48` is a 48-byte hexadecimal string, prefixed with `0x`.
19-
- `CellID` is an unsigned 64-bit integer.
19+
- `CellIndex` is an unsigned 64-bit integer.
2020
- `Cell` is a 2048-byte hexadecimal string, prefixed with `0x`.
2121

2222
All byte(s) fields are encoded as strings, hexadecimal encoding, prefixed with `0x`.
2323

2424
## Condition
2525

26-
The `verify_cell_kzg_proof` handler should verify that `commitment` is a correct KZG commitment to `cell` by using the cell KZG proof `proof`, and the result should match the expected `output`. If the commitment or proof is invalid (e.g. not on the curve or not in the G1 subgroup of the BLS curve), `cell` is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element), or `cell_id` is invalid (e.g. greater than the number of cells for an extended blob), it should error, i.e. the output should be `null`.
26+
The `verify_cell_kzg_proof` handler should verify that `commitment` is a correct KZG commitment to `cell` by using the cell KZG proof `proof`, and the result should match the expected `output`. If the commitment or proof is invalid (e.g. not on the curve or not in the G1 subgroup of the BLS curve), `cell` is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element), or `cell_index` is invalid (e.g. greater than the number of cells for an extended blob), it should error, i.e. the output should be `null`.

tests/formats/kzg_7594/verify_cell_kzg_proof_batch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ All byte(s) fields are encoded as strings, hexadecimal encoding, prefixed with `
2525

2626
## Condition
2727

28-
The `verify_cell_kzg_proof_batch` handler should verify that `row_commitments` are correct KZG commitments to `cells` by using the cell KZG proofs `proofs`, and the result should match the expected `output`. If any of the commitments or proofs are invalid (e.g. not on the curve or not in the G1 subgroup of the BLS curve), any cell is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element), or any `cell_id` is invalid (e.g. greater than the number of cells for an extended blob), it should error, i.e. the output should be `null`.
28+
The `verify_cell_kzg_proof_batch` handler should verify that `row_commitments` are correct KZG commitments to `cells` by using the cell KZG proofs `proofs`, and the result should match the expected `output`. If any of the commitments or proofs are invalid (e.g. not on the curve or not in the G1 subgroup of the BLS curve), any cell is invalid (e.g. incorrect length or one of the 32-byte blocks does not represent a BLS field element), or any `cell_index` is invalid (e.g. greater than the number of cells for an extended blob), it should error, i.e. the output should be `null`.

0 commit comments

Comments
 (0)