Skip to content

Commit

Permalink
Electra: EIP-7251 Update process_voluntary_exit
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvanloon committed Jul 2, 2024
1 parent 0aab919 commit 46b570a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
20 changes: 18 additions & 2 deletions beacon-chain/core/blocks/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ func ProcessVoluntaryExits(
// 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
// # 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 Electra:EIP7251]
// # Verify signature
// domain = get_domain(state, DOMAIN_VOLUNTARY_EXIT, voluntary_exit.epoch)
// signing_root = compute_signing_root(voluntary_exit, domain)
Expand Down Expand Up @@ -128,7 +130,7 @@ func VerifyExitAndSignature(
}

exit := signed.Exit
if err := verifyExitConditions(validator, currentSlot, exit); err != nil {
if err := verifyExitConditions(state, validator, currentSlot, exit); err != nil {
return err
}
domain, err := signing.Domain(fork, exit.Epoch, params.BeaconConfig().DomainVoluntaryExit, genesisRoot)
Expand Down Expand Up @@ -157,13 +159,15 @@ func VerifyExitAndSignature(
// 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
// # 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 Electra:EIP7251]
// # 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)
// # Initiate exit
// initiate_validator_exit(state, voluntary_exit.validator_index)
func verifyExitConditions(validator state.ReadOnlyValidator, currentSlot primitives.Slot, exit *ethpb.VoluntaryExit) error {
func verifyExitConditions(st state.ReadOnlyBeaconState, validator state.ReadOnlyValidator, currentSlot primitives.Slot, exit *ethpb.VoluntaryExit) error {
currentEpoch := slots.ToEpoch(currentSlot)
// Verify the validator is active.
if !helpers.IsActiveValidatorUsingTrie(validator, currentEpoch) {
Expand All @@ -186,6 +190,18 @@ func verifyExitConditions(validator state.ReadOnlyValidator, currentSlot primiti
params.BeaconConfig().ShardCommitteePeriod,
validator.ActivationEpoch()+params.BeaconConfig().ShardCommitteePeriod,
)
}

if st.Version() >= version.Electra {
// Only exit validator if it has no pending withdrawals in the queue.
pbw, err := st.PendingBalanceToWithdraw(exit.ValidatorIndex)
if err != nil {
return fmt.Errorf("unable to retrieve pending balance to withdraw for validator %d: %w", exit.ValidatorIndex, err)
}
if pbw != 0 {
return fmt.Errorf("validator %d must have no pending balance to withdraw, got %d pending balance to withdraw", exit.ValidatorIndex, pbw)
}
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ import (
)

func TestMainnet_Electra_Operations_VoluntaryExit(t *testing.T) {
t.Skip("TODO: Electra")
operations.RunVoluntaryExitTest(t, "mainnet")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ import (
)

func TestMinimal_Electra_Operations_VoluntaryExit(t *testing.T) {
t.Skip("TODO: Electra")
operations.RunVoluntaryExitTest(t, "minimal")
}

0 comments on commit 46b570a

Please sign in to comment.