diff --git a/specs/eip4844/polynomial-commitments.md b/specs/eip4844/polynomial-commitments.md index 012237ae08..3504607764 100644 --- a/specs/eip4844/polynomial-commitments.md +++ b/specs/eip4844/polynomial-commitments.md @@ -294,12 +294,42 @@ def compute_aggregated_poly_and_commitment( return aggregated_poly, aggregated_poly_commitment ``` +#### `compute_aggregate_kzg_proof` + +```python +def compute_aggregate_kzg_proof(blobs: Sequence[Blob]) -> KZGProof: + commitments = [blob_to_kzg_commitment(blob) for blob in blobs] + aggregated_poly, aggregated_poly_commitment = compute_aggregated_poly_and_commitment(blobs, commitments) + x = hash_to_bls_field([aggregated_poly],[aggregated_poly_commitment]) + return compute_kzg_proof(aggregated_poly, x) +``` + +#### `verify_aggregate_kzg_proof` + +```python +def verify_aggregate_kzg_proof(blobs: Sequence[Blob], + expected_kzg_commitments: Sequence[KZGCommitment], + kzg_aggregated_proof : KZGCommitment) -> bool: + aggregated_poly, aggregated_poly_commitment = compute_aggregated_poly_and_commitment( + blobs, + expected_kzg_commitments, + ) + + # Generate challenge `x` and evaluate the aggregated polynomial at `x` + x = hash_to_bls_field([aggregated_poly], [aggregated_poly_commitment]) + # Evaluate aggregated polynomial at `x` (evaluation function checks for div-by-zero) + y = evaluate_polynomial_in_evaluation_form(aggregated_poly, x) + + # Verify aggregated proof + return verify_kzg_proof(aggregated_poly_commitment, x, y, kzg_aggregated_proof) +``` + ### Polynomials #### `evaluate_polynomial_in_evaluation_form` ```python -def evaluate_polynomial_in_evaluation_form(polynomial: Sequence[BLSFieldElement], +def evaluate_polynomial_in_evaluation_form(polynomial: Polynomial, z: BLSFieldElement) -> BLSFieldElement: """ Evaluate a polynomial (in evaluation form) at an arbitrary point `z` diff --git a/specs/eip4844/validator.md b/specs/eip4844/validator.md index 7ff3a7c9f4..fc2fe828f2 100644 --- a/specs/eip4844/validator.md +++ b/specs/eip4844/validator.md @@ -77,33 +77,7 @@ def validate_blobs_sidecar(slot: Slot, kzg_aggregated_proof = blobs_sidecar.kzg_aggregated_proof assert len(expected_kzg_commitments) == len(blobs) - aggregated_poly, aggregated_poly_commitment = compute_aggregated_poly_and_commitment( - blobs, - expected_kzg_commitments, - ) - - # Generate challenge `x` and evaluate the aggregated polynomial at `x` - x = hash_to_bls_field( - PolynomialAndCommitment(polynomial=aggregated_poly, kzg_commitment=aggregated_poly_commitment) - ) - # Evaluate aggregated polynomial at `x` (evaluation function checks for div-by-zero) - y = evaluate_polynomial_in_evaluation_form(aggregated_poly, x) - - # Verify aggregated proof - assert verify_kzg_proof(aggregated_poly_commitment, x, y, kzg_aggregated_proof) -``` - -### `compute_proof_from_blobs` - -```python -def compute_proof_from_blobs(blobs: Sequence[Blob]) -> KZGProof: - commitments = [blob_to_kzg_commitment(blob) for blob in blobs] - aggregated_poly, aggregated_poly_commitment = compute_aggregated_poly_and_commitment(blobs, commitments) - x = hash_to_bls_field(PolynomialAndCommitment( - polynomial=aggregated_poly, - kzg_commitment=aggregated_poly_commitment, - )) - return compute_kzg_proof(aggregated_poly, x) + assert verify_aggregate_kzg_proof(blobs, expected_kzg_commitments, kzg_aggregated_proof) ``` ### `get_blobs_and_kzg_commitments` @@ -160,7 +134,7 @@ def get_blobs_sidecar(block: BeaconBlock, blobs: Sequence[Blob]) -> BlobsSidecar beacon_block_root=hash_tree_root(block), beacon_block_slot=block.slot, blobs=blobs, - kzg_aggregated_proof=compute_proof_from_blobs(blobs), + kzg_aggregated_proof=compute_aggregate_kzg_proof(blobs), ) ```