From 7da61a9377bc40f3a5b29012d3ae743bfcb4ff49 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Tue, 24 Jan 2023 11:29:37 +0100 Subject: [PATCH 1/2] EIP4844: compute_kzg_proof() now takes bytes as input --- specs/eip4844/polynomial-commitments.md | 17 ++++++++++++++--- .../test_polynomial_commitments.py | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/specs/eip4844/polynomial-commitments.md b/specs/eip4844/polynomial-commitments.md index 26ee00487e..7947ba522e 100644 --- a/specs/eip4844/polynomial-commitments.md +++ b/specs/eip4844/polynomial-commitments.md @@ -370,12 +370,23 @@ def verify_kzg_proof_impl(polynomial_kzg: KZGCommitment, #### `compute_kzg_proof` ```python -def compute_kzg_proof(polynomial: Polynomial, z: BLSFieldElement) -> KZGProof: +def compute_kzg_proof(blob: Blob, z: Bytes32) -> KZGProof: """ - Compute KZG proof at point `z` with `polynomial` being in evaluation form. + Compute KZG proof at point `z` for the polynomial represented by `blob`. Do this by computing the quotient polynomial in evaluation form: q(x) = (p(x) - p(z)) / (x - z). Public method. """ + polynomial = blob_to_polynomial(blob) + return compute_kzg_proof_impl(polynomial, bytes_to_bls_field(z)) +``` + +#### `compute_kzg_proof_impl` + +```python +def compute_kzg_proof_impl(polynomial: Polynomial, z: BLSFieldElement) -> KZGProof: + """ + Helper function for compute_kzg_proof(). + """ y = evaluate_polynomial_in_evaluation_form(polynomial, z) polynomial_shifted = [BLSFieldElement((int(p) - int(y)) % BLS_MODULUS) for p in polynomial] @@ -430,7 +441,7 @@ def compute_aggregate_kzg_proof(blobs: Sequence[Blob]) -> KZGProof: blobs, commitments ) - return compute_kzg_proof(aggregated_poly, evaluation_challenge) + return compute_kzg_proof_impl(aggregated_poly, evaluation_challenge) ``` #### `verify_aggregate_kzg_proof` diff --git a/tests/core/pyspec/eth2spec/test/eip4844/unittests/polynomial_commitments/test_polynomial_commitments.py b/tests/core/pyspec/eth2spec/test/eip4844/unittests/polynomial_commitments/test_polynomial_commitments.py index 24b45475e2..04f5857f31 100644 --- a/tests/core/pyspec/eth2spec/test/eip4844/unittests/polynomial_commitments/test_polynomial_commitments.py +++ b/tests/core/pyspec/eth2spec/test/eip4844/unittests/polynomial_commitments/test_polynomial_commitments.py @@ -18,7 +18,7 @@ def test_verify_kzg_proof(spec, state): blob = get_sample_blob(spec) commitment = spec.blob_to_kzg_commitment(blob) polynomial = spec.blob_to_polynomial(blob) - proof = spec.compute_kzg_proof(polynomial, x) + proof = spec.compute_kzg_proof_impl(polynomial, x) y = spec.evaluate_polynomial_in_evaluation_form(polynomial, x) assert spec.verify_kzg_proof_impl(commitment, x, y, proof) From f56456f94e515d893c74e9d8bb5c6c0427a0710c Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Tue, 24 Jan 2023 11:50:18 +0100 Subject: [PATCH 2/2] fixup! EIP4844: compute_kzg_proof() now takes bytes as input --- specs/eip4844/polynomial-commitments.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/specs/eip4844/polynomial-commitments.md b/specs/eip4844/polynomial-commitments.md index 7947ba522e..53293cee8a 100644 --- a/specs/eip4844/polynomial-commitments.md +++ b/specs/eip4844/polynomial-commitments.md @@ -35,6 +35,7 @@ - [`verify_kzg_proof`](#verify_kzg_proof) - [`verify_kzg_proof_impl`](#verify_kzg_proof_impl) - [`compute_kzg_proof`](#compute_kzg_proof) + - [`compute_kzg_proof_impl`](#compute_kzg_proof_impl) - [`compute_aggregated_poly_and_commitment`](#compute_aggregated_poly_and_commitment) - [`compute_aggregate_kzg_proof`](#compute_aggregate_kzg_proof) - [`verify_aggregate_kzg_proof`](#verify_aggregate_kzg_proof) @@ -385,7 +386,7 @@ def compute_kzg_proof(blob: Blob, z: Bytes32) -> KZGProof: ```python def compute_kzg_proof_impl(polynomial: Polynomial, z: BLSFieldElement) -> KZGProof: """ - Helper function for compute_kzg_proof(). + Helper function for compute_kzg_proof() and compute_aggregate_kzg_proof(). """ y = evaluate_polynomial_in_evaluation_form(polynomial, z) polynomial_shifted = [BLSFieldElement((int(p) - int(y)) % BLS_MODULUS) for p in polynomial]