3939 - [ ` coset_for_cell ` ] ( #coset_for_cell )
4040- [ Cells] ( #cells-1 )
4141 - [ Cell computation] ( #cell-computation )
42+ - [ ` compute_cells_and_kzg_proofs_polynomialcoeff ` ] ( #compute_cells_and_kzg_proofs_polynomialcoeff )
4243 - [ ` compute_cells_and_kzg_proofs ` ] ( #compute_cells_and_kzg_proofs )
4344 - [ Cell verification] ( #cell-verification )
4445 - [ ` verify_cell_kzg_proof_batch ` ] ( #verify_cell_kzg_proof_batch )
4546- [ Reconstruction] ( #reconstruction )
4647 - [ ` construct_vanishing_polynomial ` ] ( #construct_vanishing_polynomial )
47- - [ ` recover_data ` ] ( #recover_data )
48+ - [ ` recover_polynomialcoeff ` ] ( #recover_polynomialcoeff )
4849 - [ ` recover_cells_and_kzg_proofs ` ] ( #recover_cells_and_kzg_proofs )
4950
5051<!-- END doctoc generated TOC please keep comment here to allow auto update -->
@@ -555,6 +556,24 @@ def coset_for_cell(cell_index: CellIndex) -> Coset:
555556
556557### Cell computation
557558
559+ #### ` compute_cells_and_kzg_proofs_polynomialcoeff `
560+
561+ ``` python
562+ def compute_cells_and_kzg_proofs_polynomialcoeff (polynomial_coeff : PolynomialCoeff) -> Tuple[
563+ Vector[Cell, CELLS_PER_EXT_BLOB ],
564+ Vector[KZGProof, CELLS_PER_EXT_BLOB ]]:
565+ """
566+ Helper function which computes cells/proofs for a polynomial in coefficient form.
567+ """
568+ cells, proofs = [], []
569+ for i in range (CELLS_PER_EXT_BLOB ):
570+ coset = coset_for_cell(CellIndex(i))
571+ proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset)
572+ cells.append(coset_evals_to_cell(ys))
573+ proofs.append(proof)
574+ return cells, proofs
575+ ```
576+
558577#### ` compute_cells_and_kzg_proofs `
559578
560579``` python
@@ -572,17 +591,7 @@ def compute_cells_and_kzg_proofs(blob: Blob) -> Tuple[
572591
573592 polynomial = blob_to_polynomial(blob)
574593 polynomial_coeff = polynomial_eval_to_coeff(polynomial)
575-
576- cells = []
577- proofs = []
578-
579- for i in range (CELLS_PER_EXT_BLOB ):
580- coset = coset_for_cell(CellIndex(i))
581- proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset)
582- cells.append(coset_evals_to_cell(ys))
583- proofs.append(proof)
584-
585- return cells, proofs
594+ return compute_cells_and_kzg_proofs_polynomialcoeff(polynomial_coeff)
586595```
587596
588597### Cell verification
@@ -668,29 +677,27 @@ def construct_vanishing_polynomial(missing_cell_indices: Sequence[CellIndex]) ->
668677 return zero_poly_coeff
669678```
670679
671- ### ` recover_data `
680+ ### ` recover_polynomialcoeff `
672681
673682``` python
674- def recover_data (cell_indices : Sequence[CellIndex],
675- cells : Sequence[Cell],
676- ) -> Sequence[BLSFieldElement]:
683+ def recover_polynomialcoeff (cell_indices : Sequence[CellIndex],
684+ cells : Sequence[Cell]) -> Sequence[BLSFieldElement]:
677685 """
678- Recover the missing evaluations for the extended blob, given at least half of the evaluations .
686+ Recover the polynomial in coefficient form that when evaluated at the roots of unity will give the extended blob .
679687 """
680-
681- # Get the extended domain. This will be referred to as the FFT domain.
688+ # Get the extended domain. This will be referred to as the FFT domain
682689 roots_of_unity_extended = compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB )
683690
684- # Flatten the cells into evaluations.
685- # If a cell is missing, then its evaluation is zero.
691+ # Flatten the cells into evaluations
692+ # If a cell is missing, then its evaluation is zero
686693 extended_evaluation_rbo = [0 ] * FIELD_ELEMENTS_PER_EXT_BLOB
687694 for cell_index, cell in zip (cell_indices, cells):
688695 start = cell_index * FIELD_ELEMENTS_PER_CELL
689696 end = (cell_index + 1 ) * FIELD_ELEMENTS_PER_CELL
690697 extended_evaluation_rbo[start:end] = cell
691698 extended_evaluation = bit_reversal_permutation(extended_evaluation_rbo)
692699
693- # Compute Z(x) in monomial form
700+ # Compute Z(x) in coefficient form
694701 # Z(x) is the polynomial which vanishes on all of the evaluations which are missing
695702 missing_cell_indices = [CellIndex(cell_index) for cell_index in range (CELLS_PER_EXT_BLOB )
696703 if cell_index not in cell_indices]
@@ -703,7 +710,7 @@ def recover_data(cell_indices: Sequence[CellIndex],
703710 extended_evaluation_times_zero = [BLSFieldElement(int (a) * int (b) % BLS_MODULUS )
704711 for a, b in zip (zero_poly_eval, extended_evaluation)]
705712
706- # Convert (E*Z)(x) to monomial form
713+ # Convert (E*Z)(x) to coefficient form
707714 extended_evaluation_times_zero_coeffs = fft_field(extended_evaluation_times_zero, roots_of_unity_extended, inv = True )
708715
709716 # Convert (E*Z)(x) to evaluation form over a coset of the FFT domain
@@ -713,18 +720,12 @@ def recover_data(cell_indices: Sequence[CellIndex],
713720 zero_poly_over_coset = coset_fft_field(zero_poly_coeff, roots_of_unity_extended)
714721
715722 # Compute Q_3(x) = (E*Z)(x) / Z(x) in evaluation form over a coset of the FFT domain
716- reconstructed_poly_over_coset = [
717- div(a, b)
718- for a, b in zip (extended_evaluations_over_coset, zero_poly_over_coset)
719- ]
723+ reconstructed_poly_over_coset = [div(a, b) for a, b in zip (extended_evaluations_over_coset, zero_poly_over_coset)]
720724
721- # Convert Q_3(x) to monomial form
725+ # Convert Q_3(x) to coefficient form
722726 reconstructed_poly_coeff = coset_fft_field(reconstructed_poly_over_coset, roots_of_unity_extended, inv = True )
723727
724- # Convert Q_3(x) to evaluation form over the FFT domain and bit reverse the result
725- reconstructed_data = bit_reversal_permutation(fft_field(reconstructed_poly_coeff, roots_of_unity_extended))
726-
727- return reconstructed_data
728+ return reconstructed_poly_coeff[:FIELD_ELEMENTS_PER_BLOB ]
728729```
729730
730731### ` recover_cells_and_kzg_proofs `
@@ -735,7 +736,7 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex],
735736 Vector[Cell, CELLS_PER_EXT_BLOB ],
736737 Vector[KZGProof, CELLS_PER_EXT_BLOB ]]:
737738 """
738- Given at least 50% of cells/proofs for a blob, recover all the cells/proofs.
739+ Given at least 50% of cells for a blob, recover all the cells/proofs.
739740 This algorithm uses FFTs to recover cells faster than using Lagrange
740741 implementation, as can be seen here:
741742 https://ethresear.ch/t/reed-solomon-erasure-code-recovery-in-n-log-2-n-time-with-ffts/3039
@@ -745,6 +746,7 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex],
745746
746747 Public method.
747748 """
749+ # Check we have the same number of cells and indices
748750 assert len (cell_indices) == len (cells)
749751 # Check we have enough cells to be able to perform the reconstruction
750752 assert CELLS_PER_EXT_BLOB / 2 <= len (cell_indices) <= CELLS_PER_EXT_BLOB
@@ -757,29 +759,12 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex],
757759 for cell in cells:
758760 assert len (cell) == BYTES_PER_CELL
759761
760- # Convert cells to coset evals
762+ # Convert cells to coset evaluations
761763 cosets_evals = [cell_to_coset_evals(cell) for cell in cells]
762764
763- reconstructed_data = recover_data(cell_indices, cosets_evals)
764-
765- for cell_index, coset_evals in zip (cell_indices, cosets_evals):
766- start = cell_index * FIELD_ELEMENTS_PER_CELL
767- end = (cell_index + 1 ) * FIELD_ELEMENTS_PER_CELL
768- assert reconstructed_data[start:end] == coset_evals
769-
770- recovered_cells = [
771- coset_evals_to_cell(reconstructed_data[i * FIELD_ELEMENTS_PER_CELL :(i + 1 ) * FIELD_ELEMENTS_PER_CELL ])
772- for i in range (CELLS_PER_EXT_BLOB )]
773-
774- polynomial_eval = reconstructed_data[:FIELD_ELEMENTS_PER_BLOB ]
775- polynomial_coeff = polynomial_eval_to_coeff(polynomial_eval)
776- recovered_proofs = [None ] * CELLS_PER_EXT_BLOB
777-
778- for i in range (CELLS_PER_EXT_BLOB ):
779- coset = coset_for_cell(CellIndex(i))
780- proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset)
781- assert coset_evals_to_cell(ys) == recovered_cells[i]
782- recovered_proofs[i] = proof
783-
784- return recovered_cells, recovered_proofs
765+ # Given the coset evaluations, recover the polynomial in coefficient form
766+ polynomial_coeff = recover_polynomialcoeff(cell_indices, cosets_evals)
767+
768+ # Recompute all cells/proofs
769+ return compute_cells_and_kzg_proofs_polynomialcoeff(polynomial_coeff)
785770```
0 commit comments