From f5fb78d5156278f14c6dde98660c5865285c1361 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 7 May 2024 09:37:19 -0500 Subject: [PATCH 1/5] Encode empty hex-string with quotes --- .../pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py b/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py index 3ab2e9eea..bc7154ecf 100644 --- a/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py +++ b/tests/core/pyspec/eth2spec/gen_helpers/gen_base/gen_runner.py @@ -65,7 +65,14 @@ def get_default_yaml(): def _represent_none(self, _): return self.represent_scalar('tag:yaml.org,2002:null', 'null') + def _represent_str(self, data): + if data.startswith("0x"): + # Without this, a zero-byte hex string is represented without quotes. + return self.represent_scalar('tag:yaml.org,2002:str', data, style="'") + return self.represent_str(data) + yaml.representer.add_representer(type(None), _represent_none) + yaml.representer.add_representer(str, _represent_str) return yaml From dc772a6dca031ea41e8b8976822c3a84a49d907a Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Tue, 22 Oct 2024 13:33:00 -0500 Subject: [PATCH 2/5] Add test_fork_pending_deposits_are_sorted test --- .../electra/fork/test_electra_fork_basic.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_basic.py b/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_basic.py index e569be35e..bf97746db 100644 --- a/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_basic.py +++ b/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_basic.py @@ -94,6 +94,27 @@ def test_fork_pre_activation(spec, phases, state): assert len(post_state.pending_deposits) > 0 +@with_phases(phases=[DENEB], other_phases=[ELECTRA]) +@spec_test +@with_state +@with_meta_tags(ELECTRA_FORK_TEST_META_TAGS) +def test_fork_pending_deposits_are_sorted(spec, phases, state): + post_spec = phases[ELECTRA] + state.validators[0].activation_epoch = spec.FAR_FUTURE_EPOCH + state.validators[0].activation_eligibility_epoch = 2 + state.validators[1].activation_epoch = spec.FAR_FUTURE_EPOCH + state.validators[1].activation_eligibility_epoch = 3 + state.validators[2].activation_epoch = spec.FAR_FUTURE_EPOCH + state.validators[2].activation_eligibility_epoch = 2 + + post_state = yield from run_fork_test(post_spec, state) + + assert len(post_state.pending_deposits) == 3 + assert post_state.pending_deposits[0].pubkey == state.validators[0].pubkey + assert post_state.pending_deposits[1].pubkey == state.validators[2].pubkey + assert post_state.pending_deposits[2].pubkey == state.validators[1].pubkey + + @with_phases(phases=[DENEB], other_phases=[ELECTRA]) @spec_test @with_state From 9507b86bebb02e149f675b0fa1859aee91fe118e Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Wed, 23 Oct 2024 09:57:05 -0500 Subject: [PATCH 3/5] Add one more validator --- .../test/electra/fork/test_electra_fork_basic.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_basic.py b/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_basic.py index bf97746db..884bfcb4e 100644 --- a/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_basic.py +++ b/tests/core/pyspec/eth2spec/test/electra/fork/test_electra_fork_basic.py @@ -106,13 +106,16 @@ def test_fork_pending_deposits_are_sorted(spec, phases, state): state.validators[1].activation_eligibility_epoch = 3 state.validators[2].activation_epoch = spec.FAR_FUTURE_EPOCH state.validators[2].activation_eligibility_epoch = 2 + state.validators[3].activation_epoch = spec.FAR_FUTURE_EPOCH + state.validators[3].activation_eligibility_epoch = 1 post_state = yield from run_fork_test(post_spec, state) - assert len(post_state.pending_deposits) == 3 - assert post_state.pending_deposits[0].pubkey == state.validators[0].pubkey - assert post_state.pending_deposits[1].pubkey == state.validators[2].pubkey - assert post_state.pending_deposits[2].pubkey == state.validators[1].pubkey + assert len(post_state.pending_deposits) == 4 + assert post_state.pending_deposits[0].pubkey == state.validators[3].pubkey + assert post_state.pending_deposits[1].pubkey == state.validators[0].pubkey + assert post_state.pending_deposits[2].pubkey == state.validators[2].pubkey + assert post_state.pending_deposits[3].pubkey == state.validators[1].pubkey @with_phases(phases=[DENEB], other_phases=[ELECTRA]) From 3a4101b3e4a219498dccf96971cc526c8aafb531 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Wed, 23 Oct 2024 14:20:53 -0500 Subject: [PATCH 4/5] Rename index vars in get_attesting_indices() --- specs/electra/beacon-chain.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 0c5649190..ca6c58845 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -572,10 +572,12 @@ def get_attesting_indices(state: BeaconState, attestation: Attestation) -> Set[V output: Set[ValidatorIndex] = set() committee_indices = get_committee_indices(attestation.committee_bits) committee_offset = 0 - for index in committee_indices: - committee = get_beacon_committee(state, attestation.data.slot, index) + for committee_index in committee_indices: + committee = get_beacon_committee(state, attestation.data.slot, committee_index) committee_attesters = set( - index for i, index in enumerate(committee) if attestation.aggregation_bits[committee_offset + i]) + attester_index for i, attester_index in enumerate(committee) + if attestation.aggregation_bits[committee_offset + i] + ) output = output.union(committee_attesters) committee_offset += len(committee) From 90ae0a4ecfb36da82a7c353f15f66652f561aeeb Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Thu, 24 Oct 2024 14:48:49 -0500 Subject: [PATCH 5/5] Group pending types & request types --- specs/electra/beacon-chain.md | 51 ++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/specs/electra/beacon-chain.md b/specs/electra/beacon-chain.md index 0c5649190..3813a1f44 100644 --- a/specs/electra/beacon-chain.md +++ b/specs/electra/beacon-chain.md @@ -24,12 +24,12 @@ - [Validator cycle](#validator-cycle) - [Containers](#containers) - [New containers](#new-containers) - - [`DepositRequest`](#depositrequest) - [`PendingDeposit`](#pendingdeposit) - [`PendingPartialWithdrawal`](#pendingpartialwithdrawal) + - [`PendingConsolidation`](#pendingconsolidation) + - [`DepositRequest`](#depositrequest) - [`WithdrawalRequest`](#withdrawalrequest) - [`ConsolidationRequest`](#consolidationrequest) - - [`PendingConsolidation`](#pendingconsolidation) - [`ExecutionRequests`](#executionrequests) - [Modified Containers](#modified-containers) - [`AttesterSlashing`](#attesterslashing) @@ -201,19 +201,6 @@ The following values are (non-configurable) constants used throughout the specif ### New containers -#### `DepositRequest` - -*Note*: The container is new in EIP6110. - -```python -class DepositRequest(Container): - pubkey: BLSPubkey - withdrawal_credentials: Bytes32 - amount: Gwei - signature: BLSSignature - index: uint64 -``` - #### `PendingDeposit` *Note*: The container is new in EIP7251. @@ -237,6 +224,30 @@ class PendingPartialWithdrawal(Container): amount: Gwei withdrawable_epoch: Epoch ``` + +#### `PendingConsolidation` + +*Note*: The container is new in EIP7251. + +```python +class PendingConsolidation(Container): + source_index: ValidatorIndex + target_index: ValidatorIndex +``` + +#### `DepositRequest` + +*Note*: The container is new in EIP6110. + +```python +class DepositRequest(Container): + pubkey: BLSPubkey + withdrawal_credentials: Bytes32 + amount: Gwei + signature: BLSSignature + index: uint64 +``` + #### `WithdrawalRequest` *Note*: The container is new in EIP7251:EIP7002. @@ -259,16 +270,6 @@ class ConsolidationRequest(Container): target_pubkey: BLSPubkey ``` -#### `PendingConsolidation` - -*Note*: The container is new in EIP7251. - -```python -class PendingConsolidation(Container): - source_index: ValidatorIndex - target_index: ValidatorIndex -``` - #### `ExecutionRequests` *Note*: This container holds requests from the execution layer that are received in [