Skip to content

Commit c368721

Browse files
committed
Add support for shuffled inputs to recover_cells_and_kzg_proofs
1 parent cbaa006 commit c368721

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

specs/fulu/polynomial-commitments-sampling.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,16 @@ def recover_cells_and_kzg_proofs(
808808
for cell in cells:
809809
assert len(cell) == BYTES_PER_CELL
810810

811+
# Sort cell indices and cells together to ensure proper order
812+
sorted_pairs = sorted(zip(cell_indices, cells), key=lambda x: x[0])
813+
sorted_cell_indices = [pair[0] for pair in sorted_pairs]
814+
sorted_cells = [pair[1] for pair in sorted_pairs]
815+
811816
# Convert cells to coset evaluations
812-
cosets_evals = [cell_to_coset_evals(cell) for cell in cells]
817+
cosets_evals = [cell_to_coset_evals(cell) for cell in sorted_cells]
813818

814819
# Given the coset evaluations, recover the polynomial in coefficient form
815-
polynomial_coeff = recover_polynomialcoeff(cell_indices, cosets_evals)
820+
polynomial_coeff = recover_polynomialcoeff(sorted_cell_indices, cosets_evals)
816821

817822
# Recompute all cells/proofs
818823
return compute_cells_and_kzg_proofs_polynomialcoeff(polynomial_coeff)

tests/generators/runners/kzg_7594.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
KZG test vectors generator for EIP-7594
33
"""
44

5+
import random
56
from collections.abc import Iterable
67
from functools import cache
78

@@ -494,6 +495,38 @@ def get_inputs():
494495
get_test_runner(get_inputs),
495496
)
496497

498+
# Valid: Shuffled indices, no missing cells
499+
if True:
500+
501+
def get_inputs():
502+
cells, _ = cached_compute_cells_and_kzg_proofs(VALID_BLOBS[4])
503+
cell_indices = list(range(spec.CELLS_PER_EXT_BLOB))
504+
random.seed(42) # Use fixed seed for reproducibility
505+
random.shuffle(cell_indices)
506+
partial_cells = [cells[cell_index] for cell_index in cell_indices]
507+
return cell_indices, partial_cells
508+
509+
yield (
510+
"recover_cells_and_kzg_proofs_case_valid_shuffled_no_missing",
511+
get_test_runner(get_inputs),
512+
)
513+
514+
# Valid: Shuffled indices, one missing
515+
if True:
516+
517+
def get_inputs():
518+
cells, _ = cached_compute_cells_and_kzg_proofs(VALID_BLOBS[5])
519+
cell_indices = list(range(spec.CELLS_PER_EXT_BLOB - 1))
520+
random.seed(42) # Use fixed seed for reproducibility
521+
random.shuffle(cell_indices)
522+
partial_cells = [cells[cell_index] for cell_index in cell_indices]
523+
return cell_indices, partial_cells
524+
525+
yield (
526+
"recover_cells_and_kzg_proofs_case_valid_shuffled_one_missing",
527+
get_test_runner(get_inputs),
528+
)
529+
497530
# Edge case: All cells are missing
498531
if True:
499532

0 commit comments

Comments
 (0)