From cda10d059b61bc610493509803120e92c1bdf85b Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Wed, 27 Mar 2024 16:49:12 +0600 Subject: [PATCH 01/25] Refactor EL withdraw request processing --- specs/_features/eip7251/beacon-chain.md | 29 +++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index c4aad0a6f..19fb7a91d 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -8,6 +8,7 @@ - [Introduction](#introduction) - [Constants](#constants) + - [Misc](#misc) - [Withdrawal prefixes](#withdrawal-prefixes) - [Domains](#domains) - [Presets](#presets) @@ -87,6 +88,12 @@ See [a modest proposal](https://notes.ethereum.org/@mikeneuder/increase-maxeb), The following values are (non-configurable) constants used throughout the specification. +### Misc + +| Name | Value | +| - | - | +| `FULL_EXIT_REQUEST_AMOUNT` | `uint64(2**64 - 1)` | + ### Withdrawal prefixes | Name | Value | @@ -866,7 +873,8 @@ def process_execution_layer_withdraw_request( execution_layer_withdraw_request: ExecutionLayerWithdrawRequest ) -> None: amount = execution_layer_withdraw_request.amount - is_full_exit_request = amount == 0 + is_full_exit_request = amount == FULL_EXIT_REQUEST_AMOUNT + # If partial withdrawal queue is full, only full exits are processed if len(state.pending_partial_withdrawals) >= PENDING_PARTIAL_WITHDRAWALS_LIMIT and not is_full_exit_request: return @@ -888,20 +896,23 @@ def process_execution_layer_withdraw_request( and get_current_epoch(state) >= validator.activation_epoch + SHARD_COMMITTEE_PERIOD ): return - # New condition: only allow partial withdrawals with compounding withdrawal credentials - if not (is_full_exit_request or has_compounding_withdrawal_credential(validator)): - return pending_balance_to_withdraw = sum( item.amount for item in state.pending_partial_withdrawals if item.index == index ) - # only exit validator if it has no pending withdrawals in the queue - if is_full_exit_request and pending_balance_to_withdraw > 0: - return if is_full_exit_request: - initiate_validator_exit(state, index) - elif state.balances[index] > MIN_ACTIVATION_BALANCE + pending_balance_to_withdraw: + # Only exit validator if it has no pending withdrawals in the queue + if pending_balance_to_withdraw == 0: + initiate_validator_exit(state, index) + + return + + + has_excess_balance = state.balances[index] > MIN_ACTIVATION_BALANCE + pending_balance_to_withdraw + + # Only allow partial withdrawals with compounding withdrawal credentials + if has_compounding_withdrawal_credential(validator) and has_excess_balance: to_withdraw = min( state.balances[index] - MIN_ACTIVATION_BALANCE - pending_balance_to_withdraw, amount From 6f5cc4baf5e6b8cb9b753085fb9738c540147b8a Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Wed, 27 Mar 2024 17:35:27 +0600 Subject: [PATCH 02/25] Replace MIN_ACTIVATION_BALANCE with MAX_EFFECTIVE_BALANCE --- specs/_features/eip7251/beacon-chain.md | 28 +++++++++---------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index 19fb7a91d..b7c2ffdb1 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -373,7 +373,7 @@ def get_validator_max_effective_balance(validator: Validator) -> Gwei: if has_compounding_withdrawal_credential(validator): return MAX_EFFECTIVE_BALANCE_EIP7251 else: - return MIN_ACTIVATION_BALANCE + return MAX_EFFECTIVE_BALANCE ``` #### New `get_churn_limit` @@ -411,12 +411,8 @@ def get_consolidation_churn_limit(state: BeaconState) -> Gwei: ```python def get_active_balance(state: BeaconState, validator_index: ValidatorIndex) -> Gwei: - active_balance_ceil = ( - MIN_ACTIVATION_BALANCE - if has_eth1_withdrawal_credential(state.validators[validator_index]) - else MAX_EFFECTIVE_BALANCE_EIP7251 - ) - return min(state.balances[validator_index], active_balance_ceil) + max_effective_balance = get_validator_max_effective_balance(state.validators[validator_index]) + return min(state.balances[validator_index], max_effective_balance) ``` ### Beacon state mutators @@ -649,16 +645,12 @@ def process_effective_balance_updates(state: BeaconState) -> None: HYSTERESIS_INCREMENT = uint64(EFFECTIVE_BALANCE_INCREMENT // HYSTERESIS_QUOTIENT) DOWNWARD_THRESHOLD = HYSTERESIS_INCREMENT * HYSTERESIS_DOWNWARD_MULTIPLIER UPWARD_THRESHOLD = HYSTERESIS_INCREMENT * HYSTERESIS_UPWARD_MULTIPLIER - EFFECTIVE_BALANCE_LIMIT = ( - MAX_EFFECTIVE_BALANCE_EIP7251 if has_compounding_withdrawal_credential(validator) - else MIN_ACTIVATION_BALANCE - ) - + max_effective_balance = get_validator_max_effective_balance(validator) if ( balance + DOWNWARD_THRESHOLD < validator.effective_balance or validator.effective_balance + UPWARD_THRESHOLD < balance ): - validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, EFFECTIVE_BALANCE_LIMIT) + validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, max_effective_balance) # [Modified in EIP7251] ``` ### Block processing @@ -689,8 +681,8 @@ def get_expected_withdrawals(state: BeaconState) -> Tuple[Sequence[Withdrawal], break validator = state.validators[withdrawal.index] - if validator.exit_epoch == FAR_FUTURE_EPOCH and state.balances[withdrawal.index] > MIN_ACTIVATION_BALANCE: - withdrawable_balance = min(state.balances[withdrawal.index] - MIN_ACTIVATION_BALANCE, withdrawal.amount) + if validator.exit_epoch == FAR_FUTURE_EPOCH and state.balances[withdrawal.index] > MAX_EFFECTIVE_BALANCE: + withdrawable_balance = min(state.balances[withdrawal.index] - MAX_EFFECTIVE_BALANCE, withdrawal.amount) withdrawals.append(Withdrawal( index=withdrawal_index, validator_index=withdrawal.index, @@ -909,12 +901,12 @@ def process_execution_layer_withdraw_request( return - has_excess_balance = state.balances[index] > MIN_ACTIVATION_BALANCE + pending_balance_to_withdraw + has_excess_balance = state.balances[index] > MAX_EFFECTIVE_BALANCE + pending_balance_to_withdraw # Only allow partial withdrawals with compounding withdrawal credentials if has_compounding_withdrawal_credential(validator) and has_excess_balance: to_withdraw = min( - state.balances[index] - MIN_ACTIVATION_BALANCE - pending_balance_to_withdraw, + state.balances[index] - MAX_EFFECTIVE_BALANCE - pending_balance_to_withdraw, amount ) exit_queue_epoch = compute_exit_epoch_and_update_churn(state, to_withdraw) @@ -935,7 +927,7 @@ def process_consolidation(state: BeaconState, signed_consolidation: SignedConsol # If the pending consolidations queue is full, no consolidations are allowed in the block assert len(state.pending_consolidations) < PENDING_CONSOLIDATIONS_LIMIT # If there is too little available consolidation churn limit, no consolidations are allowed in the block - assert get_consolidation_churn_limit(state) > MIN_ACTIVATION_BALANCE + assert get_consolidation_churn_limit(state) > MAX_EFFECTIVE_BALANCE consolidation = signed_consolidation.message # Verify that source != target, so a consolidation cannot be used as an exit. assert consolidation.source_index != consolidation.target_index From 31142b0ba18572c888618bd8ef87deb1dd96bc92 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Wed, 27 Mar 2024 17:41:00 +0600 Subject: [PATCH 03/25] Require sufficient EB to emit partial withdrawal --- specs/_features/eip7251/beacon-chain.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index b7c2ffdb1..2035180af 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -681,7 +681,9 @@ def get_expected_withdrawals(state: BeaconState) -> Tuple[Sequence[Withdrawal], break validator = state.validators[withdrawal.index] - if validator.exit_epoch == FAR_FUTURE_EPOCH and state.balances[withdrawal.index] > MAX_EFFECTIVE_BALANCE: + has_sufficient_effective_balance = validator.effective_balance == MAX_EFFECTIVE_BALANCE + has_excess_balance = state.balances[withdrawal.index] > MAX_EFFECTIVE_BALANCE + if validator.exit_epoch == FAR_FUTURE_EPOCH and has_sufficient_effective_balance and has_excess_balance: withdrawable_balance = min(state.balances[withdrawal.index] - MAX_EFFECTIVE_BALANCE, withdrawal.amount) withdrawals.append(Withdrawal( index=withdrawal_index, @@ -901,10 +903,11 @@ def process_execution_layer_withdraw_request( return + has_sufficient_effective_balance = validator.effective_balance == MAX_EFFECTIVE_BALANCE has_excess_balance = state.balances[index] > MAX_EFFECTIVE_BALANCE + pending_balance_to_withdraw # Only allow partial withdrawals with compounding withdrawal credentials - if has_compounding_withdrawal_credential(validator) and has_excess_balance: + if has_compounding_withdrawal_credential(validator) and has_sufficient_effective_balance and has_excess_balance: to_withdraw = min( state.balances[index] - MAX_EFFECTIVE_BALANCE - pending_balance_to_withdraw, amount From 46638d31baf38b5d2b8178b7b51343822438b548 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Wed, 27 Mar 2024 17:42:10 +0600 Subject: [PATCH 04/25] Remove unused method --- specs/_features/eip7251/beacon-chain.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index 2035180af..e8c4e8a51 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -46,7 +46,6 @@ - [New `get_active_balance`](#new-get_active_balance) - [Beacon state mutators](#beacon-state-mutators) - [Updated `initiate_validator_exit`](#updated--initiate_validator_exit) - - [New `set_compounding_withdrawal_credentials`](#new-set_compounding_withdrawal_credentials) - [New `switch_to_compounding_validator`](#new-switch_to_compounding_validator) - [New `queue_excess_active_balance`](#new-queue_excess_active_balance) - [New `compute_exit_epoch_and_update_churn`](#new-compute_exit_epoch_and_update_churn) @@ -437,15 +436,6 @@ def initiate_validator_exit(state: BeaconState, index: ValidatorIndex) -> None: validator.withdrawable_epoch = Epoch(validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY) ``` -#### New `set_compounding_withdrawal_credentials` - -```python -def set_compounding_withdrawal_credentials(state: BeaconState, index: ValidatorIndex) -> None: - validator = state.validators[index] - if has_eth1_withdrawal_credential(validator): - validator.withdrawal_credentials[:1] = COMPOUNDING_WITHDRAWAL_PREFIX -``` - #### New `switch_to_compounding_validator` ```python From 517f741f29a53ff8068283dc5ac8f694b5d5cc58 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Wed, 27 Mar 2024 17:57:54 +0600 Subject: [PATCH 05/25] Abort voluntary exit if validator has pending partial withdrawals --- specs/_features/eip7251/beacon-chain.md | 42 ++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index e8c4e8a51..3bd461566 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -44,6 +44,7 @@ - [New `get_activation_exit_churn_limit`](#new-get_activation_exit_churn_limit) - [New `get_consolidation_churn_limit`](#new-get_consolidation_churn_limit) - [New `get_active_balance`](#new-get_active_balance) + - [New `get_pending_balance_to_withdraw`](#new-get_pending_balance_to_withdraw) - [Beacon state mutators](#beacon-state-mutators) - [Updated `initiate_validator_exit`](#updated--initiate_validator_exit) - [New `switch_to_compounding_validator`](#new-switch_to_compounding_validator) @@ -72,6 +73,8 @@ - [New `process_execution_layer_withdraw_request`](#new-process_execution_layer_withdraw_request) - [Consolidations](#consolidations) - [New `process_consolidation`](#new-process_consolidation) + - [Voluntary exits](#voluntary-exits) + - [Updated `process_voluntary_exit`](#updated-process_voluntary_exit) @@ -414,6 +417,14 @@ def get_active_balance(state: BeaconState, validator_index: ValidatorIndex) -> G return min(state.balances[validator_index], max_effective_balance) ``` +#### New `get_pending_balance_to_withdraw` + +```python +def get_pending_balance_to_withdraw(state: BeaconState, validator_index: ValidatorIndex) -> Gwei: + return sum( + withdrawal.amount for withdrawal in state.pending_partial_withdrawals if withdrawal.index == validator_index) +``` + ### Beacon state mutators #### Updated `initiate_validator_exit` @@ -762,7 +773,7 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None: for_ops(body.attester_slashings, process_attester_slashing) for_ops(body.attestations, process_attestation) for_ops(body.deposits, process_deposit) # [Modified in EIP7251] - for_ops(body.voluntary_exits, process_voluntary_exit) + for_ops(body.voluntary_exits, process_voluntary_exit) # [Modified in EIP7251] for_ops(body.bls_to_execution_changes, process_bls_to_execution_change) for_ops(body.execution_payload.withdraw_requests, process_execution_layer_withdraw_request) # New in EIP7251 for_ops(body.consolidations, process_consolidation) # New in EIP7251 @@ -881,9 +892,7 @@ def process_execution_layer_withdraw_request( ): return - pending_balance_to_withdraw = sum( - item.amount for item in state.pending_partial_withdrawals if item.index == index - ) + pending_balance_to_withdraw = get_pending_balance_to_withdraw(state, index) if is_full_exit_request: # Only exit validator if it has no pending withdrawals in the queue @@ -961,3 +970,28 @@ def process_consolidation(state: BeaconState, signed_consolidation: SignedConsol )) ``` +##### Voluntary exits + +###### Updated `process_voluntary_exit` + +```python +def process_voluntary_exit(state: BeaconState, signed_voluntary_exit: SignedVoluntaryExit) -> None: + voluntary_exit = signed_voluntary_exit.message + validator = state.validators[voluntary_exit.validator_index] + # Verify the validator is active + assert is_active_validator(validator, get_current_epoch(state)) + # Verify exit has not been initiated + assert validator.exit_epoch == FAR_FUTURE_EPOCH + # Exits must specify an epoch when they become valid; they are not valid before then + assert get_current_epoch(state) >= voluntary_exit.epoch + # Verify the validator has been active long enough + assert get_current_epoch(state) >= validator.activation_epoch + SHARD_COMMITTEE_PERIOD + # Verify signature + domain = get_domain(state, DOMAIN_VOLUNTARY_EXIT, voluntary_exit.epoch) + signing_root = compute_signing_root(voluntary_exit, domain) + assert bls.Verify(validator.pubkey, signing_root, signed_voluntary_exit.signature) + # Only exit validator if it has no pending withdrawals in the queue + assert get_pending_balance_to_withdraw(state, voluntary_exit.validator_index) == 0 # [New in EIP7251] + # Initiate exit + initiate_validator_exit(state, voluntary_exit.validator_index) +``` \ No newline at end of file From 915f90e13eddf4ddfcc38b3b1b3d89a91d10b86c Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Wed, 27 Mar 2024 18:05:05 +0600 Subject: [PATCH 06/25] Strictly check withdrawal address upon consolidation --- specs/_features/eip7251/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index 3bd461566..366eabe4c 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -950,7 +950,7 @@ def process_consolidation(state: BeaconState, signed_consolidation: SignedConsol assert has_execution_withdrawal_credential(source_validator) assert has_execution_withdrawal_credential(target_validator) # Verify the same withdrawal address - assert source_validator.withdrawal_credentials[1:] == target_validator.withdrawal_credentials[1:] + assert source_validator.withdrawal_credentials[12:] == target_validator.withdrawal_credentials[12:] # Verify consolidation is signed by the source and the target domain = compute_domain(DOMAIN_CONSOLIDATION, genesis_validators_root=state.genesis_validators_root) From 534bcfc116980efe92a032115f883e79d4825393 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Thu, 28 Mar 2024 11:49:44 +0600 Subject: [PATCH 07/25] Use source.effective_balance for consolidaiton churn --- specs/_features/eip7251/beacon-chain.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index 366eabe4c..a0bc3bc8d 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -959,8 +959,8 @@ def process_consolidation(state: BeaconState, signed_consolidation: SignedConsol assert bls.FastAggregateVerify(pubkeys, signing_root, signed_consolidation.signature) # Initiate source validator exit and append pending consolidation - active_balance = get_active_balance(state, consolidation.source_index) - source_validator.exit_epoch = compute_consolidation_epoch_and_update_churn(state, active_balance) + source_validator.exit_epoch = compute_consolidation_epoch_and_update_churn( + state, source_validator.effective_balance) source_validator.withdrawable_epoch = Epoch( source_validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY ) From 7bbecfb7625ce1411d4cf902a9dc54be0f76165d Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Fri, 29 Mar 2024 15:27:12 +0600 Subject: [PATCH 08/25] Revert "Replace MIN_ACTIVATION_BALANCE with MAX_EFFECTIVE_BALANCE" This reverts commit 6f5cc4baf5e6b8cb9b753085fb9738c540147b8a. --- specs/_features/eip7251/beacon-chain.md | 32 +++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index a0bc3bc8d..db6d7601a 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -375,7 +375,7 @@ def get_validator_max_effective_balance(validator: Validator) -> Gwei: if has_compounding_withdrawal_credential(validator): return MAX_EFFECTIVE_BALANCE_EIP7251 else: - return MAX_EFFECTIVE_BALANCE + return MIN_ACTIVATION_BALANCE ``` #### New `get_churn_limit` @@ -413,8 +413,12 @@ 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]) - return min(state.balances[validator_index], max_effective_balance) + active_balance_ceil = ( + MIN_ACTIVATION_BALANCE + if has_eth1_withdrawal_credential(state.validators[validator_index]) + else MAX_EFFECTIVE_BALANCE_EIP7251 + ) + return min(state.balances[validator_index], active_balance_ceil) ``` #### New `get_pending_balance_to_withdraw` @@ -646,12 +650,16 @@ def process_effective_balance_updates(state: BeaconState) -> None: HYSTERESIS_INCREMENT = uint64(EFFECTIVE_BALANCE_INCREMENT // HYSTERESIS_QUOTIENT) DOWNWARD_THRESHOLD = HYSTERESIS_INCREMENT * HYSTERESIS_DOWNWARD_MULTIPLIER UPWARD_THRESHOLD = HYSTERESIS_INCREMENT * HYSTERESIS_UPWARD_MULTIPLIER - max_effective_balance = get_validator_max_effective_balance(validator) + EFFECTIVE_BALANCE_LIMIT = ( + MAX_EFFECTIVE_BALANCE_EIP7251 if has_compounding_withdrawal_credential(validator) + else MIN_ACTIVATION_BALANCE + ) + if ( balance + DOWNWARD_THRESHOLD < validator.effective_balance or validator.effective_balance + UPWARD_THRESHOLD < balance ): - validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, max_effective_balance) # [Modified in EIP7251] + validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, EFFECTIVE_BALANCE_LIMIT) ``` ### Block processing @@ -682,10 +690,10 @@ def get_expected_withdrawals(state: BeaconState) -> Tuple[Sequence[Withdrawal], break validator = state.validators[withdrawal.index] - has_sufficient_effective_balance = validator.effective_balance == MAX_EFFECTIVE_BALANCE - has_excess_balance = state.balances[withdrawal.index] > MAX_EFFECTIVE_BALANCE + has_sufficient_effective_balance = validator.effective_balance == MIN_ACTIVATION_BALANCE + has_excess_balance = state.balances[withdrawal.index] > MIN_ACTIVATION_BALANCE if validator.exit_epoch == FAR_FUTURE_EPOCH and has_sufficient_effective_balance and has_excess_balance: - withdrawable_balance = min(state.balances[withdrawal.index] - MAX_EFFECTIVE_BALANCE, withdrawal.amount) + withdrawable_balance = min(state.balances[withdrawal.index] - MIN_ACTIVATION_BALANCE, withdrawal.amount) withdrawals.append(Withdrawal( index=withdrawal_index, validator_index=withdrawal.index, @@ -902,13 +910,13 @@ def process_execution_layer_withdraw_request( return - has_sufficient_effective_balance = validator.effective_balance == MAX_EFFECTIVE_BALANCE - has_excess_balance = state.balances[index] > MAX_EFFECTIVE_BALANCE + pending_balance_to_withdraw + has_sufficient_effective_balance = validator.effective_balance == MIN_ACTIVATION_BALANCE + has_excess_balance = state.balances[index] > MIN_ACTIVATION_BALANCE + pending_balance_to_withdraw # Only allow partial withdrawals with compounding withdrawal credentials if has_compounding_withdrawal_credential(validator) and has_sufficient_effective_balance and has_excess_balance: to_withdraw = min( - state.balances[index] - MAX_EFFECTIVE_BALANCE - pending_balance_to_withdraw, + state.balances[index] - MIN_ACTIVATION_BALANCE - pending_balance_to_withdraw, amount ) exit_queue_epoch = compute_exit_epoch_and_update_churn(state, to_withdraw) @@ -929,7 +937,7 @@ def process_consolidation(state: BeaconState, signed_consolidation: SignedConsol # If the pending consolidations queue is full, no consolidations are allowed in the block assert len(state.pending_consolidations) < PENDING_CONSOLIDATIONS_LIMIT # If there is too little available consolidation churn limit, no consolidations are allowed in the block - assert get_consolidation_churn_limit(state) > MAX_EFFECTIVE_BALANCE + assert get_consolidation_churn_limit(state) > MIN_ACTIVATION_BALANCE consolidation = signed_consolidation.message # Verify that source != target, so a consolidation cannot be used as an exit. assert consolidation.source_index != consolidation.target_index From 221f273e14aff0356d1b98ac1920dcc7dd523765 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Fri, 29 Mar 2024 22:35:12 +0600 Subject: [PATCH 09/25] Fix lint --- specs/_features/eip7251/beacon-chain.md | 1 - 1 file changed, 1 deletion(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index db6d7601a..845ff1b96 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -909,7 +909,6 @@ def process_execution_layer_withdraw_request( return - has_sufficient_effective_balance = validator.effective_balance == MIN_ACTIVATION_BALANCE has_excess_balance = state.balances[index] > MIN_ACTIVATION_BALANCE + pending_balance_to_withdraw From 04ef1181a8b9da5c7e3fc9aa51ba632eb09d21a3 Mon Sep 17 00:00:00 2001 From: Lion - dapplion <35266934+dapplion@users.noreply.github.com> Date: Wed, 3 Apr 2024 08:31:43 +0900 Subject: [PATCH 10/25] Remove repetitive word --- .../phase0/epoch_processing/test_process_registry_updates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py index b7a7be76a..3cb73086c 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py +++ b/tests/core/pyspec/eth2spec/test/phase0/epoch_processing/test_process_registry_updates.py @@ -114,7 +114,7 @@ def test_activation_queue_sorting(spec, state): assert state.validators[mock_activations - 2].activation_epoch == spec.FAR_FUTURE_EPOCH # the one at churn_limit did not make it, it was out-prioritized assert state.validators[churn_limit].activation_epoch == spec.FAR_FUTURE_EPOCH - # but the the one in front of the above did + # but the one in front of the above did assert state.validators[churn_limit - 1].activation_epoch != spec.FAR_FUTURE_EPOCH From a12e16b739b8abbc3cffaaed64fc528e0bce2a09 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 4 Apr 2024 17:01:08 +0900 Subject: [PATCH 11/25] Add EIP-7549 aggregation logic to testing tools --- .../test_should_override_forkchoice_update.py | 6 +- .../eth2spec/test/helpers/attestations.py | 121 ++++++++++++------ .../fork_choice/test_get_proposer_head.py | 6 +- .../test/phase0/fork_choice/test_reorg.py | 8 +- 4 files changed, 95 insertions(+), 46 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/bellatrix/fork_choice/test_should_override_forkchoice_update.py b/tests/core/pyspec/eth2spec/test/bellatrix/fork_choice/test_should_override_forkchoice_update.py index b40cc5bbe..6c8e33e95 100644 --- a/tests/core/pyspec/eth2spec/test/bellatrix/fork_choice/test_should_override_forkchoice_update.py +++ b/tests/core/pyspec/eth2spec/test/bellatrix/fork_choice/test_should_override_forkchoice_update.py @@ -7,7 +7,7 @@ from eth2spec.test.helpers.constants import ( MINIMAL, ) from eth2spec.test.helpers.attestations import ( - get_valid_attestation_at_slot, + get_valid_attestations_at_slot, ) from eth2spec.test.helpers.block import ( build_empty_block_for_next_slot, @@ -109,7 +109,7 @@ def test_should_override_forkchoice_update__true(spec, state): # Fill a slot with attestations to its parent block = build_empty_block_for_next_slot(spec, state) parent_block_slot = block.slot - 1 - block.body.attestations = get_valid_attestation_at_slot( + block.body.attestations = get_valid_attestations_at_slot( state, spec, parent_block_slot, @@ -135,7 +135,7 @@ def test_should_override_forkchoice_update__true(spec, state): # Add attestations to the parent block temp_state = state.copy() next_slot(spec, temp_state) - attestations = get_valid_attestation_at_slot( + attestations = get_valid_attestations_at_slot( temp_state, spec, slot_to_attest=temp_state.slot - 1, diff --git a/tests/core/pyspec/eth2spec/test/helpers/attestations.py b/tests/core/pyspec/eth2spec/test/helpers/attestations.py index 528de7f67..e57eb8318 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/attestations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/attestations.py @@ -84,7 +84,6 @@ def build_attestation_data(spec, state, slot, index, beacon_block_root=None, sha target=spec.Checkpoint(epoch=spec.compute_epoch_at_slot(slot), root=epoch_boundary_root), ) - # if spec.fork == SHARDING # TODO: add extra data for shard voting return data @@ -95,8 +94,12 @@ def get_valid_attestation(spec, filter_participant_set=None, beacon_block_root=None, signed=False): - # If filter_participant_set filters everything, the attestation has 0 participants, and cannot be signed. - # Thus strictly speaking invalid when no participant is added later. + """ + Return a valid attestation at `slot` and committee index `index`. + + If filter_participant_set filters everything, the attestation has 0 participants, and cannot be signed. + Thus strictly speaking invalid when no participant is added later. + """ if slot is None: slot = state.slot if index is None: @@ -104,18 +107,8 @@ def get_valid_attestation(spec, attestation_data = build_attestation_data(spec, state, slot=slot, index=index, beacon_block_root=beacon_block_root) - beacon_committee = spec.get_beacon_committee(state, slot, index) + attestation = spec.Attestation(data=attestation_data) - if is_post_eip7549(spec): - # will fill aggregation_bits later - attestation = spec.Attestation(data=attestation_data) - else: - committee_size = len(beacon_committee) - aggregation_bits = Bitlist[spec.MAX_VALIDATORS_PER_COMMITTEE](*([0] * committee_size)) - attestation = spec.Attestation( - aggregation_bits=aggregation_bits, - data=attestation_data, - ) # fill the attestation with (optionally filtered) participants, and optionally sign it fill_aggregate_attestation(spec, state, attestation, signed=signed, filter_participant_set=filter_participant_set, committee_index=index) @@ -132,7 +125,7 @@ def sign_aggregate_attestation(spec, state, attestation_data, participants: List spec, state, attestation_data, - privkey + privkey, ) ) return bls.Aggregate(signatures) @@ -180,11 +173,16 @@ def fill_aggregate_attestation(spec, state, attestation, committee_index, signed if filter_participant_set is not None: participants = filter_participant_set(participants) + # initialize `aggregation_bits` if is_post_eip7549(spec): - attestation.committee_bits = spec.Bitvector[spec.MAX_COMMITTEES_PER_SLOT]() attestation.committee_bits[committee_index] = True attestation.aggregation_bits = get_empty_eip7549_aggregation_bits( spec, state, attestation.committee_bits, attestation.data.slot) + else: + committee_size = len(beacon_committee) + attestation.aggregation_bits = Bitlist[spec.MAX_VALIDATORS_PER_COMMITTEE](*([0] * committee_size)) + + # fill in the `aggregation_bits` for i in range(len(beacon_committee)): if is_post_eip7549(spec): offset = get_eip7549_aggregation_bits_offset( @@ -205,7 +203,10 @@ def add_attestations_to_state(spec, state, attestations, slot): spec.process_attestation(state, attestation) -def get_valid_attestation_at_slot(state, spec, slot_to_attest, participation_fn=None, beacon_block_root=None): +def get_valid_attestations_at_slot(state, spec, slot_to_attest, participation_fn=None, beacon_block_root=None): + """ + Return attestations at slot `slot_to_attest`. + """ committees_per_slot = spec.get_committee_count_per_slot(state, spec.compute_epoch_at_slot(slot_to_attest)) for index in range(committees_per_slot): def participants_filter(comm): @@ -213,7 +214,6 @@ def get_valid_attestation_at_slot(state, spec, slot_to_attest, participation_fn= return comm else: return participation_fn(state.slot, index, comm) - # if spec.fork == SHARDING: TODO: add shard data to attestation, include shard headers in block yield get_valid_attestation( spec, state, @@ -225,6 +225,48 @@ def get_valid_attestation_at_slot(state, spec, slot_to_attest, participation_fn= ) +def get_valid_attestation_at_slot(state, spec, slot_to_attest, participation_fn=None, beacon_block_root=None): + """ + Return the aggregate attestation + """ + assert is_post_eip7549(spec) + attestations = list(get_valid_attestations_at_slot( + state, spec, slot_to_attest, + participation_fn=participation_fn, + beacon_block_root=beacon_block_root, + )) + if len(attestations) == 0: + return None + aggregate = spec.Attestation(data=attestations[0].data) + + # fill in committee_bits + all_committee_indices = [] + for attestation in attestations: + committee_indices_of_attestation = spec.get_committee_indices(attestation.committee_bits) + assert len(committee_indices_of_attestation) == 1 + all_committee_indices += committee_indices_of_attestation + + all_committee_indices = set(all_committee_indices) + for committee_index in all_committee_indices: + aggregate.committee_bits[committee_index] = True + + # aggregate the attestation data and sigs + aggregate.aggregation_bits = get_empty_eip7549_aggregation_bits( + spec, state, aggregate.committee_bits, slot_to_attest) + for attestation in attestations: + committee_indices_of_attestation = spec.get_committee_indices(attestation.committee_bits) + assert len(committee_indices_of_attestation) == 1 + committee_index = committee_indices_of_attestation[0] + offset = get_eip7549_aggregation_bits_offset( + spec, state, attestation.data.slot, aggregate.committee_bits, committee_index) + for i in range(len(attestation.aggregation_bits)): + aggregation_bits_index = offset + i + aggregate.aggregation_bits[aggregation_bits_index] = attestation.aggregation_bits[i] + aggregate.signature = bls.Aggregate([attestation.signature for attestation in attestations]) + + return aggregate + + def next_slots_with_attestations(spec, state, slot_count, @@ -249,6 +291,26 @@ def next_slots_with_attestations(spec, return state, signed_blocks, post_state +def _add_valid_attestations(spec, state, block, slot_to_attest, participation_fn=None): + if is_post_eip7549(spec): + attestation = get_valid_attestation_at_slot( + state, + spec, + slot_to_attest, + participation_fn=participation_fn, + ) + block.body.attestations.append(attestation) + else: + attestations = get_valid_attestations_at_slot( + state, + spec, + slot_to_attest, + participation_fn=participation_fn, + ) + for attestation in attestations: + block.body.attestations.append(attestation) + + def next_epoch_with_attestations(spec, state, fill_cur_epoch, @@ -281,24 +343,10 @@ def state_transition_with_full_block(spec, if fill_cur_epoch and state.slot >= spec.MIN_ATTESTATION_INCLUSION_DELAY: slot_to_attest = state.slot - spec.MIN_ATTESTATION_INCLUSION_DELAY + 1 if slot_to_attest >= spec.compute_start_slot_at_epoch(spec.get_current_epoch(state)): - attestations = get_valid_attestation_at_slot( - state, - spec, - slot_to_attest, - participation_fn=participation_fn - ) - for attestation in attestations: - block.body.attestations.append(attestation) + _add_valid_attestations(spec, state, block, slot_to_attest, participation_fn=participation_fn) if fill_prev_epoch and state.slot >= spec.SLOTS_PER_EPOCH: slot_to_attest = state.slot - spec.SLOTS_PER_EPOCH + 1 - attestations = get_valid_attestation_at_slot( - state, - spec, - slot_to_attest, - participation_fn=participation_fn - ) - for attestation in attestations: - block.body.attestations.append(attestation) + _add_valid_attestations(spec, state, block, slot_to_attest, participation_fn=participation_fn) if sync_aggregate is not None: block.body.sync_aggregate = sync_aggregate @@ -319,7 +367,7 @@ def state_transition_with_full_attestations_block(spec, state, fill_cur_epoch, f slots = state.slot % spec.SLOTS_PER_EPOCH for slot_offset in range(slots): target_slot = state.slot - slot_offset - attestations += get_valid_attestation_at_slot( + attestations += get_valid_attestations_at_slot( state, spec, target_slot, @@ -330,7 +378,7 @@ def state_transition_with_full_attestations_block(spec, state, fill_cur_epoch, f slots = spec.SLOTS_PER_EPOCH - state.slot % spec.SLOTS_PER_EPOCH for slot_offset in range(1, slots): target_slot = state.slot - (state.slot % spec.SLOTS_PER_EPOCH) - slot_offset - attestations += get_valid_attestation_at_slot( + attestations += get_valid_attestations_at_slot( state, spec, target_slot, @@ -423,6 +471,7 @@ def get_empty_eip7549_aggregation_bits(spec, state, committee_bits, slot): def get_eip7549_aggregation_bits_offset(spec, state, slot, committee_bits, committee_index): + # FIXME: it's not efficient to use it as an aggregator committee_indices = spec.get_committee_indices(committee_bits) assert committee_index in committee_indices offset = 0 diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_get_proposer_head.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_get_proposer_head.py index 9419a18df..81e5b4f56 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_get_proposer_head.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_get_proposer_head.py @@ -4,7 +4,7 @@ from eth2spec.test.context import ( with_altair_and_later, ) from eth2spec.test.helpers.attestations import ( - get_valid_attestation_at_slot, + get_valid_attestations_at_slot, ) from eth2spec.test.helpers.block import ( build_empty_block_for_next_slot, @@ -101,7 +101,7 @@ def test_basic_is_parent_root(spec, state): # Fill a slot with attestations to its parent block = build_empty_block_for_next_slot(spec, state) parent_block_slot = block.slot - 1 - block.body.attestations = get_valid_attestation_at_slot( + block.body.attestations = get_valid_attestations_at_slot( state, spec, parent_block_slot, @@ -128,7 +128,7 @@ def test_basic_is_parent_root(spec, state): slot = state.slot # Add attestations to the parent block - attestations = get_valid_attestation_at_slot( + attestations = get_valid_attestations_at_slot( state, spec, slot_to_attest=slot - 1, diff --git a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py index ca9b483f8..983a8ee66 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py +++ b/tests/core/pyspec/eth2spec/test/phase0/fork_choice/test_reorg.py @@ -9,7 +9,7 @@ from eth2spec.test.helpers.constants import ( from eth2spec.test.helpers.attestations import ( state_transition_with_full_block, get_valid_attestation, - get_valid_attestation_at_slot, + get_valid_attestations_at_slot, ) from eth2spec.test.helpers.block import ( build_empty_block, @@ -218,7 +218,7 @@ def _run_delayed_justification(spec, state, attemped_reorg, is_justifying_previo # add attestations of y temp_state = state.copy() next_slot(spec, temp_state) - attestations_for_y = list(get_valid_attestation_at_slot(temp_state, spec, signed_block_y.message.slot)) + attestations_for_y = list(get_valid_attestations_at_slot(temp_state, spec, signed_block_y.message.slot)) current_time = temp_state.slot * spec.config.SECONDS_PER_SLOT + store.genesis_time on_tick_and_append_step(spec, store, current_time, test_steps) yield from add_attestations(spec, store, attestations_for_y, test_steps) @@ -345,10 +345,10 @@ def _run_include_votes_of_another_empty_chain(spec, state, enough_ffg, is_justif # create 2/3 votes for the empty chain attestations_for_y = [] # target_is_current = not is_justifying_previous_epoch - attestations = list(get_valid_attestation_at_slot(state, spec, state_a.slot)) + attestations = list(get_valid_attestations_at_slot(state, spec, state_a.slot)) attestations_for_y.append(attestations) for state in states_of_empty_chain: - attestations = list(get_valid_attestation_at_slot(state, spec, state.slot)) + attestations = list(get_valid_attestations_at_slot(state, spec, state.slot)) attestations_for_y.append(attestations) state = state_a.copy() From 265788be58cfbcdd7280d17eedc309eb0bef0347 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Thu, 4 Apr 2024 18:01:08 +0900 Subject: [PATCH 12/25] refactor --- .../eth2spec/test/helpers/attestations.py | 75 +++++++++++++------ 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/attestations.py b/tests/core/pyspec/eth2spec/test/helpers/attestations.py index e57eb8318..567bbd4c4 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/attestations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/attestations.py @@ -225,6 +225,51 @@ def get_valid_attestations_at_slot(state, spec, slot_to_attest, participation_fn ) +def _get_aggregate_committee_indices(spec, attestations): + """ + Aggregate all unique committee indices from the given attestations. + """ + all_committee_indices = set() + for attestation in attestations: + committee_indices = spec.get_committee_indices(attestation.committee_bits) + assert len(committee_indices) == 1 + all_committee_indices.add(committee_indices[0]) + + return all_committee_indices + + +def _aggregate_aggregation_bits_and_signatures(spec, state, slot, aggregate, attestations): + """ + Aggregate the aggregation bits and signatures from the attestations, + incorporating the calculation of aggregation bits offset directly. + """ + # initialize aggregation bits for the aggregate attestation + aggregate.aggregation_bits = get_empty_eip7549_aggregation_bits( + spec, state, aggregate.committee_bits, slot) + + signatures = [] + + offset = 0 + attestations = sorted(attestations, key=lambda att: spec.get_committee_indices(att.committee_bits)[0]) + for attestation in attestations: + # retrieve the single committee index for the attestation. + committee_index = spec.get_committee_indices(attestation.committee_bits)[0] + + # update the aggregate's aggregation bits based on each attestation. + for i, bit in enumerate(attestation.aggregation_bits): + aggregate.aggregation_bits[offset + i] = bit + + # collect signatures for aggregation. + signatures.append(attestation.signature) + + # update offset + committee = spec.get_beacon_committee(state, slot, committee_index) + offset += len(committee) + + # aggregate signatures from all attestations. + aggregate.signature = bls.Aggregate(signatures) + + def get_valid_attestation_at_slot(state, spec, slot_to_attest, participation_fn=None, beacon_block_root=None): """ Return the aggregate attestation @@ -235,34 +280,18 @@ def get_valid_attestation_at_slot(state, spec, slot_to_attest, participation_fn= participation_fn=participation_fn, beacon_block_root=beacon_block_root, )) - if len(attestations) == 0: + if not attestations: return None + + # initialize the aggregate attestation. aggregate = spec.Attestation(data=attestations[0].data) # fill in committee_bits - all_committee_indices = [] - for attestation in attestations: - committee_indices_of_attestation = spec.get_committee_indices(attestation.committee_bits) - assert len(committee_indices_of_attestation) == 1 - all_committee_indices += committee_indices_of_attestation - - all_committee_indices = set(all_committee_indices) + all_committee_indices = _get_aggregate_committee_indices(spec, attestations) for committee_index in all_committee_indices: aggregate.committee_bits[committee_index] = True - # aggregate the attestation data and sigs - aggregate.aggregation_bits = get_empty_eip7549_aggregation_bits( - spec, state, aggregate.committee_bits, slot_to_attest) - for attestation in attestations: - committee_indices_of_attestation = spec.get_committee_indices(attestation.committee_bits) - assert len(committee_indices_of_attestation) == 1 - committee_index = committee_indices_of_attestation[0] - offset = get_eip7549_aggregation_bits_offset( - spec, state, attestation.data.slot, aggregate.committee_bits, committee_index) - for i in range(len(attestation.aggregation_bits)): - aggregation_bits_index = offset + i - aggregate.aggregation_bits[aggregation_bits_index] = attestation.aggregation_bits[i] - aggregate.signature = bls.Aggregate([attestation.signature for attestation in attestations]) + _aggregate_aggregation_bits_and_signatures(spec, state, slot_to_attest, aggregate, attestations) return aggregate @@ -471,7 +500,9 @@ def get_empty_eip7549_aggregation_bits(spec, state, committee_bits, slot): def get_eip7549_aggregation_bits_offset(spec, state, slot, committee_bits, committee_index): - # FIXME: it's not efficient to use it as an aggregator + """ + Calculate the offset for the aggregation bits based on the committee index. + """ committee_indices = spec.get_committee_indices(committee_bits) assert committee_index in committee_indices offset = 0 From 4f8fb6f7162e4559a4d051b0cf6996e125911806 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Thu, 4 Apr 2024 14:49:25 +0300 Subject: [PATCH 13/25] Update specs/_features/eip7251/beacon-chain.md Co-authored-by: fradamt <104826920+fradamt@users.noreply.github.com> --- specs/_features/eip7251/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index 845ff1b96..662d851c4 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -909,7 +909,7 @@ def process_execution_layer_withdraw_request( return - has_sufficient_effective_balance = validator.effective_balance == MIN_ACTIVATION_BALANCE + has_sufficient_effective_balance = validator.effective_balance >= MIN_ACTIVATION_BALANCE has_excess_balance = state.balances[index] > MIN_ACTIVATION_BALANCE + pending_balance_to_withdraw # Only allow partial withdrawals with compounding withdrawal credentials From ace9db9aa9a75ff1231a9631af598728d311763b Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Fri, 5 Apr 2024 15:35:06 +0300 Subject: [PATCH 14/25] Set FULL_EXIT_REQUEST_AMOUNT to 0 --- specs/_features/eip7251/beacon-chain.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index 662d851c4..852742a64 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -94,7 +94,7 @@ The following values are (non-configurable) constants used throughout the specif | Name | Value | | - | - | -| `FULL_EXIT_REQUEST_AMOUNT` | `uint64(2**64 - 1)` | +| `FULL_EXIT_REQUEST_AMOUNT` | `uint64(0)` | ### Withdrawal prefixes @@ -1001,4 +1001,4 @@ def process_voluntary_exit(state: BeaconState, signed_voluntary_exit: SignedVolu assert get_pending_balance_to_withdraw(state, voluntary_exit.validator_index) == 0 # [New in EIP7251] # Initiate exit initiate_validator_exit(state, voluntary_exit.validator_index) -``` \ No newline at end of file +``` From 3d3ec8fbba55c8067e8cbae1dce03777b9c0dd70 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 5 Apr 2024 09:38:32 -0600 Subject: [PATCH 15/25] Update tests/core/pyspec/eth2spec/test/helpers/attestations.py --- tests/core/pyspec/eth2spec/test/helpers/attestations.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/attestations.py b/tests/core/pyspec/eth2spec/test/helpers/attestations.py index 567bbd4c4..0562ec9b8 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/attestations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/attestations.py @@ -272,7 +272,8 @@ def _aggregate_aggregation_bits_and_signatures(spec, state, slot, aggregate, att def get_valid_attestation_at_slot(state, spec, slot_to_attest, participation_fn=None, beacon_block_root=None): """ - Return the aggregate attestation + Return the aggregate attestation post EIP-7549. + Note: this EIP supports dense packing of on-chain aggregates so we can just return a single `Attestation`. """ assert is_post_eip7549(spec) attestations = list(get_valid_attestations_at_slot( From a56bd85674d4c35164a4877bf7878326fef8e35f Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Fri, 5 Apr 2024 09:43:48 -0600 Subject: [PATCH 16/25] Update tests/core/pyspec/eth2spec/test/helpers/attestations.py --- tests/core/pyspec/eth2spec/test/helpers/attestations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/attestations.py b/tests/core/pyspec/eth2spec/test/helpers/attestations.py index 0562ec9b8..916a7ca00 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/attestations.py +++ b/tests/core/pyspec/eth2spec/test/helpers/attestations.py @@ -272,7 +272,7 @@ def _aggregate_aggregation_bits_and_signatures(spec, state, slot, aggregate, att def get_valid_attestation_at_slot(state, spec, slot_to_attest, participation_fn=None, beacon_block_root=None): """ - Return the aggregate attestation post EIP-7549. + Return the aggregate attestation post EIP-7549. Note: this EIP supports dense packing of on-chain aggregates so we can just return a single `Attestation`. """ assert is_post_eip7549(spec) From 6ad0c07c78f5c8da0f783032c067e4e2c6d413c8 Mon Sep 17 00:00:00 2001 From: NC Date: Sat, 6 Apr 2024 22:53:04 +0800 Subject: [PATCH 17/25] Remove extra ` queue_excess_active_balance` call --- specs/_features/eip7251/fork.md | 1 - 1 file changed, 1 deletion(-) diff --git a/specs/_features/eip7251/fork.md b/specs/_features/eip7251/fork.md index 609b4f3f8..02d73deb1 100644 --- a/specs/_features/eip7251/fork.md +++ b/specs/_features/eip7251/fork.md @@ -129,7 +129,6 @@ def upgrade_to_eip7251(pre: deneb.BeaconState) -> BeaconState: ) # Ensure early adopters of compounding credentials go through the activation churn - queue_excess_active_balance(post) for index, validator in enumerate(post.validators): if has_compounding_withdrawal_credential(validator): queue_excess_active_balance(post, index) From 982a983072f82b64289a1dc82eced7320ed92d9f Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 6 Apr 2024 10:43:35 -0600 Subject: [PATCH 18/25] EIP-7251: format/lint fixes/docs, add validator guide --- specs/_features/eip7251/beacon-chain.md | 31 +++++++---- specs/_features/eip7251/fork.md | 3 +- specs/_features/eip7251/validator.md | 73 +++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 specs/_features/eip7251/validator.md diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index 9fbc587c5..5a99ad4d4 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -81,7 +81,7 @@ ## Introduction -See [a modest proposal](https://notes.ethereum.org/@mikeneuder/increase-maxeb), the [diff view](https://github.com/michaelneuder/consensus-specs/pull/3/files) and +See [a modest proposal](https://notes.ethereum.org/@mikeneuder/increase-maxeb), the [diff view](https://github.com/michaelneuder/consensus-specs/pull/3/files) and [security considerations](https://notes.ethereum.org/@fradamt/meb-increase-security). *Note:* This specification is built upon [Deneb](../../deneb/beacon-chain.md). @@ -282,7 +282,7 @@ class BeaconBlockBody(Container): voluntary_exits: List[SignedVoluntaryExit, MAX_VOLUNTARY_EXITS] sync_aggregate: SyncAggregate # Execution - execution_payload: ExecutionPayload + execution_payload: ExecutionPayload bls_to_execution_changes: List[SignedBLSToExecutionChange, MAX_BLS_TO_EXECUTION_CHANGES] blob_kzg_commitments: List[KZGCommitment, MAX_BLOB_COMMITMENTS_PER_BLOCK] consolidations: List[SignedConsolidation, MAX_CONSOLIDATIONS] # [New in EIP-7251] @@ -386,7 +386,7 @@ def get_churn_limit(state: BeaconState) -> Gwei: Return the churn limit for the current epoch. """ churn = max( - MIN_PER_EPOCH_CHURN_LIMIT_EIP7251, + MIN_PER_EPOCH_CHURN_LIMIT_EIP7251, get_total_active_balance(state) // CHURN_LIMIT_QUOTIENT ) return churn - churn % EFFECTIVE_BALANCE_INCREMENT @@ -472,7 +472,6 @@ def queue_excess_active_balance(state: BeaconState, index: ValidatorIndex) -> No #### New `compute_exit_epoch_and_update_churn` - ```python def compute_exit_epoch_and_update_churn(state: BeaconState, exit_balance: Gwei) -> Epoch: earliest_exit_epoch = compute_activation_exit_epoch(get_current_epoch(state)) @@ -570,12 +569,16 @@ def process_epoch(state: BeaconState) -> None: #### Updated `process_registry_updates` +`process_registry_updates` uses the updated definition of `initiate_validator_exit` +and changes how the activation epochs are computed for eligible validators. + ```python def process_registry_updates(state: BeaconState) -> None: # Process activation eligibility and ejections for index, validator in enumerate(state.validators): if is_eligible_for_activation_queue(validator): validator.activation_eligibility_epoch = get_current_epoch(state) + 1 + if ( is_active_validator(validator, get_current_epoch(state)) and validator.effective_balance <= EJECTION_BALANCE @@ -607,7 +610,7 @@ def process_pending_balance_deposits(state: BeaconState) -> None: state.pending_balance_deposits = state.pending_balance_deposits[next_deposit_index:] if len(state.pending_balance_deposits) == 0: - state.deposit_balance_to_consume = 0 + state.deposit_balance_to_consume = Gwei(0) else: state.deposit_balance_to_consume = available_for_processing - processed_amount ``` @@ -638,6 +641,8 @@ def process_pending_consolidations(state: BeaconState) -> None: #### Updated `process_effective_balance_updates` +`process_effective_balance_updates` is updated with a new limit for the maximum effective balance. + ```python def process_effective_balance_updates(state: BeaconState) -> None: # Update effective balances with hysteresis @@ -760,7 +765,7 @@ def process_withdrawals(state: BeaconState, payload: ExecutionPayload) -> None: state.next_withdrawal_validator_index = next_validator_index ``` -#### Operations +#### Operations ##### Updated `process_operations` @@ -779,14 +784,16 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None: for_ops(body.deposits, process_deposit) # [Modified in EIP7251] for_ops(body.voluntary_exits, process_voluntary_exit) # [Modified in EIP7251] for_ops(body.bls_to_execution_changes, process_bls_to_execution_change) - for_ops(body.execution_payload.withdraw_requests, process_execution_layer_withdraw_request) # New in EIP7251 - for_ops(body.consolidations, process_consolidation) # New in EIP7251 + for_ops(body.execution_payload.withdraw_requests, process_execution_layer_withdraw_request) # [New in EIP7251] + for_ops(body.consolidations, process_consolidation) # [New in EIP7251] ``` ##### Deposits ###### Updated `apply_deposit` +*NOTE*: `process_deposit` is updated with a new definition of `apply_deposit`. + ```python def apply_deposit(state: BeaconState, pubkey: BLSPubkey, @@ -819,7 +826,7 @@ def apply_deposit(state: BeaconState, def is_valid_deposit_signature(pubkey: BLSPubkey, withdrawal_credentials: Bytes32, amount: uint64, - signature: BLSSignature) -> None: + signature: BLSSignature) -> bool: deposit_message = DepositMessage( pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, @@ -862,7 +869,7 @@ def get_validator_from_deposit(pubkey: BLSPubkey, withdrawal_credentials: Bytes3 ) ``` -##### Withdrawals +##### Withdrawals ###### New `process_execution_layer_withdraw_request` @@ -874,7 +881,7 @@ def process_execution_layer_withdraw_request( amount = execution_layer_withdraw_request.amount is_full_exit_request = amount == FULL_EXIT_REQUEST_AMOUNT - # If partial withdrawal queue is full, only full exits are processed + # If partial withdrawal queue is full, only full exits are processed if len(state.pending_partial_withdrawals) >= PENDING_PARTIAL_WITHDRAWALS_LIMIT and not is_full_exit_request: return @@ -947,7 +954,7 @@ def process_consolidation(state: BeaconState, signed_consolidation: SignedConsol assert source_validator.exit_epoch == FAR_FUTURE_EPOCH assert target_validator.exit_epoch == FAR_FUTURE_EPOCH # Consolidations must specify an epoch when they become valid; they are not valid before then - assert current_epoch >= consolidation.epoch + assert current_epoch >= consolidation.epoch # Verify the source and the target have Execution layer withdrawal credentials assert has_execution_withdrawal_credential(source_validator) diff --git a/specs/_features/eip7251/fork.md b/specs/_features/eip7251/fork.md index 02d73deb1..49e01ea7e 100644 --- a/specs/_features/eip7251/fork.md +++ b/specs/_features/eip7251/fork.md @@ -131,8 +131,7 @@ def upgrade_to_eip7251(pre: deneb.BeaconState) -> BeaconState: # Ensure early adopters of compounding credentials go through the activation churn for index, validator in enumerate(post.validators): if has_compounding_withdrawal_credential(validator): - queue_excess_active_balance(post, index) + queue_excess_active_balance(post, ValidatorIndex(index)) return post ``` - diff --git a/specs/_features/eip7251/validator.md b/specs/_features/eip7251/validator.md new file mode 100644 index 000000000..455699383 --- /dev/null +++ b/specs/_features/eip7251/validator.md @@ -0,0 +1,73 @@ +# EIP-7251 -- Honest Validator + +## Table of contents + + + + + +- [Introduction](#introduction) +- [Prerequisites](#prerequisites) +- [Beacon chain responsibilities](#beacon-chain-responsibilities) + - [Block and sidecar proposal](#block-and-sidecar-proposal) + - [Constructing the `BeaconBlockBody`](#constructing-the-beaconblockbody) + - [ExecutionPayload](#executionpayload) + + + + +## Introduction + +This document represents the changes to be made in the code of an "honest validator". + +## Prerequisites + +This document is an extension of the [Deneb -- Honest Validator](../deneb/validator.md) guide. +All behaviors and definitions defined in this document, and documents it extends, carry over unless explicitly noted or overridden. + +All terminology, constants, functions, and protocol mechanics defined in the updated [Beacon Chain doc of EIP-7251](./beacon-chain.md) are requisite for this document and used throughout. +Please see related Beacon Chain doc before continuing and use them as a reference throughout. + +## Beacon chain responsibilities + +All validator responsibilities remain unchanged other than those noted below. + +### Block and sidecar proposal + +#### Constructing the `BeaconBlockBody` + +##### ExecutionPayload + +`prepare_execution_payload` is updated from the Deneb specs. + +*Note*: In this section, `state` is the state of the slot for the block proposal _without_ the block yet applied. +That is, `state` is the `previous_state` processed through any empty slots up to the assigned slot using `process_slots(previous_state, slot)`. + +*Note*: The only change to `prepare_execution_payload` is the new definition of `get_expected_withdrawals`. + +```python +def prepare_execution_payload(state: BeaconState, + safe_block_hash: Hash32, + finalized_block_hash: Hash32, + suggested_fee_recipient: ExecutionAddress, + execution_engine: ExecutionEngine) -> Optional[PayloadId]: + # Verify consistency of the parent hash with respect to the previous execution payload header + parent_hash = state.latest_execution_payload_header.block_hash + + # Set the forkchoice head and initiate the payload build process + withdrawals, _ = get_expected_withdrawals(state) # [Modified in EIP-7251] + + payload_attributes = PayloadAttributes( + timestamp=compute_timestamp_at_slot(state, state.slot), + prev_randao=get_randao_mix(state, get_current_epoch(state)), + suggested_fee_recipient=suggested_fee_recipient, + withdrawals=withdrawals, + parent_beacon_block_root=hash_tree_root(state.latest_block_header), + ) + return execution_engine.notify_forkchoice_updated( + head_block_hash=parent_hash, + safe_block_hash=safe_block_hash, + finalized_block_hash=finalized_block_hash, + payload_attributes=payload_attributes, + ) +``` From a80a7775896c7cd8d9ae077be383ac23c3e68a4b Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 6 Apr 2024 11:15:03 -0600 Subject: [PATCH 19/25] add missing extended types for EIP-7251 --- specs/_features/eip7251/beacon-chain.md | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index 5a99ad4d4..8434e8378 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -30,6 +30,8 @@ - [Extended Containers](#extended-containers) - [`BeaconState`](#beaconstate) - [`BeaconBlockBody`](#beaconblockbody) + - [`ExecutionPayload`](#executionpayload) + - [`ExecutionPayloadHeader`](#executionpayloadheader) - [Helpers](#helpers) - [Predicates](#predicates) - [Updated `is_eligible_for_activation_queue`](#updated-is_eligible_for_activation_queue) @@ -136,6 +138,7 @@ The following values are (non-configurable) constants used throughout the specif | Name | Value | Description | | - | - | - | +| `MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD` | `uint64(16)` | | `MAX_PARTIAL_WITHDRAWALS_PER_PAYLOAD` | `uint64(2**3)` (= 8) | Maximum amount of partial withdrawals allowed in each payload | ### State list lengths @@ -288,6 +291,58 @@ class BeaconBlockBody(Container): consolidations: List[SignedConsolidation, MAX_CONSOLIDATIONS] # [New in EIP-7251] ``` +#### `ExecutionPayload` + +```python +class ExecutionPayload(Container): + # Execution block header fields + parent_hash: Hash32 + fee_recipient: ExecutionAddress # 'beneficiary' in the yellow paper + state_root: Bytes32 + receipts_root: Bytes32 + logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM] + prev_randao: Bytes32 # 'difficulty' in the yellow paper + block_number: uint64 # 'number' in the yellow paper + gas_limit: uint64 + gas_used: uint64 + timestamp: uint64 + extra_data: ByteList[MAX_EXTRA_DATA_BYTES] + base_fee_per_gas: uint256 + # Extra payload fields + block_hash: Hash32 # Hash of execution block + transactions: List[Transaction, MAX_TRANSACTIONS_PER_PAYLOAD] + withdrawals: List[Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD] + blob_gas_used: uint64 + excess_blob_gas: uint64 + withdraw_requests: List[ExecutionLayerWithdrawRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD] # [New in EIP-7251] +``` + +#### `ExecutionPayloadHeader` + +```python +class ExecutionPayloadHeader(Container): + # Execution block header fields + parent_hash: Hash32 + fee_recipient: ExecutionAddress + state_root: Bytes32 + receipts_root: Bytes32 + logs_bloom: ByteVector[BYTES_PER_LOGS_BLOOM] + prev_randao: Bytes32 + block_number: uint64 + gas_limit: uint64 + gas_used: uint64 + timestamp: uint64 + extra_data: ByteList[MAX_EXTRA_DATA_BYTES] + base_fee_per_gas: uint256 + # Extra payload fields + block_hash: Hash32 # Hash of execution block + transactions_root: Root + withdrawals_root: Root + blob_gas_used: uint64 + excess_blob_gas: uint64 + withdraw_requests_root: Root # [New in EIP-7251] +``` + ## Helpers ### Predicates From b5d7bd0a8afb7bb34ad5de297aceef99e8823edf Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 6 Apr 2024 11:38:33 -0600 Subject: [PATCH 20/25] bugfix: voluntary exit processing in EIP-7251 --- specs/_features/eip7251/beacon-chain.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index 8434e8378..75eae939d 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -1051,12 +1051,12 @@ def process_voluntary_exit(state: BeaconState, signed_voluntary_exit: SignedVolu assert get_current_epoch(state) >= voluntary_exit.epoch # Verify the validator has been active long enough assert get_current_epoch(state) >= validator.activation_epoch + SHARD_COMMITTEE_PERIOD - # Verify signature - domain = get_domain(state, DOMAIN_VOLUNTARY_EXIT, voluntary_exit.epoch) - signing_root = compute_signing_root(voluntary_exit, domain) - assert bls.Verify(validator.pubkey, signing_root, signed_voluntary_exit.signature) # Only exit validator if it has no pending withdrawals in the queue assert get_pending_balance_to_withdraw(state, voluntary_exit.validator_index) == 0 # [New in EIP7251] + # Verify signature + domain = compute_domain(DOMAIN_VOLUNTARY_EXIT, CAPELLA_FORK_VERSION, state.genesis_validators_root) + signing_root = compute_signing_root(voluntary_exit, domain) + assert bls.Verify(validator.pubkey, signing_root, signed_voluntary_exit.signature) # Initiate exit initiate_validator_exit(state, voluntary_exit.validator_index) ``` From 61168e6124e1b5c7359ff131ca779e4c1768b68a Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 6 Apr 2024 13:30:12 -0600 Subject: [PATCH 21/25] spec bugfix: incorrect `process_epoch` definition --- specs/_features/eip7251/beacon-chain.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index 75eae939d..c40b0faa1 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -620,6 +620,9 @@ def process_epoch(state: BeaconState) -> None: process_effective_balance_updates(state) # [Modified in EIP7251] process_slashings_reset(state) process_randao_mixes_reset(state) + process_historical_summaries_update(state) + process_participation_flag_updates(state) + process_sync_committee_updates(state) ``` #### Updated `process_registry_updates` From 8cf2fd50f601008f79be79d925f7621262dbd887 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Sat, 6 Apr 2024 14:21:36 -0600 Subject: [PATCH 22/25] add EIP-7251 `initialize_beacon_state_from_eth1` function --- specs/_features/eip7251/beacon-chain.md | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index c40b0faa1..ab627c90a 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -77,6 +77,7 @@ - [New `process_consolidation`](#new-process_consolidation) - [Voluntary exits](#voluntary-exits) - [Updated `process_voluntary_exit`](#updated-process_voluntary_exit) +- [Testing](#testing) @@ -1063,3 +1064,61 @@ def process_voluntary_exit(state: BeaconState, signed_voluntary_exit: SignedVolu # Initiate exit initiate_validator_exit(state, voluntary_exit.validator_index) ``` + +## Testing + +*Note*: The function `initialize_beacon_state_from_eth1` is modified for pure EIP-7251 testing only. + +```python +def initialize_beacon_state_from_eth1(eth1_block_hash: Hash32, + eth1_timestamp: uint64, + deposits: Sequence[Deposit], + execution_payload_header: ExecutionPayloadHeader=ExecutionPayloadHeader() + ) -> BeaconState: + fork = Fork( + previous_version=EIP7251_FORK_VERSION, # [Modified in EIP-7251] for testing only + current_version=EIP7251_FORK_VERSION, # [Modified in EIP-7251] + epoch=GENESIS_EPOCH, + ) + state = BeaconState( + genesis_time=eth1_timestamp + GENESIS_DELAY, + fork=fork, + eth1_data=Eth1Data(block_hash=eth1_block_hash, deposit_count=uint64(len(deposits))), + latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())), + randao_mixes=[eth1_block_hash] * EPOCHS_PER_HISTORICAL_VECTOR, # Seed RANDAO with Eth1 entropy + ) + + # Process deposits + leaves = list(map(lambda deposit: deposit.data, deposits)) + for index, deposit in enumerate(deposits): + deposit_data_list = List[DepositData, 2**DEPOSIT_CONTRACT_TREE_DEPTH](*leaves[:index + 1]) + state.eth1_data.deposit_root = hash_tree_root(deposit_data_list) + process_deposit(state, deposit) + + # Process deposit balance updates + for deposit in state.pending_balance_deposits: + increase_balance(state, deposit.index, deposit.amount) + state.pending_balance_deposits = [] + + # Process activations + for index, validator in enumerate(state.validators): + balance = state.balances[index] + validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE) + if validator.effective_balance == MAX_EFFECTIVE_BALANCE: + validator.activation_eligibility_epoch = GENESIS_EPOCH + validator.activation_epoch = GENESIS_EPOCH + + # Set genesis validators root for domain separation and chain versioning + state.genesis_validators_root = hash_tree_root(state.validators) + + # Fill in sync committees + # Note: A duplicate committee is assigned for the current and next committee at genesis + state.current_sync_committee = get_next_sync_committee(state) + state.next_sync_committee = get_next_sync_committee(state) + + # Initialize the execution payload header + # If empty, will initialize a chain that has not yet gone through the Merge transition + state.latest_execution_payload_header = execution_payload_header + + return state +``` From 64da0da132f6a677b60b68a27e66aa16ed04a526 Mon Sep 17 00:00:00 2001 From: Mikhail Kalinin Date: Sun, 7 Apr 2024 18:15:01 +0600 Subject: [PATCH 23/25] Fix has_sufficient_effective_balance computation --- specs/_features/eip7251/beacon-chain.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/_features/eip7251/beacon-chain.md b/specs/_features/eip7251/beacon-chain.md index 9fbc587c5..7d7e78d4a 100644 --- a/specs/_features/eip7251/beacon-chain.md +++ b/specs/_features/eip7251/beacon-chain.md @@ -686,7 +686,7 @@ def get_expected_withdrawals(state: BeaconState) -> Tuple[Sequence[Withdrawal], break validator = state.validators[withdrawal.index] - has_sufficient_effective_balance = validator.effective_balance == MIN_ACTIVATION_BALANCE + has_sufficient_effective_balance = validator.effective_balance >= MIN_ACTIVATION_BALANCE has_excess_balance = state.balances[withdrawal.index] > MIN_ACTIVATION_BALANCE if validator.exit_epoch == FAR_FUTURE_EPOCH and has_sufficient_effective_balance and has_excess_balance: withdrawable_balance = min(state.balances[withdrawal.index] - MIN_ACTIVATION_BALANCE, withdrawal.amount) From 3cf3e21504a661b8af9ab744f83ffac8b2fd4ec4 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Mon, 8 Apr 2024 16:28:17 -0600 Subject: [PATCH 24/25] Update beacon-chain.md --- specs/_features/eip7002/beacon-chain.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/specs/_features/eip7002/beacon-chain.md b/specs/_features/eip7002/beacon-chain.md index 39b03e878..58af0d540 100644 --- a/specs/_features/eip7002/beacon-chain.md +++ b/specs/_features/eip7002/beacon-chain.md @@ -222,7 +222,10 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None: ```python def process_execution_layer_exit(state: BeaconState, execution_layer_exit: ExecutionLayerExit) -> None: validator_pubkeys = [v.pubkey for v in state.validators] - validator_index = ValidatorIndex(validator_pubkeys.index(execution_layer_exit.validator_pubkey)) + pubkey_to_exit = execution_layer_exit.validator_pubkey + if pubkey_to_exit not in validator_pubkeys: + return + validator_index = ValidatorIndex(validator_pubkeys.index(pubkey_to_exit)) validator = state.validators[validator_index] # Verify withdrawal credentials From 1db1c5432365cd3b480b535d960b3c1c973c970f Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Tue, 9 Apr 2024 10:33:48 +0800 Subject: [PATCH 25/25] add comment --- specs/_features/eip7002/beacon-chain.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/_features/eip7002/beacon-chain.md b/specs/_features/eip7002/beacon-chain.md index 58af0d540..712111920 100644 --- a/specs/_features/eip7002/beacon-chain.md +++ b/specs/_features/eip7002/beacon-chain.md @@ -222,6 +222,7 @@ def process_operations(state: BeaconState, body: BeaconBlockBody) -> None: ```python def process_execution_layer_exit(state: BeaconState, execution_layer_exit: ExecutionLayerExit) -> None: validator_pubkeys = [v.pubkey for v in state.validators] + # Verify pubkey exists pubkey_to_exit = execution_layer_exit.validator_pubkey if pubkey_to_exit not in validator_pubkeys: return