From a8efcceedd04c97678cbb794629a404cc618480d Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Thu, 18 Apr 2024 15:44:17 -0500 Subject: [PATCH 01/15] Add CellBytes type --- specs/_features/eip7594/das-core.md | 9 ++--- .../polynomial-commitments-sampling.md | 40 ++++++++++++++----- .../test_polynomial_commitments.py | 6 +-- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/specs/_features/eip7594/das-core.md b/specs/_features/eip7594/das-core.md index 49b387558f..58784af576 100644 --- a/specs/_features/eip7594/das-core.md +++ b/specs/_features/eip7594/das-core.md @@ -45,8 +45,8 @@ We define the following Python custom types for type hinting and readability: | Name | SSZ equivalent | Description | | - | - | - | -| `DataColumn` | `List[Cell, MAX_BLOB_COMMITMENTS_PER_BLOCK]` | The data of each column in EIP-7594 | -| `ExtendedMatrix` | `List[Cell, MAX_BLOBS_PER_BLOCK * NUMBER_OF_COLUMNS]` | The full data of one-dimensional erasure coding extended blobs (in row major format) | +| `DataColumn` | `List[CellBytes, MAX_BLOB_COMMITMENTS_PER_BLOCK]` | The data of each column in EIP-7594 | +| `ExtendedMatrix` | `List[CellBytes, MAX_BLOBS_PER_BLOCK * NUMBER_OF_COLUMNS]` | The full data of one-dimensional erasure coding extended blobs (in row major format) | ## Configuration @@ -131,7 +131,7 @@ def compute_extended_matrix(blobs: Sequence[Blob]) -> ExtendedMatrix: #### `recover_matrix` ```python -def recover_matrix(cells_dict: Dict[Tuple[BlobIndex, CellID], Cell], blob_count: uint64) -> ExtendedMatrix: +def recover_matrix(cells_dict: Dict[Tuple[BlobIndex, CellID], CellBytes], blob_count: uint64) -> ExtendedMatrix: """ Return the recovered ``ExtendedMatrix``. @@ -141,8 +141,7 @@ def recover_matrix(cells_dict: Dict[Tuple[BlobIndex, CellID], Cell], blob_count: extended_matrix = [] for blob_index in range(blob_count): cell_ids = [cell_id for b_index, cell_id in cells_dict.keys() if b_index == blob_index] - cells = [cells_dict[(blob_index, cell_id)] for cell_id in cell_ids] - cells_bytes = [[bls_field_to_bytes(element) for element in cell] for cell in cells] + cells_bytes = [cells_dict[(blob_index, cell_id)] for cell_id in cell_ids] full_polynomial = recover_polynomial(cell_ids, cells_bytes) cells_from_full_polynomial = [ diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 829e16ebaa..1668f70377 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -64,6 +64,7 @@ Public functions MUST accept raw bytes as input and perform the required cryptog | - | - | - | | `PolynomialCoeff` | `List[BLSFieldElement, FIELD_ELEMENTS_PER_EXT_BLOB]` | A polynomial in coefficient form | | `Cell` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The unit of blob data that can come with their own KZG proofs | +| `CellBytes` | `Vector[BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_CELL]` | The flattened bytes representation of a cell | | `CellID` | `uint64` | Cell identifier | | `RowIndex` | `uint64` | Row identifier | | `ColumnIndex` | `uint64` | Column identifier | @@ -94,11 +95,26 @@ Cells are the smallest unit of blob data that can come with their own KZG proofs #### `bytes_to_cell` ```python -def bytes_to_cell(cell_bytes: Vector[Bytes32, FIELD_ELEMENTS_PER_CELL]) -> Cell: +def bytes_to_cell(cell_bytes: CellBytes) -> Cell: """ Convert untrusted bytes into a Cell. """ - return [bytes_to_bls_field(element) for element in cell_bytes] + cell = Cell() + for i in range(FIELD_ELEMENTS_PER_CELL): + value = bytes_to_bls_field(cell_bytes[i * BYTES_PER_FIELD_ELEMENT: (i + 1) * BYTES_PER_FIELD_ELEMENT]) + cell[i] = value + return cell +``` + +```python +def cell_to_bytes(cell: Cell) -> CellBytes: + """ + Convert a Cell into bytes. + """ + cell_bytes = b"" + for i in range(FIELD_ELEMENTS_PER_CELL): + cell_bytes += bls_field_to_bytes(cell[i]) + return cell_bytes ``` ### Linear combinations @@ -374,7 +390,7 @@ def coset_for_cell(cell_id: CellID) -> Cell: ```python def compute_cells_and_proofs(blob: Blob) -> Tuple[ - Vector[Cell, CELLS_PER_BLOB], + Vector[CellBytes, CELLS_PER_BLOB], Vector[KZGProof, CELLS_PER_BLOB]]: """ Compute all the cell proofs for one blob. This is an inefficient O(n^2) algorithm, @@ -392,7 +408,7 @@ def compute_cells_and_proofs(blob: Blob) -> Tuple[ for i in range(CELLS_PER_BLOB): coset = coset_for_cell(i) proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset) - cells.append(ys) + cells.append(cell_to_bytes(ys)) proofs.append(proof) return cells, proofs @@ -401,7 +417,7 @@ def compute_cells_and_proofs(blob: Blob) -> Tuple[ #### `compute_cells` ```python -def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_BLOB]: +def compute_cells(blob: Blob) -> Vector[CellBytes, CELLS_PER_BLOB]: """ Compute the cell data for a blob (without computing the proofs). @@ -413,8 +429,12 @@ def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_BLOB]: extended_data = fft_field(polynomial_coeff + [0] * FIELD_ELEMENTS_PER_BLOB, compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB)) extended_data_rbo = bit_reversal_permutation(extended_data) - return [extended_data_rbo[i * FIELD_ELEMENTS_PER_CELL:(i + 1) * FIELD_ELEMENTS_PER_CELL] - for i in range(CELLS_PER_BLOB)] + cells = [] + for cell_id in range(CELLS_PER_BLOB): + start = cell_id * FIELD_ELEMENTS_PER_CELL + end = (cell_id + 1) * FIELD_ELEMENTS_PER_CELL + cells.append(cell_to_bytes(extended_data_rbo[start:end])) + return cells ``` ### Cell verification @@ -424,7 +444,7 @@ def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_BLOB]: ```python def verify_cell_proof(commitment_bytes: Bytes48, cell_id: CellID, - cell_bytes: Vector[Bytes32, FIELD_ELEMENTS_PER_CELL], + cell_bytes: CellBytes, proof_bytes: Bytes48) -> bool: """ Check a cell proof @@ -446,7 +466,7 @@ def verify_cell_proof(commitment_bytes: Bytes48, def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48], row_indices: Sequence[RowIndex], column_indices: Sequence[ColumnIndex], - cells_bytes: Sequence[Vector[Bytes32, FIELD_ELEMENTS_PER_CELL]], + cells_bytes: Sequence[CellBytes], proofs_bytes: Sequence[Bytes48]) -> bool: """ Verify a set of cells, given their corresponding proofs and their coordinates (row_id, column_id) in the blob @@ -592,7 +612,7 @@ def recover_original_data(eval_shifted_extended_evaluation: Sequence[BLSFieldEle ```python def recover_polynomial(cell_ids: Sequence[CellID], - cells_bytes: Sequence[Vector[Bytes32, FIELD_ELEMENTS_PER_CELL]]) -> Polynomial: + cells_bytes: Sequence[CellBytes]) -> Polynomial: """ Recover original polynomial from FIELD_ELEMENTS_PER_EXT_BLOB evaluations, half of which can be missing. This algorithm uses FFTs to recover cells faster than using Lagrange implementation, as can be seen here: diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py index d49894adb1..fefd2a3e15 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py @@ -36,7 +36,7 @@ def test_verify_cell_proof(spec): commitment = spec.blob_to_kzg_commitment(blob) cells, proofs = spec.compute_cells_and_proofs(blob) - cells_bytes = [[spec.bls_field_to_bytes(element) for element in cell] for cell in cells] + cells_bytes = [spec.cell_to_bytes(cell) for cell in cells] cell_id = 0 assert spec.verify_cell_proof(commitment, cell_id, cells_bytes[cell_id], proofs[cell_id]) @@ -51,7 +51,7 @@ def test_verify_cell_proof_batch(spec): blob = get_sample_blob(spec) commitment = spec.blob_to_kzg_commitment(blob) cells, proofs = spec.compute_cells_and_proofs(blob) - cells_bytes = [[spec.bls_field_to_bytes(element) for element in cell] for cell in cells] + cells_bytes = [spec.cell_to_bytes(cell) for cell in cells] assert len(cells) == len(proofs) @@ -80,7 +80,7 @@ def test_recover_polynomial(spec): # Extend data with Reed-Solomon and split the extended data in cells cells = spec.compute_cells(blob) - cells_bytes = [[spec.bls_field_to_bytes(element) for element in cell] for cell in cells] + cells_bytes = [spec.cell_to_bytes(cell) for cell in cells] # Compute the cells we will be recovering from cell_ids = [] From 95b3bc92ad5e9fecad9617676caec44f1f6b0922 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Thu, 18 Apr 2024 15:55:57 -0500 Subject: [PATCH 02/15] Use ByteVector, not Vector --- specs/_features/eip7594/polynomial-commitments-sampling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 1668f70377..51d355a1dc 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -64,7 +64,7 @@ Public functions MUST accept raw bytes as input and perform the required cryptog | - | - | - | | `PolynomialCoeff` | `List[BLSFieldElement, FIELD_ELEMENTS_PER_EXT_BLOB]` | A polynomial in coefficient form | | `Cell` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The unit of blob data that can come with their own KZG proofs | -| `CellBytes` | `Vector[BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_CELL]` | The flattened bytes representation of a cell | +| `CellBytes` | `ByteVector[BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_CELL]` | The flattened bytes representation of a cell | | `CellID` | `uint64` | Cell identifier | | `RowIndex` | `uint64` | Row identifier | | `ColumnIndex` | `uint64` | Column identifier | From 305a3c15e8915441e7d678f665acd3b6701bf00c Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Thu, 18 Apr 2024 19:34:57 -0500 Subject: [PATCH 03/15] Fix tests --- specs/_features/eip7594/das-core.md | 2 +- .../eip7594/polynomial-commitments-sampling.md | 2 +- .../test/eip7594/unittests/das/test_das.py | 2 +- .../test_polynomial_commitments.py | 16 ++++++---------- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/specs/_features/eip7594/das-core.md b/specs/_features/eip7594/das-core.md index 58784af576..d6c433f80d 100644 --- a/specs/_features/eip7594/das-core.md +++ b/specs/_features/eip7594/das-core.md @@ -145,7 +145,7 @@ def recover_matrix(cells_dict: Dict[Tuple[BlobIndex, CellID], CellBytes], blob_c full_polynomial = recover_polynomial(cell_ids, cells_bytes) cells_from_full_polynomial = [ - full_polynomial[i * FIELD_ELEMENTS_PER_CELL:(i + 1) * FIELD_ELEMENTS_PER_CELL] + cell_to_bytes(full_polynomial[i * FIELD_ELEMENTS_PER_CELL:(i + 1) * FIELD_ELEMENTS_PER_CELL]) for i in range(CELLS_PER_BLOB) ] extended_matrix.extend(cells_from_full_polynomial) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 51d355a1dc..3589654e9d 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -114,7 +114,7 @@ def cell_to_bytes(cell: Cell) -> CellBytes: cell_bytes = b"" for i in range(FIELD_ELEMENTS_PER_CELL): cell_bytes += bls_field_to_bytes(cell[i]) - return cell_bytes + return CellBytes(cell_bytes) ``` ### Linear combinations diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py index 24011fcdd7..2d667a9049 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py @@ -27,7 +27,7 @@ def test_compute_extended_matrix(spec): for blob_index, row in enumerate(rows): extended_blob = [] for cell in row: - extended_blob.extend(cell) + extended_blob.extend(spec.bytes_to_cell(cell)) blob_part = extended_blob[0:len(extended_blob) // 2] blob = b''.join([spec.bls_field_to_bytes(x) for x in blob_part]) assert blob == input_blobs[blob_index] diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py index fefd2a3e15..e604cf4752 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py @@ -36,12 +36,10 @@ def test_verify_cell_proof(spec): commitment = spec.blob_to_kzg_commitment(blob) cells, proofs = spec.compute_cells_and_proofs(blob) - cells_bytes = [spec.cell_to_bytes(cell) for cell in cells] - cell_id = 0 - assert spec.verify_cell_proof(commitment, cell_id, cells_bytes[cell_id], proofs[cell_id]) + assert spec.verify_cell_proof(commitment, cell_id, cells[cell_id], proofs[cell_id]) cell_id = 1 - assert spec.verify_cell_proof(commitment, cell_id, cells_bytes[cell_id], proofs[cell_id]) + assert spec.verify_cell_proof(commitment, cell_id, cells[cell_id], proofs[cell_id]) @with_eip7594_and_later @@ -51,7 +49,6 @@ def test_verify_cell_proof_batch(spec): blob = get_sample_blob(spec) commitment = spec.blob_to_kzg_commitment(blob) cells, proofs = spec.compute_cells_and_proofs(blob) - cells_bytes = [spec.cell_to_bytes(cell) for cell in cells] assert len(cells) == len(proofs) @@ -59,7 +56,7 @@ def test_verify_cell_proof_batch(spec): row_commitments_bytes=[commitment], row_indices=[0, 0], column_indices=[0, 4], - cells_bytes=[cells_bytes[0], cells_bytes[4]], + cells_bytes=[cells[0], cells[4]], proofs_bytes=[proofs[0], proofs[4]], ) @@ -80,7 +77,6 @@ def test_recover_polynomial(spec): # Extend data with Reed-Solomon and split the extended data in cells cells = spec.compute_cells(blob) - cells_bytes = [spec.cell_to_bytes(cell) for cell in cells] # Compute the cells we will be recovering from cell_ids = [] @@ -91,16 +87,16 @@ def test_recover_polynomial(spec): j = rng.randint(0, spec.CELLS_PER_BLOB - 1) cell_ids.append(j) # Now the cells themselves - known_cells_bytes = [cells_bytes[cell_id] for cell_id in cell_ids] + known_cells = [cells[cell_id] for cell_id in cell_ids] # Recover the data - recovered_data = spec.recover_polynomial(cell_ids, known_cells_bytes) + recovered_data = spec.recover_polynomial(cell_ids, known_cells) # Check that the original data match the non-extended portion of the recovered data assert original_polynomial == recovered_data[:len(recovered_data) // 2] # Now flatten the cells and check that they match the entirety of the recovered data - flattened_cells = [x for xs in cells for x in xs] + flattened_cells = [x for xs in cells for x in spec.bytes_to_cell(xs)] assert flattened_cells == recovered_data From 1d79e74897feabe05199a944c7172c08f05ff2ce Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Thu, 18 Apr 2024 19:38:57 -0500 Subject: [PATCH 04/15] Replace b"" with [] --- 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 3589654e9d..0b880098c0 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -101,7 +101,9 @@ def bytes_to_cell(cell_bytes: CellBytes) -> Cell: """ cell = Cell() for i in range(FIELD_ELEMENTS_PER_CELL): - value = bytes_to_bls_field(cell_bytes[i * BYTES_PER_FIELD_ELEMENT: (i + 1) * BYTES_PER_FIELD_ELEMENT]) + start = i * BYTES_PER_FIELD_ELEMENT + end = (i + 1) * BYTES_PER_FIELD_ELEMENT + value = bytes_to_bls_field(cell_bytes[start:end]) cell[i] = value return cell ``` @@ -111,7 +113,7 @@ def cell_to_bytes(cell: Cell) -> CellBytes: """ Convert a Cell into bytes. """ - cell_bytes = b"" + cell_bytes = [] for i in range(FIELD_ELEMENTS_PER_CELL): cell_bytes += bls_field_to_bytes(cell[i]) return CellBytes(cell_bytes) From f5b27f14dac4b5b6772738efaa2291bfc3cae840 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Fri, 19 Apr 2024 09:11:06 -0500 Subject: [PATCH 05/15] Apply suggestions for bytes_to_cell --- 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 21afc1f1bc..3d44c6361e 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -99,13 +99,13 @@ def bytes_to_cell(cell_bytes: CellBytes) -> Cell: """ Convert untrusted bytes into a Cell. """ - cell = Cell() + cell = [] for i in range(FIELD_ELEMENTS_PER_CELL): start = i * BYTES_PER_FIELD_ELEMENT end = (i + 1) * BYTES_PER_FIELD_ELEMENT value = bytes_to_bls_field(cell_bytes[start:end]) - cell[i] = value - return cell + cell.append(value) + return Cell(cell) ``` ```python From 63d07c3fda5e7aa817b208f0adb8540bc7a32bce Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Fri, 19 Apr 2024 09:54:49 -0500 Subject: [PATCH 06/15] Add/integrate new CosetEvals type --- specs/_features/eip7594/das-core.md | 12 ++-- .../polynomial-commitments-sampling.md | 71 ++++++++++--------- .../test/eip7594/unittests/das/test_das.py | 2 +- .../test_polynomial_commitments.py | 8 +-- 4 files changed, 48 insertions(+), 45 deletions(-) diff --git a/specs/_features/eip7594/das-core.md b/specs/_features/eip7594/das-core.md index 5828965245..c73340b6b7 100644 --- a/specs/_features/eip7594/das-core.md +++ b/specs/_features/eip7594/das-core.md @@ -45,8 +45,8 @@ We define the following Python custom types for type hinting and readability: | Name | SSZ equivalent | Description | | - | - | - | -| `DataColumn` | `List[CellBytes, MAX_BLOB_COMMITMENTS_PER_BLOCK]` | The data of each column in EIP-7594 | -| `ExtendedMatrix` | `List[CellBytes, MAX_BLOBS_PER_BLOCK * NUMBER_OF_COLUMNS]` | The full data of one-dimensional erasure coding extended blobs (in row major format) | +| `DataColumn` | `List[Cell, MAX_BLOB_COMMITMENTS_PER_BLOCK]` | The data of each column in EIP-7594 | +| `ExtendedMatrix` | `List[Cell, MAX_BLOBS_PER_BLOCK * NUMBER_OF_COLUMNS]` | The full data of one-dimensional erasure coding extended blobs (in row major format) | ## Configuration @@ -131,7 +131,7 @@ def compute_extended_matrix(blobs: Sequence[Blob]) -> ExtendedMatrix: #### `recover_matrix` ```python -def recover_matrix(cells_dict: Dict[Tuple[BlobIndex, CellID], CellBytes], blob_count: uint64) -> ExtendedMatrix: +def recover_matrix(cells_dict: Dict[Tuple[BlobIndex, CellID], Cell], blob_count: uint64) -> ExtendedMatrix: """ Return the recovered ``ExtendedMatrix``. @@ -141,11 +141,11 @@ def recover_matrix(cells_dict: Dict[Tuple[BlobIndex, CellID], CellBytes], blob_c extended_matrix = [] for blob_index in range(blob_count): cell_ids = [cell_id for b_index, cell_id in cells_dict.keys() if b_index == blob_index] - cells_bytes = [cells_dict[(blob_index, cell_id)] for cell_id in cell_ids] + cells = [cells_dict[(blob_index, cell_id)] for cell_id in cell_ids] - full_polynomial = recover_polynomial(cell_ids, cells_bytes) + full_polynomial = recover_polynomial(cell_ids, cells) cells_from_full_polynomial = [ - cell_to_bytes(full_polynomial[i * FIELD_ELEMENTS_PER_CELL:(i + 1) * FIELD_ELEMENTS_PER_CELL]) + coset_evals_to_cell(full_polynomial[i * FIELD_ELEMENTS_PER_CELL:(i + 1) * FIELD_ELEMENTS_PER_CELL]) for i in range(CELLS_PER_EXT_BLOB) ] extended_matrix.extend(cells_from_full_polynomial) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 3d44c6361e..9c92af7a69 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -13,7 +13,8 @@ - [Cells](#cells) - [Helper functions](#helper-functions) - [BLS12-381 helpers](#bls12-381-helpers) - - [`bytes_to_cell`](#bytes_to_cell) + - [`cell_to_coset_evals`](#cell_to_coset_evals) + - [`coset_evals_to_cell`](#coset_evals_to_cell) - [Linear combinations](#linear-combinations) - [`g2_lincomb`](#g2_lincomb) - [FFTs](#ffts) @@ -63,8 +64,8 @@ Public functions MUST accept raw bytes as input and perform the required cryptog | Name | SSZ equivalent | Description | | - | - | - | | `PolynomialCoeff` | `List[BLSFieldElement, FIELD_ELEMENTS_PER_EXT_BLOB]` | A polynomial in coefficient form | -| `Cell` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The unit of blob data that can come with their own KZG proofs | -| `CellBytes` | `ByteVector[BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_CELL]` | The flattened bytes representation of a cell | +| `CosetEvals` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The internal representation of a cell | +| `Cell` | `ByteVector[BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_CELL]` | The unit of blob data that can come with its own KZG proof | | `CellID` | `uint64` | Cell identifier | | `RowIndex` | `uint64` | Row identifier | | `ColumnIndex` | `uint64` | Column identifier | @@ -92,31 +93,33 @@ Cells are the smallest unit of blob data that can come with their own KZG proofs ### BLS12-381 helpers -#### `bytes_to_cell` +#### `cell_to_coset_evals` ```python -def bytes_to_cell(cell_bytes: CellBytes) -> Cell: +def cell_to_coset_evals(cell: Cell) -> CosetEvals: """ - Convert untrusted bytes into a Cell. + Convert an untrusted ``Cell`` into a trusted ``CosetEvals``. """ - cell = [] + evals = [] for i in range(FIELD_ELEMENTS_PER_CELL): start = i * BYTES_PER_FIELD_ELEMENT end = (i + 1) * BYTES_PER_FIELD_ELEMENT - value = bytes_to_bls_field(cell_bytes[start:end]) - cell.append(value) - return Cell(cell) + value = bytes_to_bls_field(cell[start:end]) + evals.append(value) + return CosetEvals(evals) ``` +#### `coset_evals_to_cell` + ```python -def cell_to_bytes(cell: Cell) -> CellBytes: +def coset_evals_to_cell(coset_evals: CosetEvals) -> Cell: """ - Convert a Cell into bytes. + Convert a trusted ``CosetEval`` into an untrusted ``Cell``. """ - cell_bytes = [] + cell = [] for i in range(FIELD_ELEMENTS_PER_CELL): - cell_bytes += bls_field_to_bytes(cell[i]) - return CellBytes(cell_bytes) + cell += bls_field_to_bytes(coset_evals[i]) + return Cell(cell) ``` ### Linear combinations @@ -389,7 +392,7 @@ def coset_for_cell(cell_id: CellID) -> Cell: roots_of_unity_brp = bit_reversal_permutation( compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB) ) - return Cell(roots_of_unity_brp[FIELD_ELEMENTS_PER_CELL * cell_id:FIELD_ELEMENTS_PER_CELL * (cell_id + 1)]) + return CosetEvals(roots_of_unity_brp[FIELD_ELEMENTS_PER_CELL * cell_id:FIELD_ELEMENTS_PER_CELL * (cell_id + 1)]) ``` ## Cells @@ -400,7 +403,7 @@ def coset_for_cell(cell_id: CellID) -> Cell: ```python def compute_cells_and_proofs(blob: Blob) -> Tuple[ - Vector[CellBytes, CELLS_PER_EXT_BLOB], + Vector[Cell, CELLS_PER_EXT_BLOB], Vector[KZGProof, CELLS_PER_EXT_BLOB]]: """ @@ -419,7 +422,7 @@ def compute_cells_and_proofs(blob: Blob) -> Tuple[ for i in range(CELLS_PER_EXT_BLOB): coset = coset_for_cell(i) proof, ys = compute_kzg_proof_multi_impl(polynomial_coeff, coset) - cells.append(cell_to_bytes(ys)) + cells.append(coset_evals_to_cell(ys)) proofs.append(proof) return cells, proofs @@ -428,7 +431,7 @@ def compute_cells_and_proofs(blob: Blob) -> Tuple[ #### `compute_cells` ```python -def compute_cells(blob: Blob) -> Vector[CellBytes, CELLS_PER_EXTBLOB]: +def compute_cells(blob: Blob) -> Vector[Cell, CELLS_PER_EXT_BLOB]: """ Compute the cell data for an extended blob (without computing the proofs). @@ -444,7 +447,7 @@ def compute_cells(blob: Blob) -> Vector[CellBytes, CELLS_PER_EXTBLOB]: for cell_id in range(CELLS_PER_EXT_BLOB): start = cell_id * FIELD_ELEMENTS_PER_CELL end = (cell_id + 1) * FIELD_ELEMENTS_PER_CELL - cells.append(cell_to_bytes(extended_data_rbo[start:end])) + cells.append(coset_evals_to_cell(extended_data_rbo[start:end])) return cells ``` @@ -455,7 +458,7 @@ def compute_cells(blob: Blob) -> Vector[CellBytes, CELLS_PER_EXTBLOB]: ```python def verify_cell_proof(commitment_bytes: Bytes48, cell_id: CellID, - cell_bytes: CellBytes, + cell: Cell, proof_bytes: Bytes48) -> bool: """ Check a cell proof @@ -467,7 +470,7 @@ def verify_cell_proof(commitment_bytes: Bytes48, return verify_kzg_proof_multi_impl( bytes_to_kzg_commitment(commitment_bytes), coset, - bytes_to_cell(cell_bytes), + cell_to_coset_evals(cell), bytes_to_kzg_proof(proof_bytes)) ``` @@ -477,7 +480,7 @@ def verify_cell_proof(commitment_bytes: Bytes48, def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48], row_indices: Sequence[RowIndex], column_indices: Sequence[ColumnIndex], - cells_bytes: Sequence[CellBytes], + cells: Sequence[Cell], proofs_bytes: Sequence[Bytes48]) -> bool: """ Verify a set of cells, given their corresponding proofs and their coordinates (row_id, column_id) in the blob @@ -493,19 +496,19 @@ def verify_cell_proof_batch(row_commitments_bytes: Sequence[Bytes48], Public method. """ - assert len(cells_bytes) == len(proofs_bytes) == len(row_indices) == len(column_indices) + assert len(cells) == len(proofs_bytes) == len(row_indices) == len(column_indices) # Get commitments via row IDs commitments_bytes = [row_commitments_bytes[row_index] for row_index in row_indices] # Get objects from bytes commitments = [bytes_to_kzg_commitment(commitment_bytes) for commitment_bytes in commitments_bytes] - cells = [bytes_to_cell(cell_bytes) for cell_bytes in cells_bytes] + cosets_evals = [cell_to_coset_evals(cell) for cell in cells] proofs = [bytes_to_kzg_proof(proof_bytes) for proof_bytes in proofs_bytes] return all( - verify_kzg_proof_multi_impl(commitment, coset_for_cell(column_index), cell, proof) - for commitment, column_index, cell, proof in zip(commitments, column_indices, cells, proofs) + verify_kzg_proof_multi_impl(commitment, coset_for_cell(column_index), coset_evals, proof) + for commitment, column_index, coset_evals, proof in zip(commitments, column_indices, cosets_evals, proofs) ) ``` @@ -623,7 +626,7 @@ def recover_original_data(eval_shifted_extended_evaluation: Sequence[BLSFieldEle ```python def recover_polynomial(cell_ids: Sequence[CellID], - cells_bytes: Sequence[CellBytes]) -> Polynomial: + cells: Sequence[Cell]) -> Polynomial: """ Recover original polynomial from FIELD_ELEMENTS_PER_EXT_BLOB evaluations, half of which can be missing. This algorithm uses FFTs to recover cells faster than using Lagrange implementation, as can be seen here: @@ -634,7 +637,7 @@ def recover_polynomial(cell_ids: Sequence[CellID], Public method. """ - assert len(cell_ids) == len(cells_bytes) + assert len(cell_ids) == len(cells) # Check we have enough cells to be able to perform the reconstruction assert CELLS_PER_EXT_BLOB / 2 <= len(cell_ids) <= CELLS_PER_EXT_BLOB # Check for duplicates @@ -643,15 +646,15 @@ def recover_polynomial(cell_ids: Sequence[CellID], # Get the extended domain roots_of_unity_extended = compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB) - # Convert from bytes to cells - cells = [bytes_to_cell(cell_bytes) for cell_bytes in cells_bytes] + # Convert cells to coset evals + cosets_evals = [cell_to_coset_evals(cell) for cell in cells] missing_cell_ids = [cell_id for cell_id in range(CELLS_PER_EXT_BLOB) if cell_id not in cell_ids] zero_poly_coeff, zero_poly_eval, zero_poly_eval_brp = construct_vanishing_polynomial(missing_cell_ids) eval_shifted_extended_evaluation, eval_shifted_zero_poly, shift_inv = recover_shifted_data( cell_ids, - cells, + cosets_evals, zero_poly_eval, zero_poly_coeff, roots_of_unity_extended, @@ -664,10 +667,10 @@ def recover_polynomial(cell_ids: Sequence[CellID], roots_of_unity_extended, ) - for cell_id, cell in zip(cell_ids, cells): + for cell_id, coset_evals in zip(cell_ids, cosets_evals): start = cell_id * FIELD_ELEMENTS_PER_CELL end = (cell_id + 1) * FIELD_ELEMENTS_PER_CELL - assert reconstructed_data[start:end] == cell + assert reconstructed_data[start:end] == coset_evals return reconstructed_data ``` diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py index 34a7e5cef9..cdbfad9ffe 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/das/test_das.py @@ -28,7 +28,7 @@ def test_compute_extended_matrix(spec): for blob_index, row in enumerate(rows): extended_blob = [] for cell in row: - extended_blob.extend(spec.bytes_to_cell(cell)) + extended_blob.extend(spec.cell_to_coset_evals(cell)) blob_part = extended_blob[0:len(extended_blob) // 2] blob = b''.join([spec.bls_field_to_bytes(x) for x in blob_part]) assert blob == input_blobs[blob_index] diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py index 4388860edc..0cc1cac075 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py @@ -56,7 +56,7 @@ def test_verify_cell_proof_batch(spec): row_commitments_bytes=[commitment], row_indices=[0, 0], column_indices=[0, 4], - cells_bytes=[cells[0], cells[4]], + cells=[cells[0], cells[4]], proofs_bytes=[proofs[0], proofs[4]], ) @@ -95,9 +95,9 @@ def test_recover_polynomial(spec): # Check that the original data match the non-extended portion of the recovered data assert original_polynomial == recovered_data[:len(recovered_data) // 2] - # Now flatten the cells and check that they match the entirety of the recovered data - flattened_cells = [x for xs in cells for x in spec.bytes_to_cell(xs)] - assert flattened_cells == recovered_data + # Now flatten the coset evals and check that they match the entirety of the recovered data + flattened_coset_evals = [x for xs in cells for x in spec.cell_to_coset_evals(xs)] + assert flattened_coset_evals == recovered_data @with_eip7594_and_later From ae370be4b4e6920823252fa672d501b7dc5c2780 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Fri, 19 Apr 2024 11:43:23 -0500 Subject: [PATCH 07/15] Remove accidental new line --- specs/_features/eip7594/polynomial-commitments-sampling.md | 1 - 1 file changed, 1 deletion(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 9c92af7a69..ca620a60a9 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -405,7 +405,6 @@ def coset_for_cell(cell_id: CellID) -> Cell: def compute_cells_and_proofs(blob: Blob) -> Tuple[ Vector[Cell, CELLS_PER_EXT_BLOB], Vector[KZGProof, CELLS_PER_EXT_BLOB]]: - """ Compute all the cell proofs for an extended blob. This is an inefficient O(n^2) algorithm, for performant implementation the FK20 algorithm that runs in O(n log n) should be From 548a0a62596443cfdc535b1b30a6a4c434b8694c Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Fri, 19 Apr 2024 14:09:58 -0500 Subject: [PATCH 08/15] Fix recover_all_cells --- specs/_features/eip7594/polynomial-commitments-sampling.md | 4 ++-- .../polynomial_commitments/test_polynomial_commitments.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 6737d12570..0f3f21e121 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -623,8 +623,8 @@ def recover_original_data(eval_shifted_extended_evaluation: Sequence[BLSFieldEle ### `recover_all_cells` ```python -def recover_polynomial(cell_ids: Sequence[CellID], - cells: Sequence[Cell]) -> Sequence[CosetEvals]: +def recover_all_cells(cell_ids: Sequence[CellID], + cells: Sequence[Cell]) -> Sequence[CosetEvals]: """ Recover all of the cells in the extended blob from FIELD_ELEMENTS_PER_EXT_BLOB evaluations, half of which can be missing. diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py index bc676267af..4380b5d7ab 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py @@ -91,13 +91,14 @@ def test_recover_all_cells(spec): # Recover all of the cells recovered_cells = spec.recover_all_cells(cell_ids, known_cells) - recovered_data = [x for xs in recovered_cells for x in spec.cell_to_coset_evals(xs)] + recovered_data = [x for xs in recovered_cells for x in xs] # Check that the original data match the non-extended portion of the recovered data assert original_polynomial == recovered_data[:len(recovered_data) // 2] # Check that the recovered cells match the original cells - assert cells == recovered_cells + recovered_cells_bytes = [spec.coset_evals_to_cell(x) for x in recovered_cells] + assert cells == recovered_cells_bytes @with_eip7594_and_later From 300ac50f3431ca945604564a4bd8d9f1c7476102 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Fri, 19 Apr 2024 15:05:52 -0500 Subject: [PATCH 09/15] Fix recover_matrix --- specs/_features/eip7594/das-core.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/_features/eip7594/das-core.md b/specs/_features/eip7594/das-core.md index 821b8ec685..f0c5bec428 100644 --- a/specs/_features/eip7594/das-core.md +++ b/specs/_features/eip7594/das-core.md @@ -143,7 +143,7 @@ def recover_matrix(cells_dict: Dict[Tuple[BlobIndex, CellID], Cell], blob_count: cell_ids = [cell_id for b_index, cell_id in cells_dict.keys() if b_index == blob_index] cells = [cells_dict[(blob_index, cell_id)] for cell_id in cell_ids] - all_cells_for_row = recover_all_cells(cell_ids, cells) + all_cells_for_row = [coset_evals_to_cell(cell) for cell in recover_all_cells(cell_ids, cells)] extended_matrix.extend(all_cells_for_row) return ExtendedMatrix(extended_matrix) ``` From 169cc830d686a339208d92f3bdd4b18f990a5d1f Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Mon, 22 Apr 2024 10:22:11 +0100 Subject: [PATCH 10/15] fix CosetEvals abstraction leak --- specs/_features/eip7594/das-core.md | 2 +- specs/_features/eip7594/polynomial-commitments-sampling.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/specs/_features/eip7594/das-core.md b/specs/_features/eip7594/das-core.md index f0c5bec428..821b8ec685 100644 --- a/specs/_features/eip7594/das-core.md +++ b/specs/_features/eip7594/das-core.md @@ -143,7 +143,7 @@ def recover_matrix(cells_dict: Dict[Tuple[BlobIndex, CellID], Cell], blob_count: cell_ids = [cell_id for b_index, cell_id in cells_dict.keys() if b_index == blob_index] cells = [cells_dict[(blob_index, cell_id)] for cell_id in cell_ids] - all_cells_for_row = [coset_evals_to_cell(cell) for cell in recover_all_cells(cell_ids, cells)] + all_cells_for_row = recover_all_cells(cell_ids, cells) extended_matrix.extend(all_cells_for_row) return ExtendedMatrix(extended_matrix) ``` diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 0f3f21e121..e631380333 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -624,7 +624,7 @@ def recover_original_data(eval_shifted_extended_evaluation: Sequence[BLSFieldEle ```python def recover_all_cells(cell_ids: Sequence[CellID], - cells: Sequence[Cell]) -> Sequence[CosetEvals]: + cells: Sequence[Cell]) -> Sequence[Cell]: """ Recover all of the cells in the extended blob from FIELD_ELEMENTS_PER_EXT_BLOB evaluations, half of which can be missing. @@ -672,8 +672,8 @@ def recover_all_cells(cell_ids: Sequence[CellID], assert reconstructed_data[start:end] == coset_evals reconstructed_data_as_cells = [ - reconstructed_data[i * FIELD_ELEMENTS_PER_CELL:(i + 1) * FIELD_ELEMENTS_PER_CELL] + 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)] - + return reconstructed_data_as_cells ``` From bc607ece735f1fd4c28bcf72c84457dba1433f32 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Mon, 22 Apr 2024 12:36:11 +0300 Subject: [PATCH 11/15] Introduce internal Coset type for `coset_for_cell()` --- .../eip7594/polynomial-commitments-sampling.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index e631380333..e0c7a2dd84 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -64,7 +64,8 @@ Public functions MUST accept raw bytes as input and perform the required cryptog | Name | SSZ equivalent | Description | | - | - | - | | `PolynomialCoeff` | `List[BLSFieldElement, FIELD_ELEMENTS_PER_EXT_BLOB]` | A polynomial in coefficient form | -| `CosetEvals` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The internal representation of a cell | +| `Coset` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The evaluation domain of a cell | +| `CosetEvals` | `Vector[BLSFieldElement, FIELD_ELEMENTS_PER_CELL]` | The internal representation of a cell (the evaluations over its Coset) | | `Cell` | `ByteVector[BYTES_PER_FIELD_ELEMENT * FIELD_ELEMENTS_PER_CELL]` | The unit of blob data that can come with its own KZG proof | | `CellID` | `uint64` | Cell identifier | | `RowIndex` | `uint64` | Row identifier | @@ -327,7 +328,7 @@ Extended KZG functions for multiproofs ```python def compute_kzg_proof_multi_impl( polynomial_coeff: PolynomialCoeff, - zs: Sequence[BLSFieldElement]) -> Tuple[KZGProof, Sequence[BLSFieldElement]]: + zs: Coset) -> Tuple[KZGProof, Sequence[BLSFieldElement]]: """ Compute a KZG multi-evaluation proof for a set of `k` points. @@ -357,8 +358,8 @@ def compute_kzg_proof_multi_impl( ```python def verify_kzg_proof_multi_impl(commitment: KZGCommitment, - zs: Sequence[BLSFieldElement], - ys: Sequence[BLSFieldElement], + zs: Coset, + ys: CosetEvals, proof: KZGProof) -> bool: """ Helper function that verifies a KZG multiproof @@ -383,7 +384,7 @@ def verify_kzg_proof_multi_impl(commitment: KZGCommitment, #### `coset_for_cell` ```python -def coset_for_cell(cell_id: CellID) -> Cell: +def coset_for_cell(cell_id: CellID) -> Coset: """ Get the coset for a given ``cell_id`` """ @@ -391,7 +392,7 @@ def coset_for_cell(cell_id: CellID) -> Cell: roots_of_unity_brp = bit_reversal_permutation( compute_roots_of_unity(FIELD_ELEMENTS_PER_EXT_BLOB) ) - return CosetEvals(roots_of_unity_brp[FIELD_ELEMENTS_PER_CELL * cell_id:FIELD_ELEMENTS_PER_CELL * (cell_id + 1)]) + return Coset(roots_of_unity_brp[FIELD_ELEMENTS_PER_CELL * cell_id:FIELD_ELEMENTS_PER_CELL * (cell_id + 1)]) ``` ## Cells From a58fc73b24131ca4e3a08b7da0e4769a82730428 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Mon, 22 Apr 2024 12:48:04 +0300 Subject: [PATCH 12/15] Use CosetEvals in compute_kzg_proof_multi_impl() --- specs/_features/eip7594/polynomial-commitments-sampling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index e0c7a2dd84..bb396b69b2 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -328,7 +328,7 @@ Extended KZG functions for multiproofs ```python def compute_kzg_proof_multi_impl( polynomial_coeff: PolynomialCoeff, - zs: Coset) -> Tuple[KZGProof, Sequence[BLSFieldElement]]: + zs: Coset) -> Tuple[KZGProof, CosetEvals]: """ Compute a KZG multi-evaluation proof for a set of `k` points. From e4b146d666875a76bb420206810adce998c7326e Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Mon, 22 Apr 2024 11:54:17 +0100 Subject: [PATCH 13/15] update test --- .../test_polynomial_commitments.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py index 4380b5d7ab..e7e5bd1363 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py @@ -72,9 +72,7 @@ def test_recover_all_cells(spec): # Get the data we will be working with blob = get_sample_blob(spec) - # Get the data in evaluation form - original_polynomial = spec.blob_to_polynomial(blob) - + # Extend data with Reed-Solomon and split the extended data in cells cells = spec.compute_cells(blob) @@ -94,11 +92,11 @@ def test_recover_all_cells(spec): recovered_data = [x for xs in recovered_cells for x in xs] # Check that the original data match the non-extended portion of the recovered data - assert original_polynomial == recovered_data[:len(recovered_data) // 2] + blob_byte_array = [b for b in blob] + assert blob_byte_array == recovered_data[:len(recovered_data) // 2] # Check that the recovered cells match the original cells - recovered_cells_bytes = [spec.coset_evals_to_cell(x) for x in recovered_cells] - assert cells == recovered_cells_bytes + assert cells == recovered_cells @with_eip7594_and_later From 7ecf9bc57434421a43a843e420b47273ed12762e Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Mon, 22 Apr 2024 15:20:46 +0300 Subject: [PATCH 14/15] satisfy linter --- .../polynomial_commitments/test_polynomial_commitments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py index e7e5bd1363..deb83c223e 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/polynomial_commitments/test_polynomial_commitments.py @@ -72,7 +72,7 @@ def test_recover_all_cells(spec): # Get the data we will be working with blob = get_sample_blob(spec) - + # Extend data with Reed-Solomon and split the extended data in cells cells = spec.compute_cells(blob) From 5aa3aa64a1d46fab9687c1ee715c06b2df701ae7 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 22 Apr 2024 07:46:48 -0500 Subject: [PATCH 15/15] Fix two nits I noticed --- specs/_features/eip7594/polynomial-commitments-sampling.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index bb396b69b2..1c7b1c2c71 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -624,8 +624,7 @@ def recover_original_data(eval_shifted_extended_evaluation: Sequence[BLSFieldEle ### `recover_all_cells` ```python -def recover_all_cells(cell_ids: Sequence[CellID], - cells: Sequence[Cell]) -> Sequence[Cell]: +def recover_all_cells(cell_ids: Sequence[CellID], cells: Sequence[Cell]) -> Sequence[Cell]: """ Recover all of the cells in the extended blob from FIELD_ELEMENTS_PER_EXT_BLOB evaluations, half of which can be missing. @@ -675,6 +674,6 @@ def recover_all_cells(cell_ids: Sequence[CellID], reconstructed_data_as_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)] - + return reconstructed_data_as_cells ```