From fcd905cb3a41758baca11125c3a5a3d73b951d98 Mon Sep 17 00:00:00 2001 From: Lion - dapplion <35266934+dapplion@users.noreply.github.com> Date: Tue, 25 Jun 2024 10:52:23 +0200 Subject: [PATCH 01/19] Update sync-protocol.md --- specs/altair/light-client/sync-protocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/altair/light-client/sync-protocol.md b/specs/altair/light-client/sync-protocol.md index 2585889bf..f9b0625dc 100644 --- a/specs/altair/light-client/sync-protocol.md +++ b/specs/altair/light-client/sync-protocol.md @@ -204,7 +204,7 @@ def is_better_update(new_update: LightClientUpdate, old_update: LightClientUpdat new_has_supermajority = new_num_active_participants * 3 >= max_active_participants * 2 old_has_supermajority = old_num_active_participants * 3 >= max_active_participants * 2 if new_has_supermajority != old_has_supermajority: - return new_has_supermajority > old_has_supermajority + return new_has_supermajority if not new_has_supermajority and new_num_active_participants != old_num_active_participants: return new_num_active_participants > old_num_active_participants From 23a669dc29953c7be97a9d962c0e99bdebda0cef Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Fri, 9 Aug 2024 15:51:05 +0600 Subject: [PATCH 02/19] Get rid of compute_state_by_epoch_processing_to --- .../test_process_pending_consolidations.py | 11 +++++++---- .../pyspec/eth2spec/test/helpers/epoch_processing.py | 6 ------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_consolidations.py b/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_consolidations.py index d75014983..14e151e2e 100644 --- a/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_consolidations.py +++ b/tests/core/pyspec/eth2spec/test/electra/epoch_processing/test_process_pending_consolidations.py @@ -1,6 +1,6 @@ from eth2spec.test.helpers.epoch_processing import ( run_epoch_processing_with, - compute_state_by_epoch_processing_to, + run_epoch_processing_to, ) from eth2spec.test.context import ( spec_state_test, @@ -219,7 +219,8 @@ def test_pending_consolidation_future_epoch(spec, state): next_epoch_with_full_participation(spec, state) # Obtain state before the call to process_pending_consolidations - state_before_consolidation = compute_state_by_epoch_processing_to(spec, state, "process_pending_consolidations") + state_before_consolidation = state.copy() + run_epoch_processing_to(spec, state_before_consolidation, "process_pending_consolidations") yield from run_epoch_processing_with(spec, state, "process_pending_consolidations") @@ -270,7 +271,8 @@ def test_pending_consolidation_compounding_creds(spec, state): next_epoch_with_full_participation(spec, state) # Obtain state before the call to process_pending_consolidations - state_before_consolidation = compute_state_by_epoch_processing_to(spec, state, "process_pending_consolidations") + state_before_consolidation = state.copy() + run_epoch_processing_to(spec, state_before_consolidation, "process_pending_consolidations") yield from run_epoch_processing_with(spec, state, "process_pending_consolidations") @@ -325,7 +327,8 @@ def test_pending_consolidation_with_pending_deposit(spec, state): next_epoch_with_full_participation(spec, state) # Obtain state before the call to process_pending_balance_deposits - state_before_consolidation = compute_state_by_epoch_processing_to(spec, state, "process_pending_balance_deposits") + state_before_consolidation = state.copy() + run_epoch_processing_to(spec, state_before_consolidation, "process_pending_consolidations") yield from run_epoch_processing_with(spec, state, "process_pending_consolidations") diff --git a/tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py b/tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py index 80302e111..c2b7af5a4 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py +++ b/tests/core/pyspec/eth2spec/test/helpers/epoch_processing.py @@ -74,9 +74,3 @@ def run_epoch_processing_with(spec, state, process_name: str): yield 'pre', state getattr(spec, process_name)(state) yield 'post', state - - -def compute_state_by_epoch_processing_to(spec, state, process_name: str): - state_copy = state.copy() - run_epoch_processing_to(spec, state_copy, process_name) - return state_copy From c22105d5b345bff7ec7307e1ef9b05188d283be8 Mon Sep 17 00:00:00 2001 From: parithosh Date: Tue, 13 Aug 2024 12:56:03 +0200 Subject: [PATCH 03/19] updating readme and dependencies --- README.md | 16 ++++++++++++++++ docker/README.md | 6 +++--- setup.py | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c62a4171d..d53f7e6cb 100644 --- a/README.md +++ b/README.md @@ -73,3 +73,19 @@ Documentation on the different components used during spec writing can be found ## Consensus spec tests Conformance tests built from the executable python spec are available in the [Ethereum Proof-of-Stake Consensus Spec Tests](https://github.com/ethereum/consensus-spec-tests) repo. Compressed tarballs are available in [releases](https://github.com/ethereum/consensus-spec-tests/releases). + + +## Installation and Usage +The consensus-specs repo can be used by running the tests locally or inside a docker container. + +To run the tests locally: +- Clone the repository with `git clone https://github.com/ethereum/consensus-specs.git` +- Switch to the directory `cd consensus-specs` +- Install the dependencies with: `make install_test && make preinstallation && make pyspec` +- Run the tests with `make citest` + +To run the tests inside a docker container: +- Switch to the directory with `cd scripts` +- Run the script `./build_run_docker_tests.sh` +- Find the results in a folder called `./testResults` +- Find more ways to customize the script with `./build_run_docker_tests.sh --h` \ No newline at end of file diff --git a/docker/README.md b/docker/README.md index 4f0c1ecca..4f260130e 100644 --- a/docker/README.md +++ b/docker/README.md @@ -13,8 +13,8 @@ Ideally manual running of docker containers is for advanced users, we recommend The `scripts/build_run_docker_tests.sh` script will cover most usecases. The script allows the user to configure the fork(altair/bellatrix/capella..), `$IMAGE_NAME` (specifies the container to use), preset type (mainnet/minimal), and test all forks flags. Ideally, this is the main way that users interact with the spec tests instead of running it locally with varying versions of dependencies. E.g: -- `./build_run_test.sh --p mainnet` will run the mainnet preset tests -- `./build_run_test.sh --a` will run all the tests across all the forks -- `./build_run_test.sh --f deneb` will only run deneb tests +`./build_run_docker_tests.sh --p mainnet` will run the mainnet preset tests +- `./build_run_docker_tests.sh --a` will run all the tests across all the forks +- `./build_run_docker_tests.sh --f deneb` will only run deneb tests Results are always placed in a folder called `./testResults`. The results are `.xml` files and contain the fork they represent and the date/time they were run at. \ No newline at end of file diff --git a/setup.py b/setup.py index 539db215b..0ae71212c 100644 --- a/setup.py +++ b/setup.py @@ -549,7 +549,7 @@ setup( install_requires=[ "eth-utils>=2.0.0,<3", "eth-typing>=3.2.0,<4.0.0", - "pycryptodome==3.15.0", + "pycryptodome>=3.19.1", "py_ecc==6.0.0", "milagro_bls_binding==1.9.0", "remerkleable==0.1.28", From bb4c5d186bb0f78d9b7a9f887c3c4d75ce9b333f Mon Sep 17 00:00:00 2001 From: Parithosh Jayanthi Date: Tue, 13 Aug 2024 16:36:21 +0200 Subject: [PATCH 04/19] Update docker/README.md Co-authored-by: Hsiao-Wei Wang --- docker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/README.md b/docker/README.md index 4f260130e..44dc2b95e 100644 --- a/docker/README.md +++ b/docker/README.md @@ -13,7 +13,7 @@ Ideally manual running of docker containers is for advanced users, we recommend The `scripts/build_run_docker_tests.sh` script will cover most usecases. The script allows the user to configure the fork(altair/bellatrix/capella..), `$IMAGE_NAME` (specifies the container to use), preset type (mainnet/minimal), and test all forks flags. Ideally, this is the main way that users interact with the spec tests instead of running it locally with varying versions of dependencies. E.g: -`./build_run_docker_tests.sh --p mainnet` will run the mainnet preset tests +- `./build_run_docker_tests.sh --p mainnet` will run the mainnet preset tests - `./build_run_docker_tests.sh --a` will run all the tests across all the forks - `./build_run_docker_tests.sh --f deneb` will only run deneb tests From fc3640f3c209207acc494d14449879b4489351e1 Mon Sep 17 00:00:00 2001 From: Potuz Date: Mon, 19 Aug 2024 09:33:10 -0300 Subject: [PATCH 05/19] Require the builder is active and non-slashed --- specs/_features/eip7732/beacon-chain.md | 5 ++++- specs/_features/eip7732/p2p-interface.md | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/specs/_features/eip7732/beacon-chain.md b/specs/_features/eip7732/beacon-chain.md index fdcb2b300..04da9b539 100644 --- a/specs/_features/eip7732/beacon-chain.md +++ b/specs/_features/eip7732/beacon-chain.md @@ -493,9 +493,12 @@ def process_execution_payload_header(state: BeaconState, block: BeaconBlock) -> signed_header = block.body.signed_execution_payload_header assert verify_execution_payload_header_signature(state, signed_header) - # Check that the builder has funds to cover the bid + # Check that the builder is active non-slashed has funds to cover the bid header = signed_header.message builder_index = header.builder_index + builder = state.validators[builder_index] + assert is_active_validator(builder, get_current_epoch(state)) + assert not builder.slashed amount = header.value assert state.balances[builder_index] >= amount diff --git a/specs/_features/eip7732/p2p-interface.md b/specs/_features/eip7732/p2p-interface.md index 86ab89568..a48bb6990 100644 --- a/specs/_features/eip7732/p2p-interface.md +++ b/specs/_features/eip7732/p2p-interface.md @@ -170,9 +170,10 @@ The following validations MUST pass before forwarding the `signed_execution_payl - _[IGNORE]_ this is the first signed bid seen with a valid signature from the given builder for this slot. - _[IGNORE]_ this bid is the highest value bid seen for the pair of the corresponding slot and the given parent block hash. -- _[REJECT]_ The signed builder bid, `header.builder_index` is a valid and non-slashed builder index in state. +- _[REJECT]_ The signed builder bid, `header.builder_index` is a valid, active, and non-slashed builder index in state. - _[IGNORE]_ The signed builder bid value, `header.value`, is less or equal than the builder's balance in state. i.e. `MIN_BUILDER_BALANCE + header.value < state.builder_balances[header.builder_index]`. - _[IGNORE]_ `header.parent_block_hash` is the block hash of a known execution payload in fork choice. +_ _[IGNORE]_ `header.parent_block_root` is the hash tree root of a known beacon block in fork choice. - _[IGNORE]_ `header.slot` is the current slot or the next slot. - _[REJECT]_ The builder signature, `signed_execution_payload_header_envelope.signature`, is valid with respect to the `header_envelope.builder_index`. From 7d0a8c6335b2dca9d7e8f749cc886c733633d4db Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Tue, 20 Aug 2024 13:54:36 +0300 Subject: [PATCH 06/19] EIP-7732: Modify `ExecutionPayloadEnvelopeByRoot` --- configs/mainnet.yaml | 3 +++ configs/minimal.yaml | 3 +++ specs/_features/eip7732/p2p-interface.md | 24 ++++++++++++++++-------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/configs/mainnet.yaml b/configs/mainnet.yaml index 1c2911f8f..cb051ce88 100644 --- a/configs/mainnet.yaml +++ b/configs/mainnet.yaml @@ -170,3 +170,6 @@ CUSTODY_REQUIREMENT: 4 # [New in Electra:EIP7251] MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA: 128000000000 # 2**7 * 10**9 (= 128,000,000,000) MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT: 256000000000 # 2**8 * 10**9 (= 256,000,000,000) + +# EIP7732 +MAX_REQUEST_PAYLOADS: 128 diff --git a/configs/minimal.yaml b/configs/minimal.yaml index eb4f77aa2..a7c89ec1d 100644 --- a/configs/minimal.yaml +++ b/configs/minimal.yaml @@ -169,3 +169,6 @@ CUSTODY_REQUIREMENT: 4 # [New in Electra:EIP7251] MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA: 64000000000 # 2**6 * 10**9 (= 64,000,000,000) MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT: 128000000000 # 2**7 * 10**9 (= 128,000,000,000) + +# EIP7732 +MAX_REQUEST_PAYLOADS: 128 diff --git a/specs/_features/eip7732/p2p-interface.md b/specs/_features/eip7732/p2p-interface.md index 86ab89568..cd48b79aa 100644 --- a/specs/_features/eip7732/p2p-interface.md +++ b/specs/_features/eip7732/p2p-interface.md @@ -23,7 +23,7 @@ This document contains the consensus-layer networking specification for EIP7732. - [BeaconBlocksByRange v3](#beaconblocksbyrange-v3) - [BeaconBlocksByRoot v3](#beaconblocksbyroot-v3) - [BlobSidecarsByRoot v2](#blobsidecarsbyroot-v2) - - [ExecutionPayloadEnvelopeByRoot v1](#executionpayloadenvelopebyroot-v1) + - [ExecutionPayloadEnvelopesByRoot v1](#executionpayloadenvelopesbyroot-v1) @@ -37,6 +37,14 @@ This document contains the consensus-layer networking specification for EIP7732. |------------------------------------------|-----------------------------------|---------------------------------------------------------------------| | `KZG_COMMITMENT_INCLUSION_PROOF_DEPTH_EIP7732` | `13` # TODO: Compute it when the spec stabilizes | Merkle proof depth for the `blob_kzg_commitments` list item | +### Configuration + +*[Modified in EIP-7732]* + +| Name | Value | Description | +|------------------------------------------|-----------------------------------|---------------------------------------------------------------------| +| `MAX_REQUEST_PAYLOADS` | `2**7` (= 128) | Maximum number of execution payload envelopes in a single request | + ### Containers @@ -225,9 +233,9 @@ Per `context = compute_fork_digest(fork_version, genesis_validators_root)`: | `EIP7732_FORK_VERSION` | `eip7732.BlobSidecar` | -##### ExecutionPayloadEnvelopeByRoot v1 +##### ExecutionPayloadEnvelopesByRoot v1 -**Protocol ID:** `/eth2/beacon_chain/req/execution_payload_envelope_by_root/1/` +**Protocol ID:** `/eth2/beacon_chain/req/execution_payload_envelopes_by_root/1/` The `` field is calculated as `context = compute_fork_digest(fork_version, genesis_validators_root)`: @@ -241,7 +249,7 @@ Request Content: ``` ( - List[Root, MAX_REQUEST_PAYLOAD] + List[Root, MAX_REQUEST_PAYLOADS] ) ``` @@ -249,14 +257,14 @@ Response Content: ``` ( - List[SignedExecutionPayloadEnvelope, MAX_REQUEST_PAYLOAD] + List[SignedExecutionPayloadEnvelope, MAX_REQUEST_PAYLOADS] ) ``` -Requests execution payload envelope by `signed_execution_payload_envelope.message.block_root`. The response is a list of `SignedExecutionPayloadEnvelope` whose length is less than or equal to the number of requested execution payload envelopes. It may be less in the case that the responding peer is missing payload envelopes. +Requests execution payload envelopes by `signed_execution_payload_envelope.message.block_root`. The response is a list of `SignedExecutionPayloadEnvelope` whose length is less than or equal to the number of requested execution payload envelopes. It may be less in the case that the responding peer is missing payload envelopes. -No more than `MAX_REQUEST_PAYLOAD` may be requested at a time. +No more than `MAX_REQUEST_PAYLOADS` may be requested at a time. -ExecutionPayloadEnvelopeByRoot is primarily used to recover recent execution payload envelope (e.g. when receiving a payload attestation with revealed status as true but never received a payload). +ExecutionPayloadEnvelopesByRoot is primarily used to recover recent execution payload envelopes (e.g. when receiving a payload attestation with revealed status as true but never received a payload). The request MUST be encoded as an SSZ-field. From 679cb60ee2b0426be8b36282f3f472b526cb920e Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Tue, 20 Aug 2024 13:58:09 +0300 Subject: [PATCH 07/19] Add to table of contents --- specs/_features/eip7732/p2p-interface.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/_features/eip7732/p2p-interface.md b/specs/_features/eip7732/p2p-interface.md index cd48b79aa..3cbfab1e8 100644 --- a/specs/_features/eip7732/p2p-interface.md +++ b/specs/_features/eip7732/p2p-interface.md @@ -7,6 +7,7 @@ This document contains the consensus-layer networking specification for EIP7732. - [Modification in EIP-7732](#modification-in-eip-7732) - [Preset](#preset) + - [Configuration](#configuration) - [Containers](#containers) - [`BlobSidecar`](#blobsidecar) - [Helpers](#helpers) From edf0ddea3cd7ffae333bce994527b21525f736ca Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Tue, 20 Aug 2024 13:59:29 +0300 Subject: [PATCH 08/19] change to new --- specs/_features/eip7732/p2p-interface.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/_features/eip7732/p2p-interface.md b/specs/_features/eip7732/p2p-interface.md index 3cbfab1e8..0de7adcfd 100644 --- a/specs/_features/eip7732/p2p-interface.md +++ b/specs/_features/eip7732/p2p-interface.md @@ -40,7 +40,7 @@ This document contains the consensus-layer networking specification for EIP7732. ### Configuration -*[Modified in EIP-7732]* +*[New in EIP-7732]* | Name | Value | Description | |------------------------------------------|-----------------------------------|---------------------------------------------------------------------| From 24aecf554d0e4a8c92c241a633508dca95246b87 Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Tue, 20 Aug 2024 20:18:47 +0300 Subject: [PATCH 09/19] Update specs/_features/eip7732/p2p-interface.md Co-authored-by: Justin Traglia <95511699+jtraglia@users.noreply.github.com> --- specs/_features/eip7732/p2p-interface.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/_features/eip7732/p2p-interface.md b/specs/_features/eip7732/p2p-interface.md index 0de7adcfd..b0522ac98 100644 --- a/specs/_features/eip7732/p2p-interface.md +++ b/specs/_features/eip7732/p2p-interface.md @@ -42,9 +42,9 @@ This document contains the consensus-layer networking specification for EIP7732. *[New in EIP-7732]* -| Name | Value | Description | -|------------------------------------------|-----------------------------------|---------------------------------------------------------------------| -| `MAX_REQUEST_PAYLOADS` | `2**7` (= 128) | Maximum number of execution payload envelopes in a single request | +| Name | Value | Description | +|------------------------|----------------|-------------------------------------------------------------------| +| `MAX_REQUEST_PAYLOADS` | `2**7` (= 128) | Maximum number of execution payload envelopes in a single request | ### Containers From ba99f8bb16f59b4cd01ca8260e3db6f2032c9bff Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Tue, 20 Aug 2024 20:18:55 +0300 Subject: [PATCH 10/19] Update specs/_features/eip7732/p2p-interface.md Co-authored-by: Justin Traglia <95511699+jtraglia@users.noreply.github.com> --- specs/_features/eip7732/p2p-interface.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/_features/eip7732/p2p-interface.md b/specs/_features/eip7732/p2p-interface.md index b0522ac98..b101cc367 100644 --- a/specs/_features/eip7732/p2p-interface.md +++ b/specs/_features/eip7732/p2p-interface.md @@ -40,7 +40,7 @@ This document contains the consensus-layer networking specification for EIP7732. ### Configuration -*[New in EIP-7732]* +*[New in EIP7732]* | Name | Value | Description | |------------------------|----------------|-------------------------------------------------------------------| From 4c9be8978faae33a69e170b679df2e0cd24f53f2 Mon Sep 17 00:00:00 2001 From: NC <17676176+ensi321@users.noreply.github.com> Date: Thu, 22 Aug 2024 00:17:56 +0800 Subject: [PATCH 11/19] Randomize validator index in partial withdrawal test --- .../test_process_withdrawal_request.py | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py b/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py index 53460347a..c4707733a 100644 --- a/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py +++ b/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py @@ -1,3 +1,4 @@ +import random from eth2spec.test.context import ( spec_state_test, expect_assertion_error, @@ -23,7 +24,7 @@ def test_basic_withdrawal_request(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 set_eth1_withdrawal_credential_with_balance( @@ -47,7 +48,7 @@ def test_basic_withdrawal_request_with_compounding_credentials(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 set_compounding_withdrawal_credential(spec, state, validator_index, address=address) @@ -68,7 +69,7 @@ def test_basic_withdrawal_request_with_compounding_credentials(spec, state): def test_basic_withdrawal_request_with_full_partial_withdrawal_queue(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 set_eth1_withdrawal_credential_with_balance( @@ -106,7 +107,7 @@ def test_incorrect_source_address(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 incorrect_address = b"\x33" * 20 @@ -131,7 +132,7 @@ def test_incorrect_withdrawal_credential_prefix(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 set_eth1_withdrawal_credential_with_balance( @@ -160,7 +161,7 @@ def test_on_withdrawal_request_initiated_validator(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 set_eth1_withdrawal_credential_with_balance( @@ -183,7 +184,7 @@ def test_on_withdrawal_request_initiated_validator(spec, state): @spec_state_test def test_activation_epoch_less_than_shard_committee_period(spec, state): current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 set_eth1_withdrawal_credential_with_balance( @@ -213,7 +214,7 @@ def test_activation_epoch_less_than_shard_committee_period(spec, state): def test_basic_partial_withdrawal_request(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -245,7 +246,7 @@ def test_basic_partial_withdrawal_request(spec, state): def test_basic_partial_withdrawal_request_higher_excess_balance(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -277,7 +278,7 @@ def test_basic_partial_withdrawal_request_higher_excess_balance(spec, state): def test_basic_partial_withdrawal_request_lower_than_excess_balance(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 excess_balance = spec.EFFECTIVE_BALANCE_INCREMENT @@ -310,7 +311,7 @@ def test_basic_partial_withdrawal_request_lower_than_excess_balance(spec, state) def test_partial_withdrawal_request_with_pending_withdrawals(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -351,7 +352,7 @@ def test_partial_withdrawal_request_with_pending_withdrawals_and_high_amount( ): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.UINT64_MAX @@ -389,7 +390,7 @@ def test_partial_withdrawal_request_with_pending_withdrawals_and_high_amount( def test_partial_withdrawal_request_with_high_balance(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.MAX_EFFECTIVE_BALANCE_ELECTRA @@ -426,7 +427,7 @@ def test_partial_withdrawal_request_with_high_balance(spec, state): def test_partial_withdrawal_request_with_high_amount(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 # Set high amount requested to withdraw @@ -459,7 +460,7 @@ def test_partial_withdrawal_request_with_high_amount(spec, state): def test_partial_withdrawal_request_with_low_amount(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = 1 @@ -494,7 +495,7 @@ def test_partial_withdrawal_request_with_low_amount(spec, state): def test_partial_withdrawal_queue_full(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -524,7 +525,7 @@ def test_partial_withdrawal_queue_full(spec, state): def test_no_compounding_credentials(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -553,7 +554,7 @@ def test_no_compounding_credentials(spec, state): def test_no_excess_balance(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -575,7 +576,7 @@ def test_no_excess_balance(spec, state): def test_pending_withdrawals_consume_all_excess_balance(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -605,7 +606,7 @@ def test_pending_withdrawals_consume_all_excess_balance(spec, state): def test_insufficient_effective_balance(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -636,7 +637,7 @@ def test_partial_withdrawal_incorrect_source_address(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 incorrect_address = b"\x33" * 20 @@ -662,7 +663,7 @@ def test_partial_withdrawal_incorrect_withdrawal_credential_prefix(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -691,7 +692,7 @@ def test_partial_withdrawal_on_exit_initiated_validator(spec, state): state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -716,7 +717,7 @@ def test_partial_withdrawal_activation_epoch_less_than_shard_committee_period( spec, state ): current_epoch = spec.get_current_epoch(state) - validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT From 8e90dd06c3b7797936c23493961c3302f584d0a0 Mon Sep 17 00:00:00 2001 From: NC <17676176+ensi321@users.noreply.github.com> Date: Thu, 22 Aug 2024 18:35:35 +0800 Subject: [PATCH 12/19] address comment --- .../test_process_withdrawal_request.py | 98 ++++++++++++++----- 1 file changed, 72 insertions(+), 26 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py b/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py index c4707733a..ef6de4ff8 100644 --- a/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py +++ b/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py @@ -20,11 +20,12 @@ from eth2spec.test.helpers.withdrawals import ( @with_electra_and_later @spec_state_test def test_basic_withdrawal_request(spec, state): + rng = random.Random(1337) # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 set_eth1_withdrawal_credential_with_balance( @@ -40,15 +41,38 @@ def test_basic_withdrawal_request(spec, state): spec, state, withdrawal_request ) - @with_electra_and_later @spec_state_test -def test_basic_withdrawal_request_with_compounding_credentials(spec, state): +def test_basic_withdrawal_request_with_first_validator(spec, state): # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = spec.get_active_validator_indices(state, current_epoch)[0] + validator_pubkey = state.validators[validator_index].pubkey + address = b"\x22" * 20 + set_eth1_withdrawal_credential_with_balance( + spec, state, validator_index, address=address + ) + withdrawal_request = spec.WithdrawalRequest( + source_address=address, + validator_pubkey=validator_pubkey, + amount=spec.FULL_EXIT_REQUEST_AMOUNT, + ) + + yield from run_withdrawal_request_processing( + spec, state, withdrawal_request + ) + +@with_electra_and_later +@spec_state_test +def test_basic_withdrawal_request_with_compounding_credentials(spec, state): + rng = random.Random(1338) + # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit + state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH + + current_epoch = spec.get_current_epoch(state) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 set_compounding_withdrawal_credential(spec, state, validator_index, address=address) @@ -67,9 +91,10 @@ def test_basic_withdrawal_request_with_compounding_credentials(spec, state): @spec_state_test @with_presets([MINIMAL], "need full partial withdrawal queue") def test_basic_withdrawal_request_with_full_partial_withdrawal_queue(spec, state): + rng = random.Random(1339) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 set_eth1_withdrawal_credential_with_balance( @@ -103,11 +128,12 @@ def test_basic_withdrawal_request_with_full_partial_withdrawal_queue(spec, state @with_electra_and_later @spec_state_test def test_incorrect_source_address(spec, state): + rng = random.Random(1340) # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 incorrect_address = b"\x33" * 20 @@ -128,11 +154,12 @@ def test_incorrect_source_address(spec, state): @with_electra_and_later @spec_state_test def test_incorrect_withdrawal_credential_prefix(spec, state): + rng = random.Random(1341) # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 set_eth1_withdrawal_credential_with_balance( @@ -157,11 +184,12 @@ def test_incorrect_withdrawal_credential_prefix(spec, state): @with_electra_and_later @spec_state_test def test_on_withdrawal_request_initiated_validator(spec, state): + rng = random.Random(1342) # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 set_eth1_withdrawal_credential_with_balance( @@ -183,8 +211,9 @@ def test_on_withdrawal_request_initiated_validator(spec, state): @with_electra_and_later @spec_state_test def test_activation_epoch_less_than_shard_committee_period(spec, state): + rng = random.Random(1343) current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 set_eth1_withdrawal_credential_with_balance( @@ -212,9 +241,10 @@ def test_activation_epoch_less_than_shard_committee_period(spec, state): @spec_state_test @with_presets([MINIMAL]) def test_basic_partial_withdrawal_request(spec, state): + rng = random.Random(1344) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -244,9 +274,10 @@ def test_basic_partial_withdrawal_request(spec, state): @spec_state_test @with_presets([MINIMAL]) def test_basic_partial_withdrawal_request_higher_excess_balance(spec, state): + rng = random.Random(1345) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -276,9 +307,10 @@ def test_basic_partial_withdrawal_request_higher_excess_balance(spec, state): @spec_state_test @with_presets([MINIMAL]) def test_basic_partial_withdrawal_request_lower_than_excess_balance(spec, state): + rng = random.Random(1346) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 excess_balance = spec.EFFECTIVE_BALANCE_INCREMENT @@ -309,9 +341,10 @@ def test_basic_partial_withdrawal_request_lower_than_excess_balance(spec, state) @spec_state_test @with_presets([MINIMAL]) def test_partial_withdrawal_request_with_pending_withdrawals(spec, state): + rng = random.Random(1347) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -350,9 +383,10 @@ def test_partial_withdrawal_request_with_pending_withdrawals(spec, state): def test_partial_withdrawal_request_with_pending_withdrawals_and_high_amount( spec, state ): + rng = random.Random(1348) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.UINT64_MAX @@ -388,9 +422,10 @@ def test_partial_withdrawal_request_with_pending_withdrawals_and_high_amount( @spec_state_test @with_presets([MINIMAL]) def test_partial_withdrawal_request_with_high_balance(spec, state): + rng = random.Random(1349) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.MAX_EFFECTIVE_BALANCE_ELECTRA @@ -425,9 +460,10 @@ def test_partial_withdrawal_request_with_high_balance(spec, state): @spec_state_test @with_presets([MINIMAL]) def test_partial_withdrawal_request_with_high_amount(spec, state): + rng = random.Random(1350) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 # Set high amount requested to withdraw @@ -458,9 +494,10 @@ def test_partial_withdrawal_request_with_high_amount(spec, state): @spec_state_test @with_presets([MINIMAL]) def test_partial_withdrawal_request_with_low_amount(spec, state): + rng = random.Random(1351) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = 1 @@ -493,9 +530,10 @@ def test_partial_withdrawal_request_with_low_amount(spec, state): @spec_state_test @with_presets([MINIMAL], "need full partial withdrawal queue") def test_partial_withdrawal_queue_full(spec, state): + rng = random.Random(1352) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -523,9 +561,10 @@ def test_partial_withdrawal_queue_full(spec, state): @with_electra_and_later @spec_state_test def test_no_compounding_credentials(spec, state): + rng = random.Random(1353) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -552,9 +591,10 @@ def test_no_compounding_credentials(spec, state): @with_electra_and_later @spec_state_test def test_no_excess_balance(spec, state): + rng = random.Random(1354) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -574,9 +614,10 @@ def test_no_excess_balance(spec, state): @with_electra_and_later @spec_state_test def test_pending_withdrawals_consume_all_excess_balance(spec, state): + rng = random.Random(1355) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -604,9 +645,10 @@ def test_pending_withdrawals_consume_all_excess_balance(spec, state): @with_electra_and_later @spec_state_test def test_insufficient_effective_balance(spec, state): + rng = random.Random(1356) state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -633,11 +675,12 @@ def test_insufficient_effective_balance(spec, state): @with_electra_and_later @spec_state_test def test_partial_withdrawal_incorrect_source_address(spec, state): + rng = random.Random(1357) # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 incorrect_address = b"\x33" * 20 @@ -659,11 +702,12 @@ def test_partial_withdrawal_incorrect_source_address(spec, state): @with_electra_and_later @spec_state_test def test_partial_withdrawal_incorrect_withdrawal_credential_prefix(spec, state): + rng = random.Random(1358) # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -688,11 +732,12 @@ def test_partial_withdrawal_incorrect_withdrawal_credential_prefix(spec, state): @with_electra_and_later @spec_state_test def test_partial_withdrawal_on_exit_initiated_validator(spec, state): + rng = random.Random(1359) # move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT @@ -716,8 +761,9 @@ def test_partial_withdrawal_on_exit_initiated_validator(spec, state): def test_partial_withdrawal_activation_epoch_less_than_shard_committee_period( spec, state ): + rng = random.Random(1360) current_epoch = spec.get_current_epoch(state) - validator_index = random.choice(spec.get_active_validator_indices(state, current_epoch)) + validator_index = rng.choice(spec.get_active_validator_indices(state, current_epoch)) validator_pubkey = state.validators[validator_index].pubkey address = b"\x22" * 20 amount = spec.EFFECTIVE_BALANCE_INCREMENT From 725f96349bea21e7f1f0a7f88654874b477354eb Mon Sep 17 00:00:00 2001 From: Justin Traglia <95511699+jtraglia@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:02:42 -0500 Subject: [PATCH 13/19] Add blank lines to fix linter --- .../electra/block_processing/test_process_withdrawal_request.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py b/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py index ef6de4ff8..c216b297c 100644 --- a/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py +++ b/tests/core/pyspec/eth2spec/test/electra/block_processing/test_process_withdrawal_request.py @@ -41,6 +41,7 @@ def test_basic_withdrawal_request(spec, state): spec, state, withdrawal_request ) + @with_electra_and_later @spec_state_test def test_basic_withdrawal_request_with_first_validator(spec, state): @@ -64,6 +65,7 @@ def test_basic_withdrawal_request_with_first_validator(spec, state): spec, state, withdrawal_request ) + @with_electra_and_later @spec_state_test def test_basic_withdrawal_request_with_compounding_credentials(spec, state): From d4f27aff1ffad8e24ed9c09243b3176a5934f1da Mon Sep 17 00:00:00 2001 From: terence tsao Date: Tue, 27 Aug 2024 13:32:46 -0700 Subject: [PATCH 14/19] Fix some EIP-7732 typos --- specs/_features/eip7732/beacon-chain.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/_features/eip7732/beacon-chain.md b/specs/_features/eip7732/beacon-chain.md index fdcb2b300..9d7505c2b 100644 --- a/specs/_features/eip7732/beacon-chain.md +++ b/specs/_features/eip7732/beacon-chain.md @@ -184,8 +184,8 @@ class BeaconBlockBody(Container): graffiti: Bytes32 # Arbitrary data # Operations proposer_slashings: List[ProposerSlashing, MAX_PROPOSER_SLASHINGS] - attester_slashings: List[AttesterSlashing, MAX_ATTESTER_SLASHINGS] - attestations: List[Attestation, MAX_ATTESTATIONS] + attester_slashings: List[AttesterSlashing, MAX_ATTESTER_SLASHINGS_ELECTRA] + attestations: List[Attestation, MAX_ATTESTATIONS_ELECTRA] deposits: List[Deposit, MAX_DEPOSITS] voluntary_exits: List[SignedVoluntaryExit, MAX_VOLUNTARY_EXITS] sync_aggregate: SyncAggregate @@ -662,7 +662,7 @@ def process_execution_payload(state: BeaconState, for_ops(payload.deposit_requests, process_deposit_request) for_ops(payload.withdrawal_requests, process_withdrawal_request) - for_ops(payload, process_consolidation_request) + for_ops(payload.consolidation_requests, process_consolidation_request) # Cache the execution payload header and proposer state.latest_block_hash = payload.block_hash From a5990f99ac2493d4950dcfad6109e3b58be1860d Mon Sep 17 00:00:00 2001 From: Barnabas Busa Date: Wed, 28 Aug 2024 20:43:34 +0200 Subject: [PATCH 15/19] EIP-7594: PeerDAS explicit csc integer size (#3897) * EIP-7594: PeerDAS explicit csc integer size * add spec test for csc int size * import uint8 * make linter happy * add spec * Update p2p-interface.md * Update specs/_features/eip7594/das-core.md Co-authored-by: Justin Traglia <95511699+jtraglia@users.noreply.github.com> * revert metadata name * Update specs/_features/eip7594/das-core.md Co-authored-by: Justin Traglia <95511699+jtraglia@users.noreply.github.com> * update tests * make linter happy * Make `DATA_COLUMN_SIDECAR_SUBNET_COUNT` in uint8 * add `int` casting for bypassing remerkeable type conversion --------- Co-authored-by: Justin Traglia <95511699+jtraglia@users.noreply.github.com> Co-authored-by: Hsiao-Wei Wang --- scripts/build_run_docker_tests.sh | 2 +- specs/_features/eip7594/das-core.md | 12 ++++++------ specs/_features/eip7594/p2p-interface.md | 10 +++++----- .../eip7594/networking/test_get_custody_columns.py | 2 +- .../test/eip7594/unittests/test_config_invariants.py | 4 +++- .../eth2spec/test/eip7594/unittests/test_custody.py | 4 ++-- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/scripts/build_run_docker_tests.sh b/scripts/build_run_docker_tests.sh index 9d2740ca2..91aa2c8ae 100755 --- a/scripts/build_run_docker_tests.sh +++ b/scripts/build_run_docker_tests.sh @@ -10,7 +10,7 @@ # Set variables -ALL_EXECUTABLE_SPECS=("phase0" "altair" "bellatrix" "capella" "deneb" "electra" "whisk") +ALL_EXECUTABLE_SPECS=("phase0" "altair" "bellatrix" "capella" "deneb" "electra" "whisk" "eip7594") TEST_PRESET_TYPE=minimal FORK_TO_TEST=phase0 WORKDIR="//consensus-specs//tests//core//pyspec" diff --git a/specs/_features/eip7594/das-core.md b/specs/_features/eip7594/das-core.md index 2096fb9a3..59011cdcd 100644 --- a/specs/_features/eip7594/das-core.md +++ b/specs/_features/eip7594/das-core.md @@ -67,7 +67,7 @@ The following values are (non-configurable) constants used throughout the specif | Name | Value | Description | | - | - | - | -| `DATA_COLUMN_SIDECAR_SUBNET_COUNT` | `128` | The number of data column sidecar subnets used in the gossipsub protocol | +| `DATA_COLUMN_SIDECAR_SUBNET_COUNT` | `uint8(128)` | The number of data column sidecar subnets used in the gossipsub protocol | ### Custody setting @@ -105,7 +105,7 @@ class MatrixEntry(Container): ### `get_custody_columns` ```python -def get_custody_columns(node_id: NodeID, custody_subnet_count: uint64) -> Sequence[ColumnIndex]: +def get_custody_columns(node_id: NodeID, custody_subnet_count: uint8) -> Sequence[ColumnIndex]: assert custody_subnet_count <= DATA_COLUMN_SIDECAR_SUBNET_COUNT subnet_ids: List[uint64] = [] @@ -113,7 +113,7 @@ def get_custody_columns(node_id: NodeID, custody_subnet_count: uint64) -> Sequen while len(subnet_ids) < custody_subnet_count: subnet_id = ( bytes_to_uint64(hash(uint_to_bytes(uint256(current_id)))[0:8]) - % DATA_COLUMN_SIDECAR_SUBNET_COUNT + % int(DATA_COLUMN_SIDECAR_SUBNET_COUNT) ) if subnet_id not in subnet_ids: subnet_ids.append(subnet_id) @@ -124,9 +124,9 @@ def get_custody_columns(node_id: NodeID, custody_subnet_count: uint64) -> Sequen assert len(subnet_ids) == len(set(subnet_ids)) - columns_per_subnet = NUMBER_OF_COLUMNS // DATA_COLUMN_SIDECAR_SUBNET_COUNT + columns_per_subnet = NUMBER_OF_COLUMNS // int(DATA_COLUMN_SIDECAR_SUBNET_COUNT) return sorted([ - ColumnIndex(DATA_COLUMN_SIDECAR_SUBNET_COUNT * i + subnet_id) + ColumnIndex(int(DATA_COLUMN_SIDECAR_SUBNET_COUNT) * i + subnet_id) for i in range(columns_per_subnet) for subnet_id in subnet_ids ]) @@ -222,7 +222,7 @@ def get_data_column_sidecars(signed_block: SignedBeaconBlock, Each node downloads and custodies a minimum of `CUSTODY_REQUIREMENT` subnets per slot. The particular subnets that the node is required to custody are selected pseudo-randomly (more on this below). -A node *may* choose to custody and serve more than the minimum honesty requirement. Such a node explicitly advertises a number greater than `CUSTODY_REQUIREMENT` via the peer discovery mechanism -- for example, in their ENR (e.g. `custody_subnet_count: 4` if the node custodies `4` subnets each slot) -- up to a `DATA_COLUMN_SIDECAR_SUBNET_COUNT` (i.e. a super-full node). +A node *may* choose to custody and serve more than the minimum honesty requirement. Such a node explicitly advertises a number greater than `CUSTODY_REQUIREMENT` through the peer discovery mechanism, specifically by setting a higher value in the `custody_subnet_count` field within its ENR. This value can be increased up to `DATA_COLUMN_SIDECAR_SUBNET_COUNT`, indicating a super-full node. A node stores the custodied columns for the duration of the pruning period and responds to peer requests for samples on those columns. diff --git a/specs/_features/eip7594/p2p-interface.md b/specs/_features/eip7594/p2p-interface.md index 1b25c5fc5..38797a2fb 100644 --- a/specs/_features/eip7594/p2p-interface.md +++ b/specs/_features/eip7594/p2p-interface.md @@ -119,14 +119,14 @@ The `MetaData` stored locally by clients is updated with an additional field to seq_number: uint64 attnets: Bitvector[ATTESTATION_SUBNET_COUNT] syncnets: Bitvector[SYNC_COMMITTEE_SUBNET_COUNT] - custody_subnet_count: uint64 + custody_subnet_count: uint8 # csc ) ``` Where - `seq_number`, `attnets`, and `syncnets` have the same meaning defined in the Altair document. -- `custody_subnet_count` represents the node's custody subnet count. Clients MAY reject ENRs with a value less than `CUSTODY_REQUIREMENT`. +- `csc` represents the node's custody subnet count. Clients MAY reject ENRs with a value less than `CUSTODY_REQUIREMENT`. ### The gossip domain: gossipsub @@ -322,6 +322,6 @@ Requests the MetaData of a peer, using the new `MetaData` definition given above A new field is added to the ENR under the key `csc` to facilitate custody data column discovery. -| Key | Value | -|--------|------------------------------------------| -| `csc` | Custody subnet count, big endian integer | +| Key | Value | +|--------|-------------------------------------| +| `csc` | Custody subnet count, uint8 integer | diff --git a/tests/core/pyspec/eth2spec/test/eip7594/networking/test_get_custody_columns.py b/tests/core/pyspec/eth2spec/test/eip7594/networking/test_get_custody_columns.py index b41f19a6c..692b73e49 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/networking/test_get_custody_columns.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/networking/test_get_custody_columns.py @@ -20,7 +20,7 @@ def _run_get_custody_columns(spec, rng, node_id=None, custody_subnet_count=None) assert len(result) == len(set(result)) assert len(result) == ( - custody_subnet_count * spec.config.NUMBER_OF_COLUMNS // spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT + int(custody_subnet_count) * spec.config.NUMBER_OF_COLUMNS // int(spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT) ) assert all(i < spec.config.NUMBER_OF_COLUMNS for i in result) python_list_result = [int(i) for i in result] diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_config_invariants.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_config_invariants.py index fc54cc308..fbbae4e8f 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_config_invariants.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_config_invariants.py @@ -3,6 +3,7 @@ from eth2spec.test.context import ( spec_test, with_eip7594_and_later, ) +from eth2spec.utils.ssz.ssz_typing import uint8 @with_eip7594_and_later @@ -12,9 +13,10 @@ def test_invariants(spec): assert spec.FIELD_ELEMENTS_PER_BLOB % spec.FIELD_ELEMENTS_PER_CELL == 0 assert spec.FIELD_ELEMENTS_PER_EXT_BLOB % spec.config.NUMBER_OF_COLUMNS == 0 assert spec.config.SAMPLES_PER_SLOT <= spec.config.NUMBER_OF_COLUMNS + assert spec.config.NUMBER_OF_COLUMNS == uint8(spec.config.NUMBER_OF_COLUMNS) # ENR field is uint8 assert spec.config.CUSTODY_REQUIREMENT <= spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT assert spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT <= spec.config.NUMBER_OF_COLUMNS - assert spec.config.NUMBER_OF_COLUMNS % spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT == 0 + assert spec.config.NUMBER_OF_COLUMNS % int(spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT) == 0 assert spec.config.MAX_REQUEST_DATA_COLUMN_SIDECARS == ( spec.config.MAX_REQUEST_BLOCKS_DENEB * spec.config.NUMBER_OF_COLUMNS ) diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_custody.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_custody.py index 5db3635a8..27aee3457 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_custody.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_custody.py @@ -9,9 +9,9 @@ from eth2spec.test.context import ( def run_get_custody_columns(spec, peer_count, custody_subnet_count): assignments = [spec.get_custody_columns(node_id, custody_subnet_count) for node_id in range(peer_count)] - columns_per_subnet = spec.config.NUMBER_OF_COLUMNS // spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT + columns_per_subnet = spec.config.NUMBER_OF_COLUMNS // int(spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT) for assignment in assignments: - assert len(assignment) == custody_subnet_count * columns_per_subnet + assert len(assignment) == int(custody_subnet_count) * columns_per_subnet assert len(assignment) == len(set(assignment)) From c7631634fb90a13e6f2de0be26b7499f6270bfa8 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Wed, 28 Aug 2024 16:01:10 -0600 Subject: [PATCH 16/19] harmonize `process_withdrawals` spec with #3761 --- specs/electra/beacon-chain.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index cb5ee6a7a..b18006b64 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -1022,10 +1022,9 @@ def get_expected_withdrawals(state: BeaconState) -> Tuple[Sequence[Withdrawal], def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None: expected_withdrawals, partial_withdrawals_count = get_expected_withdrawals(state) # [Modified in Electra:EIP7251] - assert len(payload.withdrawals) == len(expected_withdrawals) + assert payload.withdrawals == expected_withdrawals - for expected_withdrawal, withdrawal in zip(expected_withdrawals, payload.withdrawals): - assert withdrawal == expected_withdrawal + for withdrawal in expected_withdrawals: decrease_balance(state, withdrawal.validator_index, withdrawal.amount) # Update pending partial withdrawals [New in Electra:EIP7251] From 78cc0a6e9162e7a48d3debd3ca3046b27942c42b Mon Sep 17 00:00:00 2001 From: Pawan Dhananjay Date: Fri, 30 Aug 2024 12:25:26 -0700 Subject: [PATCH 17/19] Change csc types to uint64 --- specs/_features/eip7594/das-core.md | 10 +++++----- specs/_features/eip7594/p2p-interface.md | 10 +++++----- .../eip7594/networking/test_get_custody_columns.py | 2 +- .../test/eip7594/unittests/test_config_invariants.py | 4 +--- .../eth2spec/test/eip7594/unittests/test_custody.py | 4 ++-- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/specs/_features/eip7594/das-core.md b/specs/_features/eip7594/das-core.md index 59011cdcd..25e58a133 100644 --- a/specs/_features/eip7594/das-core.md +++ b/specs/_features/eip7594/das-core.md @@ -67,7 +67,7 @@ The following values are (non-configurable) constants used throughout the specif | Name | Value | Description | | - | - | - | -| `DATA_COLUMN_SIDECAR_SUBNET_COUNT` | `uint8(128)` | The number of data column sidecar subnets used in the gossipsub protocol | +| `DATA_COLUMN_SIDECAR_SUBNET_COUNT` | `uint64(128)` | The number of data column sidecar subnets used in the gossipsub protocol | ### Custody setting @@ -105,7 +105,7 @@ class MatrixEntry(Container): ### `get_custody_columns` ```python -def get_custody_columns(node_id: NodeID, custody_subnet_count: uint8) -> Sequence[ColumnIndex]: +def get_custody_columns(node_id: NodeID, custody_subnet_count: uint64) -> Sequence[ColumnIndex]: assert custody_subnet_count <= DATA_COLUMN_SIDECAR_SUBNET_COUNT subnet_ids: List[uint64] = [] @@ -113,7 +113,7 @@ def get_custody_columns(node_id: NodeID, custody_subnet_count: uint8) -> Sequenc while len(subnet_ids) < custody_subnet_count: subnet_id = ( bytes_to_uint64(hash(uint_to_bytes(uint256(current_id)))[0:8]) - % int(DATA_COLUMN_SIDECAR_SUBNET_COUNT) + % DATA_COLUMN_SIDECAR_SUBNET_COUNT ) if subnet_id not in subnet_ids: subnet_ids.append(subnet_id) @@ -124,9 +124,9 @@ def get_custody_columns(node_id: NodeID, custody_subnet_count: uint8) -> Sequenc assert len(subnet_ids) == len(set(subnet_ids)) - columns_per_subnet = NUMBER_OF_COLUMNS // int(DATA_COLUMN_SIDECAR_SUBNET_COUNT) + columns_per_subnet = NUMBER_OF_COLUMNS // DATA_COLUMN_SIDECAR_SUBNET_COUNT return sorted([ - ColumnIndex(int(DATA_COLUMN_SIDECAR_SUBNET_COUNT) * i + subnet_id) + ColumnIndex(DATA_COLUMN_SIDECAR_SUBNET_COUNT * i + subnet_id) for i in range(columns_per_subnet) for subnet_id in subnet_ids ]) diff --git a/specs/_features/eip7594/p2p-interface.md b/specs/_features/eip7594/p2p-interface.md index 38797a2fb..7f68f7ba6 100644 --- a/specs/_features/eip7594/p2p-interface.md +++ b/specs/_features/eip7594/p2p-interface.md @@ -119,14 +119,14 @@ The `MetaData` stored locally by clients is updated with an additional field to seq_number: uint64 attnets: Bitvector[ATTESTATION_SUBNET_COUNT] syncnets: Bitvector[SYNC_COMMITTEE_SUBNET_COUNT] - custody_subnet_count: uint8 # csc + custody_subnet_count: uint64 # csc ) ``` Where - `seq_number`, `attnets`, and `syncnets` have the same meaning defined in the Altair document. -- `csc` represents the node's custody subnet count. Clients MAY reject ENRs with a value less than `CUSTODY_REQUIREMENT`. +- `custody_subnet_count` represents the node's custody subnet count. Clients MAY reject peers with a value less than `CUSTODY_REQUIREMENT`. ### The gossip domain: gossipsub @@ -322,6 +322,6 @@ Requests the MetaData of a peer, using the new `MetaData` definition given above A new field is added to the ENR under the key `csc` to facilitate custody data column discovery. -| Key | Value | -|--------|-------------------------------------| -| `csc` | Custody subnet count, uint8 integer | +| Key | Value | +|--------|------------------------------------------| +| `csc` | Custody subnet count, big endian integer | diff --git a/tests/core/pyspec/eth2spec/test/eip7594/networking/test_get_custody_columns.py b/tests/core/pyspec/eth2spec/test/eip7594/networking/test_get_custody_columns.py index 692b73e49..b41f19a6c 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/networking/test_get_custody_columns.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/networking/test_get_custody_columns.py @@ -20,7 +20,7 @@ def _run_get_custody_columns(spec, rng, node_id=None, custody_subnet_count=None) assert len(result) == len(set(result)) assert len(result) == ( - int(custody_subnet_count) * spec.config.NUMBER_OF_COLUMNS // int(spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT) + custody_subnet_count * spec.config.NUMBER_OF_COLUMNS // spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT ) assert all(i < spec.config.NUMBER_OF_COLUMNS for i in result) python_list_result = [int(i) for i in result] diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_config_invariants.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_config_invariants.py index fbbae4e8f..fc54cc308 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_config_invariants.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_config_invariants.py @@ -3,7 +3,6 @@ from eth2spec.test.context import ( spec_test, with_eip7594_and_later, ) -from eth2spec.utils.ssz.ssz_typing import uint8 @with_eip7594_and_later @@ -13,10 +12,9 @@ def test_invariants(spec): assert spec.FIELD_ELEMENTS_PER_BLOB % spec.FIELD_ELEMENTS_PER_CELL == 0 assert spec.FIELD_ELEMENTS_PER_EXT_BLOB % spec.config.NUMBER_OF_COLUMNS == 0 assert spec.config.SAMPLES_PER_SLOT <= spec.config.NUMBER_OF_COLUMNS - assert spec.config.NUMBER_OF_COLUMNS == uint8(spec.config.NUMBER_OF_COLUMNS) # ENR field is uint8 assert spec.config.CUSTODY_REQUIREMENT <= spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT assert spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT <= spec.config.NUMBER_OF_COLUMNS - assert spec.config.NUMBER_OF_COLUMNS % int(spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT) == 0 + assert spec.config.NUMBER_OF_COLUMNS % spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT == 0 assert spec.config.MAX_REQUEST_DATA_COLUMN_SIDECARS == ( spec.config.MAX_REQUEST_BLOCKS_DENEB * spec.config.NUMBER_OF_COLUMNS ) diff --git a/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_custody.py b/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_custody.py index 27aee3457..5db3635a8 100644 --- a/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_custody.py +++ b/tests/core/pyspec/eth2spec/test/eip7594/unittests/test_custody.py @@ -9,9 +9,9 @@ from eth2spec.test.context import ( def run_get_custody_columns(spec, peer_count, custody_subnet_count): assignments = [spec.get_custody_columns(node_id, custody_subnet_count) for node_id in range(peer_count)] - columns_per_subnet = spec.config.NUMBER_OF_COLUMNS // int(spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT) + columns_per_subnet = spec.config.NUMBER_OF_COLUMNS // spec.config.DATA_COLUMN_SIDECAR_SUBNET_COUNT for assignment in assignments: - assert len(assignment) == int(custody_subnet_count) * columns_per_subnet + assert len(assignment) == custody_subnet_count * columns_per_subnet assert len(assignment) == len(set(assignment)) From 6938dcc2fa2698a58989aa99f29ab3dea270bee9 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 30 Aug 2024 16:16:44 -0600 Subject: [PATCH 18/19] simplify name of helper `get_validator_max_effective_balance` --- specs/electra/beacon-chain.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index b18006b64..8565379ec 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -50,7 +50,7 @@ - [Modified `is_partially_withdrawable_validator`](#modified-is_partially_withdrawable_validator) - [Misc](#misc-1) - [New `get_committee_indices`](#new-get_committee_indices) - - [New `get_validator_max_effective_balance`](#new-get_validator_max_effective_balance) + - [New `get_max_effective_balance`](#new-get_max_effective_balance) - [Beacon state accessors](#beacon-state-accessors) - [New `get_balance_churn_limit`](#new-get_balance_churn_limit) - [New `get_activation_exit_churn_limit`](#new-get_activation_exit_churn_limit) @@ -512,14 +512,14 @@ def is_fully_withdrawable_validator(validator: Validator, balance: Gwei, epoch: #### Modified `is_partially_withdrawable_validator` -*Note*: The function `is_partially_withdrawable_validator` is modified to use `get_validator_max_effective_balance` instead of `MAX_EFFECTIVE_BALANCE` and `has_execution_withdrawal_credential` instead of `has_eth1_withdrawal_credential`. +*Note*: The function `is_partially_withdrawable_validator` is modified to use `get_max_effective_balance` instead of `MAX_EFFECTIVE_BALANCE` and `has_execution_withdrawal_credential` instead of `has_eth1_withdrawal_credential`. ```python def is_partially_withdrawable_validator(validator: Validator, balance: Gwei) -> bool: """ Check if ``validator`` is partially withdrawable. """ - max_effective_balance = get_validator_max_effective_balance(validator) + max_effective_balance = get_max_effective_balance(validator) has_max_effective_balance = validator.effective_balance == max_effective_balance # [Modified in Electra:EIP7251] has_excess_balance = balance > max_effective_balance # [Modified in Electra:EIP7251] return ( @@ -538,10 +538,10 @@ def get_committee_indices(committee_bits: Bitvector) -> Sequence[CommitteeIndex] return [CommitteeIndex(index) for index, bit in enumerate(committee_bits) if bit] ``` -#### New `get_validator_max_effective_balance` +#### New `get_max_effective_balance` ```python -def get_validator_max_effective_balance(validator: Validator) -> Gwei: +def get_max_effective_balance(validator: Validator) -> Gwei: """ Get max effective balance for ``validator``. """ @@ -588,7 +588,7 @@ def get_consolidation_churn_limit(state: BeaconState) -> Gwei: ```python def get_active_balance(state: BeaconState, validator_index: ValidatorIndex) -> Gwei: - max_effective_balance = get_validator_max_effective_balance(state.validators[validator_index]) + max_effective_balance = get_max_effective_balance(state.validators[validator_index]) return min(state.balances[validator_index], max_effective_balance) ``` @@ -875,7 +875,7 @@ def process_pending_balance_deposits(state: BeaconState) -> None: if processed_amount + deposit.amount > available_for_processing: break # Deposit fits in the churn, process it. Increase balance and consume churn. - else: + else: increase_balance(state, deposit.index, deposit.amount) processed_amount += deposit.amount # Regardless of how the deposit was handled, we move on in the queue. @@ -1005,7 +1005,7 @@ def get_expected_withdrawals(state: BeaconState) -> Tuple[Sequence[Withdrawal], index=withdrawal_index, validator_index=validator_index, address=ExecutionAddress(validator.withdrawal_credentials[12:]), - amount=balance - get_validator_max_effective_balance(validator), # [Modified in Electra:EIP7251] + amount=balance - get_max_effective_balance(validator), # [Modified in Electra:EIP7251] )) withdrawal_index += WithdrawalIndex(1) if len(withdrawals) == MAX_WITHDRAWALS_PER_PAYLOAD: @@ -1495,7 +1495,7 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32, balance = state.balances[index] # [Modified in Electra:EIP7251] validator.effective_balance = min( - balance - balance % EFFECTIVE_BALANCE_INCREMENT, get_validator_max_effective_balance(validator)) + balance - balance % EFFECTIVE_BALANCE_INCREMENT, get_max_effective_balance(validator)) if validator.effective_balance >= MIN_ACTIVATION_BALANCE: validator.activation_eligibility_epoch = GENESIS_EPOCH validator.activation_epoch = GENESIS_EPOCH From 88a76574b6f6ee3ee63c2e433f67de50d32762e5 Mon Sep 17 00:00:00 2001 From: Justin Traglia <95511699+jtraglia@users.noreply.github.com> Date: Tue, 3 Sep 2024 09:35:02 -0500 Subject: [PATCH 19/19] Update csc description Co-authored-by: Anton Nashatyrev --- specs/_features/eip7594/p2p-interface.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/_features/eip7594/p2p-interface.md b/specs/_features/eip7594/p2p-interface.md index 7f68f7ba6..9087a8210 100644 --- a/specs/_features/eip7594/p2p-interface.md +++ b/specs/_features/eip7594/p2p-interface.md @@ -324,4 +324,4 @@ A new field is added to the ENR under the key `csc` to facilitate custody data c | Key | Value | |--------|------------------------------------------| -| `csc` | Custody subnet count, big endian integer | +| `csc` | Custody subnet count, `uint64` big endian integer with no leading zero bytes (`0` is encoded as empty byte string) |