From 252b852a61289efeb961a497f56302a70aeb7c77 Mon Sep 17 00:00:00 2001 From: Justin Traglia <95511699+jtraglia@users.noreply.github.com> Date: Mon, 15 Jul 2024 11:41:33 -0500 Subject: [PATCH] Rename column_index to cell_index in KZG spec (#3841) * Rename column_index to cell_index in KZG spec * Fix table of contents * Replace list(set()) with set() * Change coset_evals to cell_indices in some places * Remove punctuation in table description * Remove "row" from comments & improve docstring * Replace unique with deduplicated --- specs/_features/eip7594/das-core.md | 4 +- specs/_features/eip7594/p2p-interface.md | 7 +- .../polynomial-commitments-sampling.md | 132 ++++++++--------- .../test_polynomial_commitments.py | 30 ++-- .../kzg_7594/verify_cell_kzg_proof_batch.md | 4 +- tests/generators/kzg_7594/main.py | 134 +++++++++--------- 6 files changed, 149 insertions(+), 162 deletions(-) diff --git a/specs/_features/eip7594/das-core.md b/specs/_features/eip7594/das-core.md index 0d6530226..ee5dc557f 100644 --- a/specs/_features/eip7594/das-core.md +++ b/specs/_features/eip7594/das-core.md @@ -68,8 +68,8 @@ The following values are (non-configurable) constants used throughout the specif | Name | Value | Description | | - | - | - | -| `NUMBER_OF_COLUMNS` | `uint64(CELLS_PER_EXT_BLOB)` (= 128) | Number of columns in the extended data matrix. | -| `MAX_CELLS_IN_EXTENDED_MATRIX` | `uint64(MAX_BLOBS_PER_BLOCK * NUMBER_OF_COLUMNS)` (= 768) | The data size of `ExtendedMatrix`. | +| `NUMBER_OF_COLUMNS` | `uint64(CELLS_PER_EXT_BLOB)` (= 128) | Number of columns in the extended data matrix | +| `MAX_CELLS_IN_EXTENDED_MATRIX` | `uint64(MAX_BLOBS_PER_BLOCK * NUMBER_OF_COLUMNS)` (= 768) | The data size of `ExtendedMatrix` | ### Networking diff --git a/specs/_features/eip7594/p2p-interface.md b/specs/_features/eip7594/p2p-interface.md index 0c9a7cd17..4584a6c8e 100644 --- a/specs/_features/eip7594/p2p-interface.md +++ b/specs/_features/eip7594/p2p-interface.md @@ -73,12 +73,13 @@ def verify_data_column_sidecar_kzg_proofs(sidecar: DataColumnSidecar) -> bool: assert sidecar.index < NUMBER_OF_COLUMNS assert len(sidecar.column) == len(sidecar.kzg_commitments) == len(sidecar.kzg_proofs) - column_indices = [sidecar.index] * len(sidecar.column) + # The column index also represents the cell index + cell_indices = [CellIndex(sidecar.index)] * len(sidecar.column) - # KZG batch verifies that the cells match the corresponding commitments and proofs + # Batch verify that the cells match the corresponding commitments and proofs return verify_cell_kzg_proof_batch( commitments_bytes=sidecar.kzg_commitments, - column_indices=column_indices, + cell_indices=cell_indices, cells=sidecar.column, proofs_bytes=sidecar.kzg_proofs, ) diff --git a/specs/_features/eip7594/polynomial-commitments-sampling.md b/specs/_features/eip7594/polynomial-commitments-sampling.md index 253644fe7..2993d50bf 100644 --- a/specs/_features/eip7594/polynomial-commitments-sampling.md +++ b/specs/_features/eip7594/polynomial-commitments-sampling.md @@ -9,7 +9,6 @@ - [Introduction](#introduction) - [Public Methods](#public-methods) - [Custom types](#custom-types) -- [Constants](#constants) - [Preset](#preset) - [Cells](#cells) - [Helper functions](#helper-functions) @@ -77,11 +76,7 @@ The following is a list of the public methods: | `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 | | `CellIndex` | `uint64` | Validation: `x < CELLS_PER_EXT_BLOB` | - -## Constants - -| Name | Value | Notes | -| - | - | - | +| `CommitmentIndex` | `uint64` | The type which represents the index of an element in the list of commitments | ## Preset @@ -226,46 +221,30 @@ def coset_fft_field(vals: Sequence[BLSFieldElement], #### `compute_verify_cell_kzg_proof_batch_challenge` ```python -def compute_verify_cell_kzg_proof_batch_challenge(row_commitments: Sequence[KZGCommitment], - row_indices: Sequence[RowIndex], - column_indices: Sequence[ColumnIndex], +def compute_verify_cell_kzg_proof_batch_challenge(commitments: Sequence[KZGCommitment], + commitment_indices: Sequence[CommitmentIndex], + cell_indices: Sequence[CellIndex], cosets_evals: Sequence[CosetEvals], proofs: Sequence[KZGProof]) -> BLSFieldElement: """ - Compute a random challenge r used in the universal verification equation. - This is used in verify_cell_kzg_proof_batch_impl. - - To compute the challenge, `RANDOM_CHALLENGE_KZG_CELL_BATCH_DOMAIN` is used as a hash prefix. + Compute a random challenge ``r`` used in the universal verification equation. To compute the + challenge, ``RANDOM_CHALLENGE_KZG_CELL_BATCH_DOMAIN`` and all data that can influence the + verification is hashed together to deterministically generate a "random" field element via + the Fiat-Shamir heuristic. """ - # input the domain separator hashinput = RANDOM_CHALLENGE_KZG_CELL_BATCH_DOMAIN - - # input the degree bound of the polynomial hashinput += int.to_bytes(FIELD_ELEMENTS_PER_BLOB, 8, KZG_ENDIANNESS) - - # input the field elements per cell hashinput += int.to_bytes(FIELD_ELEMENTS_PER_CELL, 8, KZG_ENDIANNESS) - - # input the number of commitments - num_commitments = len(row_commitments) - hashinput += int.to_bytes(num_commitments, 8, KZG_ENDIANNESS) - - # input the number of cells - num_cells = len(row_indices) - hashinput += int.to_bytes(num_cells, 8, KZG_ENDIANNESS) - - # input all commitments - for commitment in row_commitments: + hashinput += int.to_bytes(len(commitments), 8, KZG_ENDIANNESS) + hashinput += int.to_bytes(len(cell_indices), 8, KZG_ENDIANNESS) + for commitment in commitments: hashinput += commitment - - # input each cell with its indices and proof - for k in range(num_cells): - hashinput += int.to_bytes(row_indices[k], 8, KZG_ENDIANNESS) - hashinput += int.to_bytes(column_indices[k], 8, KZG_ENDIANNESS) - for eval in cosets_evals[k]: - hashinput += bls_field_to_bytes(eval) + for k, coset_evals in enumerate(cosets_evals): + hashinput += int.to_bytes(commitment_indices[k], 8, KZG_ENDIANNESS) + hashinput += int.to_bytes(cell_indices[k], 8, KZG_ENDIANNESS) + for coset_eval in coset_evals: + hashinput += bls_field_to_bytes(coset_eval) hashinput += proofs[k] - return hash_to_bls_field(hashinput) ``` @@ -434,24 +413,25 @@ def compute_kzg_proof_multi_impl( #### `verify_cell_kzg_proof_batch_impl` ```python -def verify_cell_kzg_proof_batch_impl(row_commitments: Sequence[KZGCommitment], - row_indices: Sequence[RowIndex], - column_indices: Sequence[ColumnIndex], +def verify_cell_kzg_proof_batch_impl(commitments: Sequence[KZGCommitment], + commitment_indices: Sequence[CommitmentIndex], + cell_indices: Sequence[CellIndex], cosets_evals: Sequence[CosetEvals], proofs: Sequence[KZGProof]) -> bool: """ Helper: Verify that a set of cells belong to their corresponding commitment. - Given a list of ``row_commitments`` and four lists representing tuples of (``row_index``, - ``column_index``, ``evals``, ``proof``), the function verifies ``proof`` which shows that - ``evals`` are the evaluations of the polynomial associated with ``row_commitments[row_index]``, - evaluated over the domain specified by ``column_index``. + Given a list of ``commitments`` (which contains no duplicates) and four lists representing + tuples of (``commitment_index``, ``cell_index``, ``evals``, ``proof``), the function + verifies ``proof`` which shows that ``evals`` are the evaluations of the polynomial associated + with ``commitments[commitment_index]``, evaluated over the domain specified by ``cell_index``. This function is the internal implementation of ``verify_cell_kzg_proof_batch``. """ - assert len(row_indices) == len(column_indices) == len(cosets_evals) == len(proofs) - for row_index in row_indices: - assert row_index < len(row_commitments) + assert len(commitment_indices) == len(cell_indices) == len(cosets_evals) == len(proofs) + assert len(commitments) == len(set(commitments)) + for commitment_index in commitment_indices: + assert commitment_index < len(commitments) # The verification equation that we will check is pairing (LL, LR) = pairing (RL, [1]), where # LL = sum_k r^k proofs[k], @@ -462,25 +442,26 @@ def verify_cell_kzg_proof_batch_impl(row_commitments: Sequence[KZGCommitment], # RLP = sum_k (r^k * h_k^n) proofs[k] # # Here, the variables have the following meaning: - # - k < len(row_indices) is an index iterating over all cells in the input + # - k < len(cell_indices) is an index iterating over all cells in the input # - r is a random coefficient, derived from hashing all data provided by the prover # - s is the secret embedded in the KZG setup # - n = FIELD_ELEMENTS_PER_CELL is the size of the evaluation domain - # - i ranges over all rows that are touched - # - weights[i] is a weight computed for row i. It depends on r and on which cells are in row i + # - i ranges over all provided commitments + # - weights[i] is a weight computed for commitment i + # - It depends on r and on which cells are associated with commitment i # - interpolation_poly_k is the interpolation polynomial for the kth cell # - h_k is the coset shift specifying the evaluation domain of the kth cell # Preparation - num_cells = len(row_indices) + num_cells = len(cell_indices) n = FIELD_ELEMENTS_PER_CELL - num_rows = len(row_commitments) + num_commitments = len(commitments) # Step 1: Compute a challenge r and its powers r^0, ..., r^{num_cells-1} r = compute_verify_cell_kzg_proof_batch_challenge( - row_commitments, - row_indices, - column_indices, + commitments, + commitment_indices, + cell_indices, cosets_evals, proofs ) @@ -494,20 +475,20 @@ def verify_cell_kzg_proof_batch_impl(row_commitments: Sequence[KZGCommitment], # Step 4: Compute RL = RLC - RLI + RLP # Step 4.1: Compute RLC = sum_i weights[i] commitments[i] - # Step 4.1a: Compute weights[i]: the sum of all r^k for which cell k is in row i. + # Step 4.1a: Compute weights[i]: the sum of all r^k for which cell k is associated with commitment i. # Note: we do that by iterating over all k and updating the correct weights[i] accordingly - weights = [0] * num_rows + weights = [0] * num_commitments for k in range(num_cells): - i = row_indices[k] + i = commitment_indices[k] weights[i] = (weights[i] + int(r_powers[k])) % BLS_MODULUS # Step 4.1b: Linearly combine the weights with the commitments to get RLC - rlc = bls.bytes48_to_G1(g1_lincomb(row_commitments, weights)) + rlc = bls.bytes48_to_G1(g1_lincomb(commitments, weights)) # Step 4.2: Compute RLI = [sum_k r^k interpolation_poly_k(s)] # Note: an efficient implementation would use the IDFT based method explained in the blog post sum_interp_polys_coeff = [0] * n for k in range(num_cells): - interp_poly_coeff = interpolate_polynomialcoeff(coset_for_cell(column_indices[k]), cosets_evals[k]) + interp_poly_coeff = interpolate_polynomialcoeff(coset_for_cell(cell_indices[k]), cosets_evals[k]) interp_poly_scaled_coeff = multiply_polynomialcoeff([r_powers[k]], interp_poly_coeff) sum_interp_polys_coeff = add_polynomialcoeff(sum_interp_polys_coeff, interp_poly_scaled_coeff) rli = bls.bytes48_to_G1(g1_lincomb(KZG_SETUP_G1_MONOMIAL[:n], sum_interp_polys_coeff)) @@ -515,7 +496,7 @@ def verify_cell_kzg_proof_batch_impl(row_commitments: Sequence[KZGCommitment], # Step 4.3: Compute RLP = sum_k (r^k * h_k^n) proofs[k] weighted_r_powers = [] for k in range(num_cells): - h_k = int(coset_shift_for_cell(column_indices[k])) + h_k = int(coset_shift_for_cell(cell_indices[k])) h_k_pow = pow(h_k, n, BLS_MODULUS) wrp = (int(r_powers[k]) * h_k_pow) % BLS_MODULUS weighted_r_powers.append(wrp) @@ -610,15 +591,15 @@ def compute_cells_and_kzg_proofs(blob: Blob) -> Tuple[ ```python def verify_cell_kzg_proof_batch(commitments_bytes: Sequence[Bytes48], - column_indices: Sequence[ColumnIndex], + cell_indices: Sequence[CellIndex], cells: Sequence[Cell], proofs_bytes: Sequence[Bytes48]) -> bool: """ Verify that a set of cells belong to their corresponding commitments. - Given four lists representing tuples of (``commitment``, ``column_index``, ``cell``, ``proof``), + Given four lists representing tuples of (``commitment``, ``cell_index``, ``cell``, ``proof``), the function verifies ``proof`` which shows that ``cell`` are the evaluations of the polynomial - associated with ``commitment``, evaluated over the domain specified by ``column_index``. + associated with ``commitment``, evaluated over the domain specified by ``cell_index``. This function implements the universal verification equation that has been introduced here: https://ethresear.ch/t/a-universal-verification-equation-for-data-availability-sampling/13240 @@ -626,27 +607,32 @@ def verify_cell_kzg_proof_batch(commitments_bytes: Sequence[Bytes48], Public method. """ - assert len(commitments_bytes) == len(cells) == len(proofs_bytes) == len(column_indices) + assert len(commitments_bytes) == len(cells) == len(proofs_bytes) == len(cell_indices) for commitment_bytes in commitments_bytes: assert len(commitment_bytes) == BYTES_PER_COMMITMENT - for column_index in column_indices: - assert column_index < CELLS_PER_EXT_BLOB + for cell_index in cell_indices: + assert cell_index < CELLS_PER_EXT_BLOB for cell in cells: assert len(cell) == BYTES_PER_CELL for proof_bytes in proofs_bytes: assert len(proof_bytes) == BYTES_PER_PROOF - # Create the list of unique commitments we are dealing with - deduplicated_commitments = list(set(commitments_bytes)) - row_commitments = [bytes_to_kzg_commitment(commitment_bytes) for commitment_bytes in deduplicated_commitments] - # Create indices list mapping initial commitments (that potentially contains duplicates) to the unique commitments. - row_indices = [deduplicated_commitments.index(commitment_bytes) for commitment_bytes in commitments_bytes] + # Create the list of deduplicated commitments we are dealing with + deduplicated_commitments = [bytes_to_kzg_commitment(commitment_bytes) + for commitment_bytes in set(commitments_bytes)] + # Create indices list mapping initial commitments (that may contain duplicates) to the deduplicated commitments + commitment_indices = [deduplicated_commitments.index(commitment_bytes) for commitment_bytes in commitments_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] # Do the actual verification - return verify_cell_kzg_proof_batch_impl(row_commitments, row_indices, column_indices, cosets_evals, proofs) + return verify_cell_kzg_proof_batch_impl( + deduplicated_commitments, + commitment_indices, + cell_indices, + cosets_evals, + proofs) ``` ## Reconstruction 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 1e8d86f6e..c68c60676 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 @@ -115,7 +115,7 @@ def test_verify_cell_kzg_proof_batch_zero_cells(spec): # Verify with zero cells should return true assert spec.verify_cell_kzg_proof_batch( commitments_bytes=[], - column_indices=[], + cell_indices=[], cells=[], proofs_bytes=[], ) @@ -135,7 +135,7 @@ def test_verify_cell_kzg_proof_batch(spec): assert spec.verify_cell_kzg_proof_batch( commitments_bytes=[commitment, commitment], - column_indices=[0, 4], + cell_indices=[0, 4], cells=[cells[0], cells[4]], proofs_bytes=[proofs[0], proofs[4]], ) @@ -158,16 +158,16 @@ def test_verify_cell_kzg_proof_batch(spec): all_proofs.append(proofs) # the cells of interest - row_indices = [0, 0, 1, 2, 1] - column_indices = [0, 4, 0, 1, 2] - cells = [all_cells[i][j] for (i, j) in zip(row_indices, column_indices)] - proofs = [all_proofs[i][j] for (i, j) in zip(row_indices, column_indices)] - commitments = [all_commitments[i] for i in row_indices] + commitment_indices = [0, 0, 1, 2, 1] + cell_indices = [0, 4, 0, 1, 2] + cells = [all_cells[i][j] for (i, j) in zip(commitment_indices, cell_indices)] + proofs = [all_proofs[i][j] for (i, j) in zip(commitment_indices, cell_indices)] + commitments = [all_commitments[i] for i in commitment_indices] # do the check assert spec.verify_cell_kzg_proof_batch( commitments_bytes=commitments, - column_indices=column_indices, + cell_indices=cell_indices, cells=cells, proofs_bytes=proofs, ) @@ -187,7 +187,7 @@ def test_verify_cell_kzg_proof_batch_invalid(spec): assert not spec.verify_cell_kzg_proof_batch( commitments_bytes=[commitment, commitment], - column_indices=[0, 4], + cell_indices=[0, 4], cells=[cells[0], cells[5]], # Note: this is where it should go wrong proofs_bytes=[proofs[0], proofs[4]], ) @@ -210,11 +210,11 @@ def test_verify_cell_kzg_proof_batch_invalid(spec): all_proofs.append(proofs) # the cells of interest - row_indices = [0, 0, 1, 2, 1] - column_indices = [0, 4, 0, 1, 2] - cells = [all_cells[i][j] for (i, j) in zip(row_indices, column_indices)] - proofs = [all_proofs[i][j] for (i, j) in zip(row_indices, column_indices)] - commitments = [all_commitments[i] for i in row_indices] + commitment_indices = [0, 0, 1, 2, 1] + cell_indices = [0, 4, 0, 1, 2] + cells = [all_cells[i][j] for (i, j) in zip(commitment_indices, cell_indices)] + proofs = [all_proofs[i][j] for (i, j) in zip(commitment_indices, cell_indices)] + commitments = [all_commitments[i] for i in commitment_indices] # let's change one of the cells. Then it should not verify cells[1] = all_cells[1][3] @@ -222,7 +222,7 @@ def test_verify_cell_kzg_proof_batch_invalid(spec): # do the check assert not spec.verify_cell_kzg_proof_batch( commitments_bytes=commitments, - column_indices=column_indices, + cell_indices=cell_indices, cells=cells, proofs_bytes=proofs, ) diff --git a/tests/formats/kzg_7594/verify_cell_kzg_proof_batch.md b/tests/formats/kzg_7594/verify_cell_kzg_proof_batch.md index 270ad3e89..84bfaa1c2 100644 --- a/tests/formats/kzg_7594/verify_cell_kzg_proof_batch.md +++ b/tests/formats/kzg_7594/verify_cell_kzg_proof_batch.md @@ -9,14 +9,14 @@ The test data is declared in a `data.yaml` file: ```yaml input: commitments: List[Bytes48] -- the KZG commitments for each cell - column_indices: List[ColumnIndex] -- the column index for each cell + cell_indices: List[CellIndex] -- the cell index for each cell cells: List[Cell] -- the cells proofs: List[Bytes48] -- the KZG proof for each cell output: bool -- true (all proofs are correct) or false (some proofs incorrect) ``` - `Bytes48` is a 48-byte hexadecimal string, prefixed with `0x`. -- `ColumnIndex` is an unsigned 64-bit integer. +- `CellIndex` is an unsigned 64-bit integer. - `Cell` is a 2048-byte hexadecimal string, prefixed with `0x`. All byte(s) fields are encoded as strings, hexadecimal encoding, prefixed with `0x`. diff --git a/tests/generators/kzg_7594/main.py b/tests/generators/kzg_7594/main.py index f21fa4125..d96c67744 100644 --- a/tests/generators/kzg_7594/main.py +++ b/tests/generators/kzg_7594/main.py @@ -66,13 +66,13 @@ def case_verify_cell_kzg_proof_batch(): for i in range(len(VALID_BLOBS)): cells, proofs = VALID_CELLS_AND_PROOFS[i] commitments = [VALID_COMMITMENTS[i] for _ in cells] - column_indices = list(range(spec.CELLS_PER_EXT_BLOB)) - assert spec.verify_cell_kzg_proof_batch(commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + cell_indices = list(range(spec.CELLS_PER_EXT_BLOB)) + assert spec.verify_cell_kzg_proof_batch(commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_valid_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, @@ -80,13 +80,13 @@ def case_verify_cell_kzg_proof_batch(): } # Valid: zero cells - cells, commitments, column_indices, proofs = [], [], [], [] - assert spec.verify_cell_kzg_proof_batch(commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + cells, commitments, cell_indices, proofs = [], [], [], [] + assert spec.verify_cell_kzg_proof_batch(commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_valid_zero_cells_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, @@ -97,15 +97,15 @@ def case_verify_cell_kzg_proof_batch(): cells0, proofs0 = VALID_CELLS_AND_PROOFS[0] cells1, proofs1 = VALID_CELLS_AND_PROOFS[1] commitments = [VALID_COMMITMENTS[0], VALID_COMMITMENTS[1]] - column_indices = [0, 0] + cell_indices = [0, 0] cells = [cells0[0], cells1[0]] proofs = [proofs0[0], proofs1[0]] - assert spec.verify_cell_kzg_proof_batch(commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + assert spec.verify_cell_kzg_proof_batch(commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_valid_multiple_blobs_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, @@ -115,15 +115,15 @@ def case_verify_cell_kzg_proof_batch(): # Valid: Same cell multiple times num_duplicates = 3 commitments = [VALID_COMMITMENTS[3]] * num_duplicates - column_indices = [0] * num_duplicates + cell_indices = [0] * num_duplicates cells = [VALID_CELLS_AND_PROOFS[3][0][0]] * num_duplicates proofs = [VALID_CELLS_AND_PROOFS[3][1][0]] * num_duplicates - assert spec.verify_cell_kzg_proof_batch(commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + assert spec.verify_cell_kzg_proof_batch(commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_valid_same_cell_multiple_times_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, @@ -135,13 +135,13 @@ def case_verify_cell_kzg_proof_batch(): cells, proofs = cells[:1], proofs[:1] # Use the wrong commitment commitments = [bls_add_one(VALID_COMMITMENTS[5])] - column_indices = list(range(len(cells))) - assert not spec.verify_cell_kzg_proof_batch(commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + cell_indices = list(range(len(cells))) + assert not spec.verify_cell_kzg_proof_batch(commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_incorrect_commitment_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, @@ -152,15 +152,15 @@ def case_verify_cell_kzg_proof_batch(): cells, proofs = VALID_CELLS_AND_PROOFS[6] cells, proofs = cells[:1], proofs[:1] commitments = [VALID_COMMITMENTS[6]] - column_indices = list(range(len(cells))) + cell_indices = list(range(len(cells))) # Change last cell so it's wrong cells[-1] = CELL_RANDOM_VALID2 - assert not spec.verify_cell_kzg_proof_batch(commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + assert not spec.verify_cell_kzg_proof_batch(commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_incorrect_cell_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, @@ -171,15 +171,15 @@ def case_verify_cell_kzg_proof_batch(): cells, proofs = VALID_CELLS_AND_PROOFS[0] cells, proofs = cells[:1], proofs[:1] commitments = [VALID_COMMITMENTS[0]] - column_indices = list(range(len(cells))) + cell_indices = list(range(len(cells))) # Change last proof so it's wrong proofs[-1] = bls_add_one(proofs[-1]) - assert not spec.verify_cell_kzg_proof_batch(commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + assert not spec.verify_cell_kzg_proof_batch(commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_incorrect_proof_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, @@ -192,32 +192,32 @@ def case_verify_cell_kzg_proof_batch(): cells, proofs = cells[:1], proofs[:1] # Set commitments to the invalid commitment commitments = [commitment] - column_indices = list(range(len(cells))) - expect_exception(spec.verify_cell_kzg_proof_batch, commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + cell_indices = list(range(len(cells))) + expect_exception(spec.verify_cell_kzg_proof_batch, commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_invalid_commitment_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, 'output': None } - # Edge case: Invalid column_index + # Edge case: Invalid cell_index cells, proofs = VALID_CELLS_AND_PROOFS[1] cells, proofs = cells[:1], proofs[:1] commitments = [VALID_COMMITMENTS[1]] - column_indices = list(range(len(cells))) - # Set first column index to an invalid value - column_indices[0] = spec.CELLS_PER_EXT_BLOB - expect_exception(spec.verify_cell_kzg_proof_batch, commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) - yield f'verify_cell_kzg_proof_batch_case_invalid_column_index_{identifier}', { + cell_indices = list(range(len(cells))) + # Set first cell index to an invalid value + cell_indices[0] = spec.CELLS_PER_EXT_BLOB + expect_exception(spec.verify_cell_kzg_proof_batch, commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) + yield f'verify_cell_kzg_proof_batch_case_invalid_cell_index_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, @@ -229,15 +229,15 @@ def case_verify_cell_kzg_proof_batch(): cells, proofs = VALID_CELLS_AND_PROOFS[i % len(INVALID_INDIVIDUAL_CELL_BYTES)] cells, proofs = cells[:1], proofs[:1] commitments = [VALID_COMMITMENTS[i % len(INVALID_INDIVIDUAL_CELL_BYTES)]] - column_indices = list(range(len(cells))) + cell_indices = list(range(len(cells))) # Set first cell to the invalid cell cells[0] = cell - expect_exception(spec.verify_cell_kzg_proof_batch, commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_invalid_cell_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, @@ -249,15 +249,15 @@ def case_verify_cell_kzg_proof_batch(): cells, proofs = VALID_CELLS_AND_PROOFS[i % len(INVALID_G1_POINTS)] cells, proofs = cells[:1], proofs[:1] commitments = [VALID_COMMITMENTS[i % len(INVALID_G1_POINTS)]] - column_indices = list(range(len(cells))) + cell_indices = list(range(len(cells))) # Set first proof to the invalid proof proofs[0] = proof - expect_exception(spec.verify_cell_kzg_proof_batch, commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_invalid_proof_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, @@ -269,31 +269,31 @@ def case_verify_cell_kzg_proof_batch(): cells, proofs = cells[:2], proofs[:2] # Do not include the second commitment commitments = [VALID_COMMITMENTS[0]] - column_indices = list(range(len(cells))) - expect_exception(spec.verify_cell_kzg_proof_batch, commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + cell_indices = list(range(len(cells))) + expect_exception(spec.verify_cell_kzg_proof_batch, commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_invalid_missing_commitment_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, 'output': None } - # Edge case: Missing a column index + # Edge case: Missing a cell index cells, proofs = VALID_CELLS_AND_PROOFS[2] cells, proofs = cells[:2], proofs[:2] commitments = [VALID_COMMITMENTS[2], VALID_COMMITMENTS[2]] - # Leave off one of the column indices - column_indices = list(range(len(cells) - 1)) - expect_exception(spec.verify_cell_kzg_proof_batch, commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) - yield f'verify_cell_kzg_proof_batch_case_invalid_missing_column_index_{identifier}', { + # Leave off one of the cell indices + cell_indices = list(range(len(cells) - 1)) + expect_exception(spec.verify_cell_kzg_proof_batch, commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) + yield f'verify_cell_kzg_proof_batch_case_invalid_missing_cell_index_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, @@ -304,15 +304,15 @@ def case_verify_cell_kzg_proof_batch(): cells, proofs = VALID_CELLS_AND_PROOFS[3] cells, proofs = cells[:2], proofs[:2] commitments = [VALID_COMMITMENTS[3], VALID_COMMITMENTS[3]] - column_indices = list(range(len(cells))) + cell_indices = list(range(len(cells))) # Remove the last proof cells = cells[:-1] - expect_exception(spec.verify_cell_kzg_proof_batch, commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_invalid_missing_cell_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), }, @@ -323,15 +323,15 @@ def case_verify_cell_kzg_proof_batch(): cells, proofs = VALID_CELLS_AND_PROOFS[4] cells, proofs = cells[:2], proofs[:2] commitments = [VALID_COMMITMENTS[4], VALID_COMMITMENTS[4]] - column_indices = list(range(len(cells))) + cell_indices = list(range(len(cells))) # Remove the last proof proofs = proofs[:-1] - expect_exception(spec.verify_cell_kzg_proof_batch, commitments, column_indices, cells, proofs) - identifier = make_id(commitments, column_indices, cells, proofs) + expect_exception(spec.verify_cell_kzg_proof_batch, commitments, cell_indices, cells, proofs) + identifier = make_id(commitments, cell_indices, cells, proofs) yield f'verify_cell_kzg_proof_batch_case_invalid_missing_proof_{identifier}', { 'input': { 'commitments': encode_hex_list(commitments), - 'column_indices': column_indices, + 'cell_indices': cell_indices, 'cells': encode_hex_list(cells), 'proofs': encode_hex_list(proofs), },