-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Electra: EIP-7251 Update process_voluntary_exit
#14176
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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) { | ||
|
@@ -187,5 +191,17 @@ func verifyExitConditions(validator state.ReadOnlyValidator, currentSlot primiti | |
validator.ActivationEpoch()+params.BeaconConfig().ShardCommitteePeriod, | ||
) | ||
} | ||
|
||
if st.Version() >= version.Electra { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to break this out from the core blocks into electra? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually. Breaking this out would involve breaking the other forks out and it would be a large change. Currently trying to get to devnet-1 while taking note of this. I'll take a note of this, thanks |
||
// 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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am worried about the new state not being compatible with
currentSlot
here. Either the state should havestate.Slot() == currentSlot
in which case you can just not pass this old parameter, or you need to ensure compatibility. One may be acting on an exit for a slot with data from an old state.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK that is fair, I will remove the state parameter and require the fork parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, actually, we must have the state. So the correct solution is to remove currentSlot and reference state.Slot() as you mentioned