Skip to content

Commit

Permalink
Merge pull request #3830 from jtraglia/remove-verify-cell-kzg-proof
Browse files Browse the repository at this point in the history
Remove `verify_cell_kzg_proof` (non-batch)
  • Loading branch information
asn-d6 authored Jul 10, 2024
2 parents 9a9fa96 + c402414 commit dc5f74d
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 264 deletions.
67 changes: 0 additions & 67 deletions specs/_features/eip7594/polynomial-commitments-sampling.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
- [`evaluate_polynomialcoeff`](#evaluate_polynomialcoeff)
- [KZG multiproofs](#kzg-multiproofs)
- [`compute_kzg_proof_multi_impl`](#compute_kzg_proof_multi_impl)
- [`verify_kzg_proof_multi_impl`](#verify_kzg_proof_multi_impl)
- [`verify_cell_kzg_proof_batch_impl`](#verify_cell_kzg_proof_batch_impl)
- [Cell cosets](#cell-cosets)
- [`coset_shift_for_cell`](#coset_shift_for_cell)
Expand All @@ -43,7 +42,6 @@
- [Cell computation](#cell-computation)
- [`compute_cells_and_kzg_proofs`](#compute_cells_and_kzg_proofs)
- [Cell verification](#cell-verification)
- [`verify_cell_kzg_proof`](#verify_cell_kzg_proof)
- [`verify_cell_kzg_proof_batch`](#verify_cell_kzg_proof_batch)
- [Reconstruction](#reconstruction)
- [`construct_vanishing_polynomial`](#construct_vanishing_polynomial)
Expand Down Expand Up @@ -433,45 +431,6 @@ def compute_kzg_proof_multi_impl(
return KZGProof(g1_lincomb(KZG_SETUP_G1_MONOMIAL[:len(quotient_polynomial)], quotient_polynomial)), ys
```

#### `verify_kzg_proof_multi_impl`

```python
def verify_kzg_proof_multi_impl(commitment: KZGCommitment,
zs: Coset,
ys: CosetEvals,
proof: KZGProof) -> bool:
"""
Verify a KZG multi-evaluation proof for a set of `k` points.
This is done by checking if the following equation holds:
Q(x) Z(x) = f(X) - I(X)
Where:
f(X) is the polynomial that we want to verify opens at `k` points to `k` values
Q(X) is the quotient polynomial computed by the prover
I(X) is the degree k-1 polynomial that evaluates to `ys` at all `zs`` points
Z(X) is the polynomial that evaluates to zero on all `k` points
The verifier receives the commitments to Q(X) and f(X), so they check the equation
holds by using the following pairing equation:
e([Q(X)]_1, [Z(X)]_2) == e([f(X)]_1 - [I(X)]_1, [1]_2)
"""

assert len(zs) == len(ys)

# Compute [Z(X)]_2
zero_poly = g2_lincomb(KZG_SETUP_G2_MONOMIAL[:len(zs) + 1], vanishing_polynomialcoeff(zs))
# Compute [I(X)]_1
interpolated_poly = g1_lincomb(KZG_SETUP_G1_MONOMIAL[:len(zs)], interpolate_polynomialcoeff(zs, ys))

return (bls.pairing_check([
[bls.bytes48_to_G1(proof), bls.bytes96_to_G2(zero_poly)],
[
bls.add(bls.bytes48_to_G1(commitment), bls.neg(bls.bytes48_to_G1(interpolated_poly))),
bls.neg(bls.bytes96_to_G2(KZG_SETUP_G2_MONOMIAL[0])),
],
]))
```

#### `verify_cell_kzg_proof_batch_impl`

```python
Expand Down Expand Up @@ -647,32 +606,6 @@ def compute_cells_and_kzg_proofs(blob: Blob) -> Tuple[

### Cell verification

#### `verify_cell_kzg_proof`

```python
def verify_cell_kzg_proof(commitment_bytes: Bytes48,
cell_index: CellIndex,
cell: Cell,
proof_bytes: Bytes48) -> bool:
"""
Check a cell proof
Public method.
"""
assert len(commitment_bytes) == BYTES_PER_COMMITMENT
assert cell_index < CELLS_PER_EXT_BLOB
assert len(cell) == BYTES_PER_CELL
assert len(proof_bytes) == BYTES_PER_PROOF

coset = coset_for_cell(cell_index)

return verify_kzg_proof_multi_impl(
bytes_to_kzg_commitment(commitment_bytes),
coset,
cell_to_coset_evals(cell),
bytes_to_kzg_proof(proof_bytes))
```

#### `verify_cell_kzg_proof_batch`

```python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,6 @@ def test_construct_vanishing_polynomial(spec):
assert all(a != 0 for a in zero_poly_eval_brp[start:end])


@with_eip7594_and_later
@spec_test
@single_phase
def test_verify_cell_kzg_proof(spec):
blob = get_sample_blob(spec)
commitment = spec.blob_to_kzg_commitment(blob)
cells, proofs = spec.compute_cells_and_kzg_proofs(blob)

cell_index = 0
assert spec.verify_cell_kzg_proof(commitment, cell_index, cells[cell_index], proofs[cell_index])
cell_index = 1
assert spec.verify_cell_kzg_proof(commitment, cell_index, cells[cell_index], proofs[cell_index])


@with_eip7594_and_later
@spec_test
@single_phase
Expand Down
1 change: 0 additions & 1 deletion tests/formats/kzg_7594/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ The KZG test suite runner has the following handlers:

- [`compute_cells`](./compute_cells.md)
- [`compute_cells_and_kzg_proofs`](./compute_cells_and_kzg_proofs.md)
- [`verify_cell_kzg_proof`](./verify_cell_kzg_proof.md)
- [`verify_cell_kzg_proof_batch`](./verify_cell_kzg_proof_batch.md)
- [`recover_all_cells`](./recover_all_cells.md)
26 changes: 0 additions & 26 deletions tests/formats/kzg_7594/verify_cell_kzg_proof.md

This file was deleted.

156 changes: 0 additions & 156 deletions tests/generators/kzg_7594/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
VALID_BLOBS,
VALID_CELLS_AND_PROOFS,
VALID_COMMITMENTS,
VALID_INDIVIDUAL_RANDOM_CELL_BYTES,
bls_add_one,
encode_hex_list,
expect_exception,
Expand Down Expand Up @@ -58,160 +57,6 @@ def case_compute_cells_and_kzg_proofs():
}


###############################################################################
# Test cases for verify_cell_kzg_proof
###############################################################################

def case_verify_cell_kzg_proof():
# Valid cases
for i in range(len(VALID_BLOBS)):
cells, proofs = VALID_CELLS_AND_PROOFS[i]
commitment = VALID_COMMITMENTS[i]
cell_index = (2 ** i - 1) % spec.CELLS_PER_EXT_BLOB
cell = cells[cell_index]
proof = proofs[cell_index]
assert spec.verify_cell_kzg_proof(commitment, cell_index, cell, proof)
identifier = make_id(commitment, cell_index, cell, proof)
yield f'verify_cell_kzg_proof_case_valid_{identifier}', {
'input': {
'commitment': encode_hex(commitment),
'cell_index': cell_index,
'cell': encode_hex(cell),
'proof': encode_hex(proof),
},
'output': True
}

# Incorrect commitment
for i in range(len(VALID_BLOBS)):
cells, proofs = VALID_CELLS_AND_PROOFS[i]
commitment = bls_add_one(VALID_COMMITMENTS[i])
cell_index = 99 % spec.CELLS_PER_EXT_BLOB
cell = cells[cell_index]
proof = proofs[cell_index]
assert not spec.verify_cell_kzg_proof(commitment, cell_index, cell, proof)
identifier = make_id(commitment, cell_index, cell, proof)
yield f'verify_cell_kzg_proof_case_incorrect_commitment_{identifier}', {
'input': {
'commitment': encode_hex(commitment),
'cell_index': cell_index,
'cell': encode_hex(cell),
'proof': encode_hex(proof),
},
'output': False
}

# Incorrect cell
for i in range(len(VALID_INDIVIDUAL_RANDOM_CELL_BYTES)):
cell_index = 16 % spec.CELLS_PER_EXT_BLOB
commitment = VALID_COMMITMENTS[i]
cells, proofs = VALID_CELLS_AND_PROOFS[i]
cell = VALID_INDIVIDUAL_RANDOM_CELL_BYTES[i]
proof = proofs[cell_index]
assert not spec.verify_cell_kzg_proof(commitment, cell_index, cell, proof)
identifier = make_id(commitment, cell_index, cell, proof)
yield f'verify_cell_kzg_proof_case_incorrect_cell_{identifier}', {
'input': {
'commitment': encode_hex(commitment),
'cell_index': cell_index,
'cell': encode_hex(cell),
'proof': encode_hex(proof),
},
'output': False
}

# Incorrect proof
for i in range(len(VALID_BLOBS)):
cell_index = 91 % spec.CELLS_PER_EXT_BLOB
commitment = VALID_COMMITMENTS[i]
cells, proofs = VALID_CELLS_AND_PROOFS[i]
cell = cells[cell_index]
proof = bls_add_one(proofs[cell_index])
assert not spec.verify_cell_kzg_proof(commitment, cell_index, cell, proof)
identifier = make_id(commitment, cell_index, cell, proof)
yield f'verify_cell_kzg_proof_case_incorrect_proof_{identifier}', {
'input': {
'commitment': encode_hex(commitment),
'cell_index': cell_index,
'cell': encode_hex(cell),
'proof': encode_hex(proof),
},
'output': False
}

# Edge case: Invalid commitment
for commitment in INVALID_G1_POINTS:
cells, proofs = VALID_CELLS_AND_PROOFS[0]
cell_index = 81 % spec.CELLS_PER_EXT_BLOB
cell = cells[cell_index]
proof = proofs[cell_index]
expect_exception(spec.verify_cell_kzg_proof, commitment, cell_index, cell, proof)
identifier = make_id(commitment, cell_index, cell, proof)
yield f'verify_cell_kzg_proof_case_invalid_commitment_{identifier}', {
'input': {
'commitment': encode_hex(commitment),
'cell_index': cell_index,
'cell': encode_hex(cell),
'proof': encode_hex(proof),
},
'output': None
}

# Edge case: Invalid cell_index
for cell_index in [spec.CELLS_PER_EXT_BLOB, spec.CELLS_PER_EXT_BLOB + 1]:
cells, proofs = VALID_CELLS_AND_PROOFS[1]
commitment = VALID_COMMITMENTS[1]
cell = cells[0]
proof = proofs[0]
expect_exception(spec.verify_cell_kzg_proof, commitment, cell_index, cell, proof)
identifier = make_id(commitment, cell_index, cell, proof)
yield f'verify_cell_kzg_proof_case_invalid_cell_index_{identifier}', {
'input': {
'commitment': encode_hex(commitment),
'cell_index': cell_index,
'cell': encode_hex(cell),
'proof': encode_hex(proof),
},
'output': None
}

# Edge case: Invalid cell
for cell in INVALID_INDIVIDUAL_CELL_BYTES:
cell_index = 32 % spec.CELLS_PER_EXT_BLOB
commitment = VALID_COMMITMENTS[2]
cells, proofs = VALID_CELLS_AND_PROOFS[2]
proof = proofs[cell_index]
expect_exception(spec.verify_cell_kzg_proof, commitment, cell_index, cell, proof)
identifier = make_id(commitment, cell_index, cell, proof)
yield f'verify_cell_kzg_proof_case_invalid_cell_{identifier}', {
'input': {
'commitment': encode_hex(commitment),
'cell_index': cell_index,
'cell': encode_hex(cell),
'proof': encode_hex(proof),
},
'output': None
}

# Edge case: Invalid proof
for proof in INVALID_G1_POINTS:
cells, _ = VALID_CELLS_AND_PROOFS[3]
commitment = VALID_COMMITMENTS[3]
cell_index = 36 % spec.CELLS_PER_EXT_BLOB
cell = cells[cell_index]
expect_exception(spec.verify_cell_kzg_proof, commitment, cell_index, cell, proof)
identifier = make_id(commitment, cell_index, cell, proof)
yield f'verify_cell_kzg_proof_case_invalid_proof_{identifier}', {
'input': {
'commitment': encode_hex(commitment),
'cell_index': cell_index,
'cell': encode_hex(cell),
'proof': encode_hex(proof),
},
'output': None
}


###############################################################################
# Test cases for verify_cell_kzg_proof_batch
###############################################################################
Expand Down Expand Up @@ -722,7 +567,6 @@ def cases_fn() -> Iterable[gen_typing.TestCase]:
gen_runner.run_generator("kzg_7594", [
# EIP-7594
create_provider(EIP7594, 'compute_cells_and_kzg_proofs', case_compute_cells_and_kzg_proofs),
create_provider(EIP7594, 'verify_cell_kzg_proof', case_verify_cell_kzg_proof),
create_provider(EIP7594, 'verify_cell_kzg_proof_batch', case_verify_cell_kzg_proof_batch),
create_provider(EIP7594, 'recover_cells_and_kzg_proofs', case_recover_cells_and_kzg_proofs),
])

0 comments on commit dc5f74d

Please sign in to comment.