Skip to content

Commit a3a6c91

Browse files
authored
Remove proof parameter from recover_cells_and_kzg_proofs (#3819)
1 parent 0a49572 commit a3a6c91

File tree

5 files changed

+35
-103
lines changed

5 files changed

+35
-103
lines changed

specs/_features/eip7594/das-core.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,8 @@ def recover_matrix(partial_matrix: Sequence[MatrixEntry],
179179
for blob_index in range(blob_count):
180180
cell_indices = [e.column_index for e in partial_matrix if e.row_index == blob_index]
181181
cells = [e.cell for e in partial_matrix if e.row_index == blob_index]
182-
proofs = [e.kzg_proof for e in partial_matrix if e.row_index == blob_index]
183182

184-
recovered_cells, recovered_proofs = recover_cells_and_kzg_proofs(cell_indices, cells, proofs)
183+
recovered_cells, recovered_proofs = recover_cells_and_kzg_proofs(cell_indices, cells)
185184
for cell_index, (cell, proof) in enumerate(zip(recovered_cells, recovered_proofs)):
186185
extended_matrix.append(MatrixEntry(
187186
cell=cell,

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,7 @@ def recover_data(cell_indices: Sequence[CellIndex],
645645

646646
```python
647647
def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex],
648-
cells: Sequence[Cell],
649-
proofs_bytes: Sequence[Bytes48]) -> Tuple[
648+
cells: Sequence[Cell]) -> Tuple[
650649
Vector[Cell, CELLS_PER_EXT_BLOB],
651650
Vector[KZGProof, CELLS_PER_EXT_BLOB]]:
652651
"""
@@ -660,7 +659,7 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex],
660659
661660
Public method.
662661
"""
663-
assert len(cell_indices) == len(cells) == len(proofs_bytes)
662+
assert len(cell_indices) == len(cells)
664663
# Check we have enough cells to be able to perform the reconstruction
665664
assert CELLS_PER_EXT_BLOB / 2 <= len(cell_indices) <= CELLS_PER_EXT_BLOB
666665
# Check for duplicates
@@ -671,9 +670,6 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex],
671670
# Check that each cell is the correct length
672671
for cell in cells:
673672
assert len(cell) == BYTES_PER_CELL
674-
# Check that each proof is the correct length
675-
for proof_bytes in proofs_bytes:
676-
assert len(proof_bytes) == BYTES_PER_PROOF
677673

678674
# Convert cells to coset evals
679675
cosets_evals = [cell_to_coset_evals(cell) for cell in cells]
@@ -692,14 +688,12 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex],
692688
polynomial_eval = reconstructed_data[:FIELD_ELEMENTS_PER_BLOB]
693689
polynomial_coeff = polynomial_eval_to_coeff(polynomial_eval)
694690
recovered_proofs = [None] * CELLS_PER_EXT_BLOB
695-
for i, cell_index in enumerate(cell_indices):
696-
recovered_proofs[cell_index] = bytes_to_kzg_proof(proofs_bytes[i])
691+
697692
for i in range(CELLS_PER_EXT_BLOB):
698-
if recovered_proofs[i] is None:
699-
coset = coset_for_cell(CellIndex(i))
700-
proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset)
701-
assert coset_evals_to_cell(ys) == recovered_cells[i]
702-
recovered_proofs[i] = proof
693+
coset = coset_for_cell(CellIndex(i))
694+
proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset)
695+
assert coset_evals_to_cell(ys) == recovered_cells[i]
696+
recovered_proofs[i] = proof
703697

704698
return recovered_cells, recovered_proofs
705699
```

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,11 @@ def test_recover_cells_and_kzg_proofs(spec):
164164
while j in cell_indices:
165165
j = rng.randint(0, spec.CELLS_PER_EXT_BLOB - 1)
166166
cell_indices.append(j)
167-
# Now the cells/proofs themselves
167+
# Now the cells themselves
168168
known_cells = [cells[cell_index] for cell_index in cell_indices]
169-
known_proofs = [proofs[cell_index] for cell_index in cell_indices]
170169

171170
# Recover the missing cells and proofs
172-
recovered_cells, recovered_proofs = spec.recover_cells_and_kzg_proofs(cell_indices, known_cells, known_proofs)
171+
recovered_cells, recovered_proofs = spec.recover_cells_and_kzg_proofs(cell_indices, known_cells)
173172
recovered_data = [x for xs in recovered_cells for x in xs]
174173

175174
# 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ All byte(s) fields are encoded as strings, hexadecimal encoding, prefixed with `
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_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`.
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), 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/generators/kzg_7594/main.py

Lines changed: 24 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from eth2spec.test.utils.kzg_tests import (
1414
CELL_RANDOM_VALID1,
1515
CELL_RANDOM_VALID2,
16-
G1,
1716
INVALID_BLOBS,
1817
INVALID_G1_POINTS,
1918
INVALID_INDIVIDUAL_CELL_BYTES,
@@ -593,15 +592,14 @@ def case_recover_cells_and_kzg_proofs():
593592
# Valid: No missing cells
594593
cells, proofs = VALID_CELLS_AND_PROOFS[0]
595594
cell_indices = list(range(spec.CELLS_PER_EXT_BLOB))
596-
recovered_cells, recovered_proofs = spec.recover_cells_and_kzg_proofs(cell_indices, cells, proofs)
595+
recovered_cells, recovered_proofs = spec.recover_cells_and_kzg_proofs(cell_indices, cells)
597596
assert recovered_cells == cells
598597
assert recovered_proofs == proofs
599-
identifier = make_id(cell_indices, cells, proofs)
598+
identifier = make_id(cell_indices, cells)
600599
yield f'recover_cells_and_kzg_proofs_case_valid_no_missing_{identifier}', {
601600
'input': {
602601
'cell_indices': cell_indices,
603602
'cells': encode_hex_list(cells),
604-
'proofs': encode_hex_list(proofs),
605603
},
606604
'output': (encode_hex_list(recovered_cells), encode_hex_list(recovered_proofs))
607605
}
@@ -610,16 +608,14 @@ def case_recover_cells_and_kzg_proofs():
610608
cells, proofs = VALID_CELLS_AND_PROOFS[1]
611609
cell_indices = list(range(0, spec.CELLS_PER_EXT_BLOB, 2))
612610
partial_cells = [cells[cell_index] for cell_index in cell_indices]
613-
partial_proofs = [proofs[cell_index] for cell_index in cell_indices]
614-
recovered_cells, recovered_proofs = spec.recover_cells_and_kzg_proofs(cell_indices, partial_cells, partial_proofs)
611+
recovered_cells, recovered_proofs = spec.recover_cells_and_kzg_proofs(cell_indices, partial_cells)
615612
assert recovered_cells == cells
616613
assert recovered_proofs == proofs
617-
identifier = make_id(cell_indices, partial_cells, partial_proofs)
614+
identifier = make_id(cell_indices, partial_cells)
618615
yield f'recover_cells_and_kzg_proofs_case_valid_half_missing_every_other_cell_{identifier}', {
619616
'input': {
620617
'cell_indices': cell_indices,
621618
'cells': encode_hex_list(partial_cells),
622-
'proofs': encode_hex_list(partial_proofs),
623619
},
624620
'output': (encode_hex_list(recovered_cells), encode_hex_list(recovered_proofs))
625621
}
@@ -628,16 +624,14 @@ def case_recover_cells_and_kzg_proofs():
628624
cells, proofs = VALID_CELLS_AND_PROOFS[2]
629625
cell_indices = list(range(0, spec.CELLS_PER_EXT_BLOB // 2))
630626
partial_cells = [cells[cell_index] for cell_index in cell_indices]
631-
partial_proofs = [proofs[cell_index] for cell_index in cell_indices]
632-
recovered_cells, recovered_proofs = spec.recover_cells_and_kzg_proofs(cell_indices, partial_cells, partial_proofs)
627+
recovered_cells, recovered_proofs = spec.recover_cells_and_kzg_proofs(cell_indices, partial_cells)
633628
assert recovered_cells == cells
634629
assert recovered_proofs == proofs
635630
identifier = make_id(cell_indices, partial_cells)
636631
yield f'recover_cells_and_kzg_proofs_case_valid_half_missing_first_half_{identifier}', {
637632
'input': {
638633
'cell_indices': cell_indices,
639634
'cells': encode_hex_list(partial_cells),
640-
'proofs': encode_hex_list(partial_proofs),
641635
},
642636
'output': (encode_hex_list(recovered_cells), encode_hex_list(recovered_proofs))
643637
}
@@ -646,16 +640,14 @@ def case_recover_cells_and_kzg_proofs():
646640
cells, proofs = VALID_CELLS_AND_PROOFS[3]
647641
cell_indices = list(range(spec.CELLS_PER_EXT_BLOB // 2, spec.CELLS_PER_EXT_BLOB))
648642
partial_cells = [cells[cell_index] for cell_index in cell_indices]
649-
partial_proofs = [proofs[cell_index] for cell_index in cell_indices]
650-
recovered_cells, recovered_proofs = spec.recover_cells_and_kzg_proofs(cell_indices, partial_cells, partial_proofs)
643+
recovered_cells, recovered_proofs = spec.recover_cells_and_kzg_proofs(cell_indices, partial_cells)
651644
assert recovered_cells == cells
652645
assert recovered_proofs == proofs
653646
identifier = make_id(cell_indices, partial_cells)
654647
yield f'recover_cells_and_kzg_proofs_case_valid_half_missing_second_half_{identifier}', {
655648
'input': {
656649
'cell_indices': cell_indices,
657650
'cells': encode_hex_list(partial_cells),
658-
'proofs': encode_hex_list(partial_proofs),
659651
},
660652
'output': (encode_hex_list(recovered_cells), encode_hex_list(recovered_proofs))
661653
}
@@ -668,95 +660,67 @@ def case_recover_cells_and_kzg_proofs():
668660
'input': {
669661
'cell_indices': cell_indices,
670662
'cells': encode_hex_list(partial_cells),
671-
'proofs': encode_hex_list(partial_proofs),
672663
},
673664
'output': None
674665
}
675666

676667
# Edge case: More than half missing
677-
cells, proofs = VALID_CELLS_AND_PROOFS[4]
668+
cells, _ = VALID_CELLS_AND_PROOFS[4]
678669
cell_indices = list(range(spec.CELLS_PER_EXT_BLOB // 2 - 1))
679670
partial_cells = [cells[cell_index] for cell_index in cell_indices]
680-
partial_proofs = [proofs[cell_index] for cell_index in cell_indices]
681-
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells, partial_proofs)
682-
identifier = make_id(cell_indices, partial_cells, partial_proofs)
671+
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells)
672+
identifier = make_id(cell_indices, partial_cells)
683673
yield f'recover_cells_and_kzg_proofs_case_invalid_more_than_half_missing_{identifier}', {
684674
'input': {
685675
'cell_indices': cell_indices,
686676
'cells': encode_hex_list(partial_cells),
687-
'proofs': encode_hex_list(partial_proofs),
688677
},
689678
'output': None
690679
}
691680

692681
# Edge case: More cells provided than CELLS_PER_EXT_BLOB
693-
cells, proofs = VALID_CELLS_AND_PROOFS[5]
682+
cells, _ = VALID_CELLS_AND_PROOFS[5]
694683
cell_indices = list(range(spec.CELLS_PER_EXT_BLOB)) + [0]
695684
partial_cells = [cells[cell_index] for cell_index in cell_indices]
696-
partial_proofs = [proofs[cell_index] for cell_index in cell_indices]
697-
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells, partial_proofs)
698-
identifier = make_id(cell_indices, partial_cells, partial_proofs)
685+
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells)
686+
identifier = make_id(cell_indices, partial_cells)
699687
yield f'recover_cells_and_kzg_proofs_case_invalid_more_cells_than_cells_per_ext_blob_{identifier}', {
700688
'input': {
701689
'cell_indices': cell_indices,
702690
'cells': encode_hex_list(partial_cells),
703-
'proofs': encode_hex_list(partial_proofs),
704691
},
705692
'output': None
706693
}
707694

708695
# Edge case: Invalid cell_index
709-
cells, proofs = VALID_CELLS_AND_PROOFS[6]
696+
cells, _ = VALID_CELLS_AND_PROOFS[6]
710697
cell_indices = list(range(spec.CELLS_PER_EXT_BLOB // 2))
711698
partial_cells = [cells[cell_index] for cell_index in cell_indices]
712-
partial_proofs = [proofs[cell_index] for cell_index in cell_indices]
713699
# Replace first cell_index with an invalid value
714700
cell_indices[0] = spec.CELLS_PER_EXT_BLOB
715-
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells, partial_proofs)
716-
identifier = make_id(cell_indices, partial_cells, partial_proofs)
701+
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells)
702+
identifier = make_id(cell_indices, partial_cells)
717703
yield f'recover_cells_and_kzg_proofs_case_invalid_cell_index_{identifier}', {
718704
'input': {
719705
'cell_indices': cell_indices,
720706
'cells': encode_hex_list(partial_cells),
721-
'proofs': encode_hex_list(partial_proofs),
722707
},
723708
'output': None
724709
}
725710

726711
# Edge case: Invalid cell
727712
for cell in INVALID_INDIVIDUAL_CELL_BYTES:
728-
cells, proofs = VALID_CELLS_AND_PROOFS[6]
713+
cells, _ = VALID_CELLS_AND_PROOFS[6]
729714
cell_indices = list(range(spec.CELLS_PER_EXT_BLOB // 2))
730715
partial_cells = [cells[cell_index] for cell_index in cell_indices]
731-
partial_proofs = [proofs[cell_index] for cell_index in cell_indices]
732716
# Replace first cell with an invalid value
733717
partial_cells[0] = cell
734-
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells, partial_proofs)
735-
identifier = make_id(cell_indices, partial_cells, partial_proofs)
718+
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells)
719+
identifier = make_id(cell_indices, partial_cells)
736720
yield f'recover_cells_and_kzg_proofs_case_invalid_cell_{identifier}', {
737721
'input': {
738722
'cell_indices': cell_indices,
739723
'cells': encode_hex_list(partial_cells),
740-
'proofs': encode_hex_list(partial_proofs),
741-
},
742-
'output': None
743-
}
744-
745-
# Edge case: Invalid proof
746-
for proof in INVALID_G1_POINTS:
747-
cells, proofs = VALID_CELLS_AND_PROOFS[0]
748-
cell_indices = list(range(spec.CELLS_PER_EXT_BLOB // 2))
749-
partial_cells = [cells[cell_index] for cell_index in cell_indices]
750-
partial_proofs = [proofs[cell_index] for cell_index in cell_indices]
751-
# Replace first proof with an invalid value
752-
partial_proofs[0] = proof
753-
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells, partial_proofs)
754-
identifier = make_id(cell_indices, partial_cells, partial_proofs)
755-
yield f'recover_cells_and_kzg_proofs_case_invalid_proof_{identifier}', {
756-
'input': {
757-
'cell_indices': cell_indices,
758-
'cells': encode_hex_list(partial_cells),
759-
'proofs': encode_hex_list(partial_proofs),
760724
},
761725
'output': None
762726
}
@@ -765,16 +729,14 @@ def case_recover_cells_and_kzg_proofs():
765729
cells, proofs = VALID_CELLS_AND_PROOFS[0]
766730
cell_indices = list(range(0, spec.CELLS_PER_EXT_BLOB, 2))
767731
partial_cells = [cells[cell_index] for cell_index in cell_indices]
768-
partial_proofs = [proofs[cell_index] for cell_index in cell_indices]
769732
# Add another cell_index
770733
cell_indices.append(spec.CELLS_PER_EXT_BLOB - 1)
771-
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells, partial_proofs)
772-
identifier = make_id(cell_indices, partial_cells, partial_proofs)
734+
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells)
735+
identifier = make_id(cell_indices, partial_cells)
773736
yield f'recover_cells_and_kzg_proofs_case_invalid_more_cell_indices_than_cells_{identifier}', {
774737
'input': {
775738
'cell_indices': cell_indices,
776739
'cells': encode_hex_list(partial_cells),
777-
'proofs': encode_hex_list(partial_proofs),
778740
},
779741
'output': None
780742
}
@@ -783,34 +745,14 @@ def case_recover_cells_and_kzg_proofs():
783745
cells, proofs = VALID_CELLS_AND_PROOFS[1]
784746
cell_indices = list(range(0, spec.CELLS_PER_EXT_BLOB, 2))
785747
partial_cells = [cells[cell_index] for cell_index in cell_indices]
786-
partial_proofs = [proofs[cell_index] for cell_index in cell_indices]
787748
# Add another cell
788749
partial_cells.append(CELL_RANDOM_VALID1)
789-
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells, partial_proofs)
790-
identifier = make_id(cell_indices, partial_cells, partial_proofs)
750+
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells)
751+
identifier = make_id(cell_indices, partial_cells)
791752
yield f'recover_cells_and_kzg_proofs_case_invalid_more_cells_than_cell_indices_{identifier}', {
792753
'input': {
793754
'cell_indices': cell_indices,
794755
'cells': encode_hex_list(partial_cells),
795-
'proofs': encode_hex_list(partial_proofs),
796-
},
797-
'output': None
798-
}
799-
800-
# Edge case: More proofs than cell_indices
801-
cells, proofs = VALID_CELLS_AND_PROOFS[1]
802-
cell_indices = list(range(0, spec.CELLS_PER_EXT_BLOB, 2))
803-
partial_cells = [cells[cell_index] for cell_index in cell_indices]
804-
partial_proofs = [proofs[cell_index] for cell_index in cell_indices]
805-
# Add another proof
806-
partial_proofs.append(G1)
807-
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells, partial_proofs)
808-
identifier = make_id(cell_indices, partial_cells, partial_proofs)
809-
yield f'recover_cells_and_kzg_proofs_case_invalid_more_proofs_than_cell_indices_{identifier}', {
810-
'input': {
811-
'cell_indices': cell_indices,
812-
'cells': encode_hex_list(partial_cells),
813-
'proofs': encode_hex_list(partial_proofs),
814756
},
815757
'output': None
816758
}
@@ -824,16 +766,14 @@ def case_recover_cells_and_kzg_proofs():
824766
# to insufficient cell count, not because of a duplicate cell.
825767
cell_indices = list(range(spec.CELLS_PER_EXT_BLOB // 2 + 1))
826768
partial_cells = [cells[cell_index] for cell_index in cell_indices]
827-
partial_proofs = [proofs[cell_index] for cell_index in cell_indices]
828769
# Replace first cell_index with the second cell_index
829770
cell_indices[0] = cell_indices[1]
830-
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells, partial_proofs)
831-
identifier = make_id(cell_indices, partial_cells, partial_proofs)
771+
expect_exception(spec.recover_cells_and_kzg_proofs, cell_indices, partial_cells)
772+
identifier = make_id(cell_indices, partial_cells)
832773
yield f'recover_cells_and_kzg_proofs_case_invalid_duplicate_cell_index_{identifier}', {
833774
'input': {
834775
'cell_indices': cell_indices,
835776
'cells': encode_hex_list(partial_cells),
836-
'proofs': encode_hex_list(partial_proofs),
837777
},
838778
'output': None
839779
}

0 commit comments

Comments
 (0)