From 1a4db24919dbdf438c5f45b2bb4c51874266d6f6 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 17 May 2023 11:49:46 -0600 Subject: [PATCH 1/2] Update fork-choice.md Remove duplicate check --- specs/deneb/fork-choice.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/specs/deneb/fork-choice.md b/specs/deneb/fork-choice.md index ce9973f130..1390b3d4e7 100644 --- a/specs/deneb/fork-choice.md +++ b/specs/deneb/fork-choice.md @@ -30,8 +30,6 @@ This is the modification of the fork choice accompanying the Deneb upgrade. def validate_blobs(expected_kzg_commitments: Sequence[KZGCommitment], blobs: Sequence[Blob], proofs: Sequence[KZGProof]) -> None: - assert len(expected_kzg_commitments) == len(blobs) == len(proofs) - assert verify_blob_kzg_proof_batch(blobs, expected_kzg_commitments, proofs) ``` From c9b84ecc1a75d3a3d3d028955a2e5646cc62b54a Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 1 Jun 2023 23:40:46 +0800 Subject: [PATCH 2/2] Use `verify_blob_kzg_proof_batch` directly in `is_data_available` and remove `validate_blob` wrapper --- specs/deneb/fork-choice.md | 14 +---- specs/deneb/p2p-interface.md | 2 +- .../deneb/unittests/fork_choice/__init__.py | 0 .../fork_choice/test_validate_blobs.py | 54 ------------------- 4 files changed, 3 insertions(+), 67 deletions(-) delete mode 100644 tests/core/pyspec/eth2spec/test/deneb/unittests/fork_choice/__init__.py delete mode 100644 tests/core/pyspec/eth2spec/test/deneb/unittests/fork_choice/test_validate_blobs.py diff --git a/specs/deneb/fork-choice.md b/specs/deneb/fork-choice.md index 1390b3d4e7..4636b42a19 100644 --- a/specs/deneb/fork-choice.md +++ b/specs/deneb/fork-choice.md @@ -8,7 +8,6 @@ - [Introduction](#introduction) - [Containers](#containers) - [Helpers](#helpers) - - [`validate_blobs`](#validate_blobs) - [`is_data_available`](#is_data_available) - [Updated fork-choice handlers](#updated-fork-choice-handlers) - [`on_block`](#on_block) @@ -24,19 +23,10 @@ This is the modification of the fork choice accompanying the Deneb upgrade. ## Helpers -#### `validate_blobs` - -```python -def validate_blobs(expected_kzg_commitments: Sequence[KZGCommitment], - blobs: Sequence[Blob], - proofs: Sequence[KZGProof]) -> None: - assert verify_blob_kzg_proof_batch(blobs, expected_kzg_commitments, proofs) -``` - #### `is_data_available` The implementation of `is_data_available` will become more sophisticated during later scaling upgrades. -Initially, verification requires every verifying actor to retrieve all matching `Blob`s and `KZGProof`s, and validate them with `validate_blobs`. +Initially, verification requires every verifying actor to retrieve all matching `Blob`s and `KZGProof`s, and validate them with `verify_blob_kzg_proof_batch`. The block MUST NOT be considered valid until all valid `Blob`s have been downloaded. Blocks that have been previously validated as available SHOULD be considered available even if the associated `Blob`s have subsequently been pruned. @@ -52,7 +42,7 @@ def is_data_available(beacon_block_root: Root, blob_kzg_commitments: Sequence[KZ if isinstance(blobs, str) or isinstance(proofs, str): return True - validate_blobs(blob_kzg_commitments, blobs, proofs) + assert verify_blob_kzg_proof_batch(blobs, blob_kzg_commitments, proofs) return True ``` diff --git a/specs/deneb/p2p-interface.md b/specs/deneb/p2p-interface.md index 3c6f3c88a5..f7c962e46e 100644 --- a/specs/deneb/p2p-interface.md +++ b/specs/deneb/p2p-interface.md @@ -264,7 +264,7 @@ Requests blob sidecars in the slot range `[start_slot, start_slot + count)`, lea The response is unsigned, i.e. `BlobSidecarsByRange`, as the signature of the beacon block proposer may not be available beyond the initial distribution via gossip. -Before consuming the next response chunk, the response reader SHOULD verify the blob sidecar is well-formatted and correct w.r.t. the expected KZG commitments through `validate_blobs`. +Before consuming the next response chunk, the response reader SHOULD verify the blob sidecar is well-formatted and correct w.r.t. the expected KZG commitments through `verify_blob_kzg_proof_batch`. `BlobSidecarsByRange` is primarily used to sync blobs that may have been missed on gossip and to sync within the `MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS` window. diff --git a/tests/core/pyspec/eth2spec/test/deneb/unittests/fork_choice/__init__.py b/tests/core/pyspec/eth2spec/test/deneb/unittests/fork_choice/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/core/pyspec/eth2spec/test/deneb/unittests/fork_choice/test_validate_blobs.py b/tests/core/pyspec/eth2spec/test/deneb/unittests/fork_choice/test_validate_blobs.py deleted file mode 100644 index 0d7bd53e52..0000000000 --- a/tests/core/pyspec/eth2spec/test/deneb/unittests/fork_choice/test_validate_blobs.py +++ /dev/null @@ -1,54 +0,0 @@ -from eth2spec.test.helpers.state import ( - state_transition_and_sign_block, -) -from eth2spec.test.helpers.block import ( - build_empty_block_for_next_slot -) -from eth2spec.test.context import ( - spec_state_test, - with_deneb_and_later, -) -from eth2spec.test.helpers.execution_payload import ( - compute_el_block_hash, -) -from eth2spec.test.helpers.sharding import ( - get_sample_opaque_tx, -) - - -def _run_validate_blobs(spec, state, blob_count): - block = build_empty_block_for_next_slot(spec, state) - opaque_tx, blobs, blob_kzg_commitments, kzg_proofs = get_sample_opaque_tx(spec, blob_count=blob_count) - block.body.blob_kzg_commitments = blob_kzg_commitments - block.body.execution_payload.transactions = [opaque_tx] - block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload) - state_transition_and_sign_block(spec, state, block) - - blob_sidecars = spec.get_blob_sidecars(block, blobs, kzg_proofs) - blobs = [sidecar.blob for sidecar in blob_sidecars] - kzg_proofs = [sidecar.kzg_proof for sidecar in blob_sidecars] - spec.validate_blobs(blob_kzg_commitments, blobs, kzg_proofs) - - -@with_deneb_and_later -@spec_state_test -def test_validate_blobs_zero_blobs(spec, state): - _run_validate_blobs(spec, state, blob_count=0) - - -@with_deneb_and_later -@spec_state_test -def test_validate_blobs_one_blob(spec, state): - _run_validate_blobs(spec, state, blob_count=1) - - -@with_deneb_and_later -@spec_state_test -def test_validate_blobs_two_blobs(spec, state): - _run_validate_blobs(spec, state, blob_count=2) - - -@with_deneb_and_later -@spec_state_test -def test_validate_blobs_max_blobs(spec, state): - _run_validate_blobs(spec, state, blob_count=spec.MAX_BLOBS_PER_BLOCK)