From f2649f65ba36d3ea6bc0234547759245622226bc Mon Sep 17 00:00:00 2001 From: dapplion <35266934+dapplion@users.noreply.github.com> Date: Fri, 27 Oct 2023 18:51:43 +0300 Subject: [PATCH] fix unit tests --- specs/deneb/p2p-interface.md | 4 +- specs/deneb/validator.md | 2 +- .../unittests/validator/test_validator.py | 43 +++---------------- 3 files changed, 10 insertions(+), 39 deletions(-) diff --git a/specs/deneb/p2p-interface.md b/specs/deneb/p2p-interface.md index 346810295..5ace66fde 100644 --- a/specs/deneb/p2p-interface.md +++ b/specs/deneb/p2p-interface.md @@ -51,8 +51,8 @@ The specification of these changes continues in the same format as the network s | `MAX_REQUEST_BLOB_SIDECARS` | `MAX_REQUEST_BLOCKS_DENEB * MAX_BLOBS_PER_BLOCK` | Maximum number of blob sidecars in a single request | | `MIN_EPOCHS_FOR_BLOB_SIDECARS_REQUESTS` | `2**12` (= 4096 epochs, ~18 days) | The minimum epoch range over which a node must serve blob sidecars | | `BLOB_SIDECAR_SUBNET_COUNT` | `6` | The number of blob sidecar subnets used in the gossipsub protocol. | -| `BLOB_KZG_COMMITMENTS_GINDEX` | `get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments')` (= 27) | `blob_kzg_commitments` field gindex on `BeaconBlockBody` container | -| `KZG_COMMITMENT_INCLUSION_PROOF_DEPTH` | `floorlog2(BLOB_KZG_COMMITMENTS_GINDEX) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK) # noqa: E501` | Merkle proof for `blob_kzg_commitments` list item | +| `BLOB_KZG_COMMITMENTS_GINDEX` | `2**4 + 11` (= 27) | `blob_kzg_commitments` field gindex on `BeaconBlockBody` container | +| `KZG_COMMITMENT_INCLUSION_PROOF_DEPTH` | `4 + 1 + floorlog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` | Merkle proof for `blob_kzg_commitments` list item | ### Containers diff --git a/specs/deneb/validator.md b/specs/deneb/validator.md index ba41adf0b..6b21ea30f 100644 --- a/specs/deneb/validator.md +++ b/specs/deneb/validator.md @@ -165,7 +165,7 @@ def get_blob_sidecars(signed_block: SignedBeaconBlock, kzg_proof=blob_kzg_proofs[index], commitment_inclusion_proof=compute_commitment_inclusion_proof( block.body, - get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments', index), + get_generalized_index(BeaconBlockBody, 'blob_kzg_commitments', index), # type: ignore ), signed_block_header=signed_block_header, ) diff --git a/tests/core/pyspec/eth2spec/test/deneb/unittests/validator/test_validator.py b/tests/core/pyspec/eth2spec/test/deneb/unittests/validator/test_validator.py index a45acb071..52374d42f 100644 --- a/tests/core/pyspec/eth2spec/test/deneb/unittests/validator/test_validator.py +++ b/tests/core/pyspec/eth2spec/test/deneb/unittests/validator/test_validator.py @@ -10,46 +10,15 @@ from eth2spec.test.helpers.sharding import ( get_sample_opaque_tx, ) from eth2spec.test.helpers.block import ( - build_empty_block_for_next_slot + build_empty_block_for_next_slot, + sign_block ) from tests.core.pyspec.eth2spec.utils.ssz.ssz_impl import hash_tree_root -def get_blob_sidecars(spec, signed_block, blobs, blob_kzg_proofs): - block = signed_block.message - block_header = spec.BeaconBlockHeader( - slot=block.slot, - proposer_index=block.proposer_index, - parent_root=block.parent_root, - state_root=block.state_root, - body_root=hash_tree_root(block.body), - ) - signed_block_header = spec.SignedBeaconBlockHeader(message=block_header, signature=signed_block.signature) - return [ - spec.BlobSidecar( - index=index, - blob=blob, - kzg_commitment=signed_block.message.body.blob_kzg_commitments[index], - kzg_proof=blob_kzg_proofs[index], - commitment_inclusion_proof=compute_commitment_inclusion_proof( - spec, - signed_block.message.body, - index, - ), - signed_block_header=signed_block_header, - ) - for index, blob in enumerate(blobs) - ] - - -def compute_commitment_inclusion_proof(spec, body, index): - gindex = spec.get_generalized_index(spec.BeaconBlockBody, 'blob_kzg_commitments', index) - return spec.build_proof(body, gindex) - - @with_deneb_and_later @spec_state_test -def test_blob_sidecar_inclusion_proof(spec, state): +def test_blob_sidecar_inclusion_proof_correct(spec, state): """ Test `verify_blob_sidecar_inclusion_proof` """ @@ -60,7 +29,8 @@ def test_blob_sidecar_inclusion_proof(spec, state): block.body.execution_payload.transactions = [opaque_tx] block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload) - blob_sidecars = spec.get_blob_sidecars(spec, block, blobs, proofs) + signed_block = sign_block(spec, state, block, proposer_index=0) + blob_sidecars = spec.get_blob_sidecars(signed_block, blobs, proofs) for blob_sidecar in blob_sidecars: assert spec.verify_blob_sidecar_inclusion_proof(blob_sidecar) @@ -80,7 +50,8 @@ def test_blob_sidecar_inclusion_proof_incorrect(spec, state): block.body.execution_payload.transactions = [opaque_tx] block.body.execution_payload.block_hash = compute_el_block_hash(spec, block.body.execution_payload) - blob_sidecars = spec.get_blob_sidecars(spec, block, blobs, proofs) + signed_block = sign_block(spec, state, block, proposer_index=0) + blob_sidecars = spec.get_blob_sidecars(signed_block, blobs, proofs) for blob_sidecar in blob_sidecars: block = blob_sidecar.signed_block_header.message