From 4907658a6f587df5eb4b32988e70875ca307f00a Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 26 Jun 2024 20:18:02 +0100 Subject: [PATCH 1/8] chore: remove recover_data --- .../polynomial-commitments-sampling.md | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 7be1a4a059..5127178570 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -44,7 +44,7 @@ - [`verify_cell_kzg_proof_batch`](#verify_cell_kzg_proof_batch) - [Reconstruction](#reconstruction) - [`construct_vanishing_polynomial`](#construct_vanishing_polynomial) - - [`recover_data`](#recover_data) + - [`recover_polynomial_coeff`](#recover_polynomial_coeff) - [`recover_cells_and_kzg_proofs`](#recover_cells_and_kzg_proofs) @@ -582,14 +582,14 @@ def construct_vanishing_polynomial(missing_cell_indices: Sequence[CellIndex]) -> return zero_poly_coeff ``` -### `recover_data` +### `recover_polynomial_coeff` ```python -def recover_data(cell_indices: Sequence[CellIndex], +def recover_polynomial_coeff(cell_indices: Sequence[CellIndex], cells: Sequence[Cell], ) -> Sequence[BLSFieldElement]: """ - Recover the missing evaluations for the extended blob, given at least half of the evaluations. + Recover the polynomial in monomial form that when evaluated at the roots of unity will give the extended_blob. """ # Get the extended domain. This will be referred to as the FFT domain. @@ -635,10 +635,7 @@ def recover_data(cell_indices: Sequence[CellIndex], # Convert Q_3(x) to monomial form reconstructed_poly_coeff = coset_fft_field(reconstructed_poly_over_coset, roots_of_unity_extended, inv=True) - # Convert Q_3(x) to evaluation form over the FFT domain and bit reverse the result - reconstructed_data = bit_reversal_permutation(fft_field(reconstructed_poly_coeff, roots_of_unity_extended)) - - return reconstructed_data + return reconstructed_poly_coeff ``` ### `recover_cells_and_kzg_proofs` @@ -678,19 +675,8 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex], # Convert cells to coset evals cosets_evals = [cell_to_coset_evals(cell) for cell in cells] - reconstructed_data = recover_data(cell_indices, cosets_evals) + polynomial_coeff = recover_polynomial_coeff(cell_indices, cosets_evals) - for cell_index, coset_evals in zip(cell_indices, cosets_evals): - start = cell_index * FIELD_ELEMENTS_PER_CELL - end = (cell_index + 1) * FIELD_ELEMENTS_PER_CELL - assert reconstructed_data[start:end] == coset_evals - - recovered_cells = [ - coset_evals_to_cell(reconstructed_data[i * FIELD_ELEMENTS_PER_CELL:(i + 1) * FIELD_ELEMENTS_PER_CELL]) - for i in range(CELLS_PER_EXT_BLOB)] - - polynomial_eval = reconstructed_data[:FIELD_ELEMENTS_PER_BLOB] - polynomial_coeff = polynomial_eval_to_coeff(polynomial_eval) recovered_proofs = [None] * CELLS_PER_EXT_BLOB for i, cell_index in enumerate(cell_indices): recovered_proofs[cell_index] = bytes_to_kzg_proof(proofs_bytes[i]) @@ -698,7 +684,6 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex], if recovered_proofs[i] is None: coset = coset_for_cell(CellIndex(i)) proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset) - assert coset_evals_to_cell(ys) == recovered_cells[i] recovered_proofs[i] = proof return recovered_cells, recovered_proofs From e4b228c21f5329b9ba8becf1a92120db75ae1273 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 26 Jun 2024 20:30:47 +0100 Subject: [PATCH 2/8] make it look closer to final code --- .../eip7594/polynomial-commitments-sampling.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 5127178570..b887f9da87 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -586,8 +586,8 @@ def construct_vanishing_polynomial(missing_cell_indices: Sequence[CellIndex]) -> ```python def recover_polynomial_coeff(cell_indices: Sequence[CellIndex], - cells: Sequence[Cell], - ) -> Sequence[BLSFieldElement]: + cells: Sequence[Cell], + ) -> Sequence[BLSFieldElement]: """ Recover the polynomial in monomial form that when evaluated at the roots of unity will give the extended_blob. """ @@ -678,13 +678,13 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex], polynomial_coeff = recover_polynomial_coeff(cell_indices, cosets_evals) recovered_proofs = [None] * CELLS_PER_EXT_BLOB - for i, cell_index in enumerate(cell_indices): - recovered_proofs[cell_index] = bytes_to_kzg_proof(proofs_bytes[i]) + recovered_cells = [None] * CELLS_PER_EXT_BLOB + for i in range(CELLS_PER_EXT_BLOB): - if recovered_proofs[i] is None: - coset = coset_for_cell(CellIndex(i)) - proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset) - recovered_proofs[i] = proof + coset = coset_for_cell(CellIndex(i)) + proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset) + recovered_proofs[i] = proof + recovered_cells[i] = ys return recovered_cells, recovered_proofs ``` From 92e88d9f52bffbd22bdca4dce17cf8c16a5c9915 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 16 Jul 2024 11:49:25 -0500 Subject: [PATCH 3/8] Improve comments --- specs/_features/eip7594/polynomial-commitments-sampling.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 115f197d49..c0d4c765e6 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -732,7 +732,7 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex], Vector[Cell, CELLS_PER_EXT_BLOB], Vector[KZGProof, CELLS_PER_EXT_BLOB]]: """ - Given at least 50% of cells/proofs for a blob, recover all the cells/proofs. + Given at least 50% of cells for a blob, recover all the cells/proofs. This algorithm uses FFTs to recover cells faster than using Lagrange implementation, as can be seen here: https://ethresear.ch/t/reed-solomon-erasure-code-recovery-in-n-log-2-n-time-with-ffts/3039 @@ -754,11 +754,13 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex], for cell in cells: assert len(cell) == BYTES_PER_CELL - # Convert cells to coset evals + # Convert cells to coset evaluations cosets_evals = [cell_to_coset_evals(cell) for cell in cells] + # Given the coset evaluations, recover the polynomial in coefficient form polynomial_coeff = recover_polynomial_coeff(cell_indices, cosets_evals) + # Recompute cells/proofs for the polynomial recovered_cells = [None] * CELLS_PER_EXT_BLOB recovered_proofs = [None] * CELLS_PER_EXT_BLOB for i in range(CELLS_PER_EXT_BLOB): From ee91e29a6cdf7803171cfea7efd3bdafa794a806 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 16 Jul 2024 11:52:01 -0500 Subject: [PATCH 4/8] Fix lint issue --- specs/_features/eip7594/polynomial-commitments-sampling.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index c0d4c765e6..a4823d99f3 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -672,8 +672,7 @@ def construct_vanishing_polynomial(missing_cell_indices: Sequence[CellIndex]) -> ```python def recover_polynomial_coeff(cell_indices: Sequence[CellIndex], - cells: Sequence[Cell], - ) -> Sequence[BLSFieldElement]: + cells: Sequence[Cell]) -> Sequence[BLSFieldElement]: """ Recover the polynomial in monomial form that when evaluated at the roots of unity will give the extended_blob. """ From d9decab453db9a40c81fce52b2215977accec98d Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 16 Jul 2024 12:50:22 -0500 Subject: [PATCH 5/8] Fix tests & clean things up a bit --- .../polynomial-commitments-sampling.md | 74 +++++++++---------- 1 file changed, 36 insertions(+), 38 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index a4823d99f3..5675d91510 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -39,12 +39,13 @@ - [`coset_for_cell`](#coset_for_cell) - [Cells](#cells-1) - [Cell computation](#cell-computation) + - [`compute_cells_and_kzg_proofs_polynomialcoeff`](#compute_cells_and_kzg_proofs_polynomialcoeff) - [`compute_cells_and_kzg_proofs`](#compute_cells_and_kzg_proofs) - [Cell verification](#cell-verification) - [`verify_cell_kzg_proof_batch`](#verify_cell_kzg_proof_batch) - [Reconstruction](#reconstruction) - [`construct_vanishing_polynomial`](#construct_vanishing_polynomial) - - [`recover_polynomial_coeff`](#recover_polynomial_coeff) + - [`recover_polynomialcoeff`](#recover_polynomialcoeff) - [`recover_cells_and_kzg_proofs`](#recover_cells_and_kzg_proofs) @@ -555,6 +556,24 @@ def coset_for_cell(cell_index: CellIndex) -> Coset: ### Cell computation +#### `compute_cells_and_kzg_proofs_polynomialcoeff` + +```python +def compute_cells_and_kzg_proofs_polynomialcoeff(polynomial_coeff: PolynomialCoeff) -> Tuple[ + Vector[Cell, CELLS_PER_EXT_BLOB], + Vector[KZGProof, CELLS_PER_EXT_BLOB]]: + """ + Helper function which computes cells/proofs for a polynomial in coefficient form. + """ + cells, proofs = [], [] + for i in range(CELLS_PER_EXT_BLOB): + coset = coset_for_cell(CellIndex(i)) + proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset) + cells.append(coset_evals_to_cell(ys)) + proofs.append(proof) + return cells, proofs +``` + #### `compute_cells_and_kzg_proofs` ```python @@ -572,17 +591,7 @@ def compute_cells_and_kzg_proofs(blob: Blob) -> Tuple[ polynomial = blob_to_polynomial(blob) polynomial_coeff = polynomial_eval_to_coeff(polynomial) - - cells = [] - proofs = [] - - for i in range(CELLS_PER_EXT_BLOB): - coset = coset_for_cell(CellIndex(i)) - proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset) - cells.append(coset_evals_to_cell(ys)) - proofs.append(proof) - - return cells, proofs + return compute_cells_and_kzg_proofs_polynomialcoeff(polynomial_coeff) ``` ### Cell verification @@ -668,20 +677,19 @@ def construct_vanishing_polynomial(missing_cell_indices: Sequence[CellIndex]) -> return zero_poly_coeff ``` -### `recover_polynomial_coeff` +### `recover_polynomialcoeff` ```python -def recover_polynomial_coeff(cell_indices: Sequence[CellIndex], - cells: Sequence[Cell]) -> Sequence[BLSFieldElement]: +def recover_polynomialcoeff(cell_indices: Sequence[CellIndex], + cells: Sequence[Cell]) -> Sequence[BLSFieldElement]: """ - Recover the polynomial in monomial form that when evaluated at the roots of unity will give the extended_blob. + Recover the polynomial in monomial form that when evaluated at the roots of unity will give the extended blob. """ - - # Get the extended domain. This will be referred to as the FFT domain. + # Get the extended domain. This will be referred to as the FFT domain roots_of_unity_extended = compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB) - # Flatten the cells into evaluations. - # If a cell is missing, then its evaluation is zero. + # Flatten the cells into evaluations + # If a cell is missing, then its evaluation is zero extended_evaluation_rbo = [0] * FIELD_ELEMENTS_PER_EXT_BLOB for cell_index, cell in zip(cell_indices, cells): start = cell_index * FIELD_ELEMENTS_PER_CELL @@ -712,15 +720,12 @@ def recover_polynomial_coeff(cell_indices: Sequence[CellIndex], zero_poly_over_coset = coset_fft_field(zero_poly_coeff, roots_of_unity_extended) # Compute Q_3(x) = (E*Z)(x) / Z(x) in evaluation form over a coset of the FFT domain - reconstructed_poly_over_coset = [ - div(a, b) - for a, b in zip(extended_evaluations_over_coset, zero_poly_over_coset) - ] + reconstructed_poly_over_coset = [div(a, b) for a, b in zip(extended_evaluations_over_coset, zero_poly_over_coset)] - # Convert Q_3(x) to monomial form + # Convert Q_3(x) to coefficient form reconstructed_poly_coeff = coset_fft_field(reconstructed_poly_over_coset, roots_of_unity_extended, inv=True) - return reconstructed_poly_coeff + return reconstructed_poly_coeff[:FIELD_ELEMENTS_PER_BLOB] ``` ### `recover_cells_and_kzg_proofs` @@ -741,6 +746,7 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex], Public method. """ + # Check we have the same number of cells and indices assert len(cell_indices) == len(cells) # Check we have enough cells to be able to perform the reconstruction assert CELLS_PER_EXT_BLOB / 2 <= len(cell_indices) <= CELLS_PER_EXT_BLOB @@ -757,16 +763,8 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex], cosets_evals = [cell_to_coset_evals(cell) for cell in cells] # Given the coset evaluations, recover the polynomial in coefficient form - polynomial_coeff = recover_polynomial_coeff(cell_indices, cosets_evals) - - # Recompute cells/proofs for the polynomial - recovered_cells = [None] * CELLS_PER_EXT_BLOB - recovered_proofs = [None] * CELLS_PER_EXT_BLOB - for i in range(CELLS_PER_EXT_BLOB): - coset = coset_for_cell(CellIndex(i)) - proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset) - recovered_proofs[i] = proof - recovered_cells[i] = ys - - return recovered_cells, recovered_proofs + polynomial_coeff = recover_polynomialcoeff(cell_indices, cosets_evals) + + # Recompute all cells/proofs + return compute_cells_and_kzg_proofs_polynomialcoeff(polynomial_coeff) ``` From c9a1a757d1a09190eee78767b3d36b2a84066e42 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 16 Jul 2024 13:39:26 -0500 Subject: [PATCH 6/8] Replace a couple uses of "monomial" with "coefficient" --- .../polynomial-commitments-sampling.md | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 5675d91510..89047a601b 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -39,7 +39,6 @@ - [`coset_for_cell`](#coset_for_cell) - [Cells](#cells-1) - [Cell computation](#cell-computation) - - [`compute_cells_and_kzg_proofs_polynomialcoeff`](#compute_cells_and_kzg_proofs_polynomialcoeff) - [`compute_cells_and_kzg_proofs`](#compute_cells_and_kzg_proofs) - [Cell verification](#cell-verification) - [`verify_cell_kzg_proof_batch`](#verify_cell_kzg_proof_batch) @@ -256,14 +255,25 @@ def compute_verify_cell_kzg_proof_batch_challenge(commitments: Sequence[KZGCommi ```python def polynomial_eval_to_coeff(polynomial: Polynomial) -> PolynomialCoeff: """ - Interpolates a polynomial (given in evaluation form) to a polynomial in coefficient form. + Interpolates a polynomial evaluation form to a polynomial in coefficient form. """ roots_of_unity = compute_roots_of_unity(FIELD_ELEMENTS_PER_BLOB) polynomial_coeff = fft_field(bit_reversal_permutation(list(polynomial)), roots_of_unity, inv=True) - return polynomial_coeff ``` +#### `polynomial_coeff_to_eval` + +```python +def polynomial_coeff_to_eval(polynomial_coeff: PolynomialCoeff) -> Polynomial: + """ + Interpolates a polynomial in coefficient form to a polynomial in evaluation form. + """ + roots_of_unity = compute_roots_of_unity(FIELD_ELEMENTS_PER_BLOB) + polynomial = bit_reversal_permutation(fft_field(list(polynomial_coeff)), roots_of_unity) + return polynomial +``` + #### `add_polynomialcoeff` ```python @@ -556,24 +566,6 @@ def coset_for_cell(cell_index: CellIndex) -> Coset: ### Cell computation -#### `compute_cells_and_kzg_proofs_polynomialcoeff` - -```python -def compute_cells_and_kzg_proofs_polynomialcoeff(polynomial_coeff: PolynomialCoeff) -> Tuple[ - Vector[Cell, CELLS_PER_EXT_BLOB], - Vector[KZGProof, CELLS_PER_EXT_BLOB]]: - """ - Helper function which computes cells/proofs for a polynomial in coefficient form. - """ - cells, proofs = [], [] - for i in range(CELLS_PER_EXT_BLOB): - coset = coset_for_cell(CellIndex(i)) - proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset) - cells.append(coset_evals_to_cell(ys)) - proofs.append(proof) - return cells, proofs -``` - #### `compute_cells_and_kzg_proofs` ```python @@ -591,7 +583,15 @@ def compute_cells_and_kzg_proofs(blob: Blob) -> Tuple[ polynomial = blob_to_polynomial(blob) polynomial_coeff = polynomial_eval_to_coeff(polynomial) - return compute_cells_and_kzg_proofs_polynomialcoeff(polynomial_coeff) + + cells, proofs = [], [] + for i in range(CELLS_PER_EXT_BLOB): + coset = coset_for_cell(CellIndex(i)) + proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset) + cells.append(coset_evals_to_cell(ys)) + proofs.append(proof) + + return cells, proofs ``` ### Cell verification @@ -683,7 +683,7 @@ def construct_vanishing_polynomial(missing_cell_indices: Sequence[CellIndex]) -> def recover_polynomialcoeff(cell_indices: Sequence[CellIndex], cells: Sequence[Cell]) -> Sequence[BLSFieldElement]: """ - Recover the polynomial in monomial form that when evaluated at the roots of unity will give the extended blob. + Recover the polynomial in coefficient form that when evaluated at the roots of unity will give the extended blob. """ # Get the extended domain. This will be referred to as the FFT domain roots_of_unity_extended = compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB) @@ -710,7 +710,7 @@ def recover_polynomialcoeff(cell_indices: Sequence[CellIndex], extended_evaluation_times_zero = [BLSFieldElement(int(a) * int(b) % BLS_MODULUS) for a, b in zip(zero_poly_eval, extended_evaluation)] - # Convert (E*Z)(x) to monomial form + # Convert (E*Z)(x) to coefficient form extended_evaluation_times_zero_coeffs = fft_field(extended_evaluation_times_zero, roots_of_unity_extended, inv=True) # Convert (E*Z)(x) to evaluation form over a coset of the FFT domain @@ -765,6 +765,9 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex], # Given the coset evaluations, recover the polynomial in coefficient form polynomial_coeff = recover_polynomialcoeff(cell_indices, cosets_evals) + # Convert the polynomial to a blob + polynomial = polynomial_coeff_to_eval(polynomial_coeff) + # Recompute all cells/proofs - return compute_cells_and_kzg_proofs_polynomialcoeff(polynomial_coeff) + return compute_cells_and_kzg_proofs(blob) ``` From 60afc3089efaab6bfb1a76d1e80cc222b29aa434 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 16 Jul 2024 13:42:04 -0500 Subject: [PATCH 7/8] Revert "Replace a couple uses of "monomial" with "coefficient"" This reverts commit c9a1a757d1a09190eee78767b3d36b2a84066e42. --- .../polynomial-commitments-sampling.md | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 89047a601b..5675d91510 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -39,6 +39,7 @@ - [`coset_for_cell`](#coset_for_cell) - [Cells](#cells-1) - [Cell computation](#cell-computation) + - [`compute_cells_and_kzg_proofs_polynomialcoeff`](#compute_cells_and_kzg_proofs_polynomialcoeff) - [`compute_cells_and_kzg_proofs`](#compute_cells_and_kzg_proofs) - [Cell verification](#cell-verification) - [`verify_cell_kzg_proof_batch`](#verify_cell_kzg_proof_batch) @@ -255,23 +256,12 @@ def compute_verify_cell_kzg_proof_batch_challenge(commitments: Sequence[KZGCommi ```python def polynomial_eval_to_coeff(polynomial: Polynomial) -> PolynomialCoeff: """ - Interpolates a polynomial evaluation form to a polynomial in coefficient form. + Interpolates a polynomial (given in evaluation form) to a polynomial in coefficient form. """ roots_of_unity = compute_roots_of_unity(FIELD_ELEMENTS_PER_BLOB) polynomial_coeff = fft_field(bit_reversal_permutation(list(polynomial)), roots_of_unity, inv=True) - return polynomial_coeff -``` - -#### `polynomial_coeff_to_eval` -```python -def polynomial_coeff_to_eval(polynomial_coeff: PolynomialCoeff) -> Polynomial: - """ - Interpolates a polynomial in coefficient form to a polynomial in evaluation form. - """ - roots_of_unity = compute_roots_of_unity(FIELD_ELEMENTS_PER_BLOB) - polynomial = bit_reversal_permutation(fft_field(list(polynomial_coeff)), roots_of_unity) - return polynomial + return polynomial_coeff ``` #### `add_polynomialcoeff` @@ -566,6 +556,24 @@ def coset_for_cell(cell_index: CellIndex) -> Coset: ### Cell computation +#### `compute_cells_and_kzg_proofs_polynomialcoeff` + +```python +def compute_cells_and_kzg_proofs_polynomialcoeff(polynomial_coeff: PolynomialCoeff) -> Tuple[ + Vector[Cell, CELLS_PER_EXT_BLOB], + Vector[KZGProof, CELLS_PER_EXT_BLOB]]: + """ + Helper function which computes cells/proofs for a polynomial in coefficient form. + """ + cells, proofs = [], [] + for i in range(CELLS_PER_EXT_BLOB): + coset = coset_for_cell(CellIndex(i)) + proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset) + cells.append(coset_evals_to_cell(ys)) + proofs.append(proof) + return cells, proofs +``` + #### `compute_cells_and_kzg_proofs` ```python @@ -583,15 +591,7 @@ def compute_cells_and_kzg_proofs(blob: Blob) -> Tuple[ polynomial = blob_to_polynomial(blob) polynomial_coeff = polynomial_eval_to_coeff(polynomial) - - cells, proofs = [], [] - for i in range(CELLS_PER_EXT_BLOB): - coset = coset_for_cell(CellIndex(i)) - proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset) - cells.append(coset_evals_to_cell(ys)) - proofs.append(proof) - - return cells, proofs + return compute_cells_and_kzg_proofs_polynomialcoeff(polynomial_coeff) ``` ### Cell verification @@ -683,7 +683,7 @@ def construct_vanishing_polynomial(missing_cell_indices: Sequence[CellIndex]) -> def recover_polynomialcoeff(cell_indices: Sequence[CellIndex], cells: Sequence[Cell]) -> Sequence[BLSFieldElement]: """ - Recover the polynomial in coefficient form that when evaluated at the roots of unity will give the extended blob. + Recover the polynomial in monomial form that when evaluated at the roots of unity will give the extended blob. """ # Get the extended domain. This will be referred to as the FFT domain roots_of_unity_extended = compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB) @@ -710,7 +710,7 @@ def recover_polynomialcoeff(cell_indices: Sequence[CellIndex], extended_evaluation_times_zero = [BLSFieldElement(int(a) * int(b) % BLS_MODULUS) for a, b in zip(zero_poly_eval, extended_evaluation)] - # Convert (E*Z)(x) to coefficient form + # Convert (E*Z)(x) to monomial form extended_evaluation_times_zero_coeffs = fft_field(extended_evaluation_times_zero, roots_of_unity_extended, inv=True) # Convert (E*Z)(x) to evaluation form over a coset of the FFT domain @@ -765,9 +765,6 @@ def recover_cells_and_kzg_proofs(cell_indices: Sequence[CellIndex], # Given the coset evaluations, recover the polynomial in coefficient form polynomial_coeff = recover_polynomialcoeff(cell_indices, cosets_evals) - # Convert the polynomial to a blob - polynomial = polynomial_coeff_to_eval(polynomial_coeff) - # Recompute all cells/proofs - return compute_cells_and_kzg_proofs(blob) + return compute_cells_and_kzg_proofs_polynomialcoeff(polynomial_coeff) ``` From c8f2d2d92434c2153ead45ccc90f3432602ed0ad Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 16 Jul 2024 13:42:57 -0500 Subject: [PATCH 8/8] Only replace "monomial" with "coefficient" --- specs/_features/eip7594/polynomial-commitments-sampling.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 5675d91510..7fec2a52d7 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -683,7 +683,7 @@ def construct_vanishing_polynomial(missing_cell_indices: Sequence[CellIndex]) -> def recover_polynomialcoeff(cell_indices: Sequence[CellIndex], cells: Sequence[Cell]) -> Sequence[BLSFieldElement]: """ - Recover the polynomial in monomial form that when evaluated at the roots of unity will give the extended blob. + Recover the polynomial in coefficient form that when evaluated at the roots of unity will give the extended blob. """ # Get the extended domain. This will be referred to as the FFT domain roots_of_unity_extended = compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB) @@ -697,7 +697,7 @@ def recover_polynomialcoeff(cell_indices: Sequence[CellIndex], extended_evaluation_rbo[start:end] = cell extended_evaluation = bit_reversal_permutation(extended_evaluation_rbo) - # Compute Z(x) in monomial form + # Compute Z(x) in coefficient form # Z(x) is the polynomial which vanishes on all of the evaluations which are missing missing_cell_indices = [CellIndex(cell_index) for cell_index in range(CELLS_PER_EXT_BLOB) if cell_index not in cell_indices] @@ -710,7 +710,7 @@ def recover_polynomialcoeff(cell_indices: Sequence[CellIndex], extended_evaluation_times_zero = [BLSFieldElement(int(a) * int(b) % BLS_MODULUS) for a, b in zip(zero_poly_eval, extended_evaluation)] - # Convert (E*Z)(x) to monomial form + # Convert (E*Z)(x) to coefficient form extended_evaluation_times_zero_coeffs = fft_field(extended_evaluation_times_zero, roots_of_unity_extended, inv=True) # Convert (E*Z)(x) to evaluation form over a coset of the FFT domain