Skip to content
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

EIP-7251: Handle top-ups to exiting/exited validators #3650

Closed
wants to merge 9 commits into from

Conversation

fradamt
Copy link
Contributor

@fradamt fradamt commented Apr 4, 2024

Currently, a top-up can be made to an exiting validator, so that the balance exits the active set soon after being activated. Even if the top-up goes through the activation churn, this may still have some weak subjectivity impact because exits have twice the weak subjectivity impact of activations (see https://notes.ethereum.org/SyjG0FomTxqKki1m2cmU9w#Consolidations-and-churn-limit). Similarly, a top-up can be made to a consolidating validator, where the consolidation target is itself exiting, so that the balance ends up moving to the target and then shortly after leaving the active set without going through the exit churn.

To handle this, we just postpone the deposits of exiting validators (consolidating validators are included, since they have a set exit epoch), by skipping the pending_balance_deposit and appending it at the end of state.pending_balance_deposits. The deposit is only processed (strictly) after the withdrawable epoch. In the case of a normal exit, even just processing the deposit after the exit epoch would suffice, because the balance would never become active and can only be withdrawn. In the case of a consolidating validator, the consolidation happens on withdrawable epoch, so any balance deposited to the source after that never becomes active and can only be withdrawn.

Since the balance of a postponed deposit never become active, we don't require it to go through the churn , so we don't count it towards decreasing state.deposit_balance_to_consume.

Note that such a deposit might be postponed (skipped and appended at the end of the queue) multiple times, until it is processed at the right epoch.

Currently, a top-up can be made to an exiting validator, so that the balance exits the active set soon after being activated. Even if the top-up goes through the activation churn, this may still have some weak subjectivity impact because exits have twice the weak subjectivity impact of activations (see https://notes.ethereum.org/SyjG0FomTxqKki1m2cmU9w#Consolidations-and-churn-limit).

To handle this, we just postpone the deposits of exiting validators, by skipping the `pending_balance_deposit` and appending it at the end of `state.pending_balance_deposits`. This might happen multiple times, as the deposit is only processed once the validator is exited. 

We also modify the processing of pending balance deposits from exited validators. Since the deposited balance goes straight to an exited validator and thus never becomes active, we don't need to have it go through the churn, so we don't count it towards decreasing `state.deposit_balance_to_consume`
@hwwhww hwwhww changed the title Handle top-ups to exiting/exited validators EIP-7251: Handle top-ups to exiting/exited validators Apr 4, 2024
- Fixes infinite loop pointed out by Mikhail, when there are only deposits of exiting validators in the queue
- Prevents accumulation of deposit_balance_to_consume when there are just postponed deposits in the queue
@ralexstokes
Copy link
Member

I think this generally makes sense but I haven't gone through the diff with a fine-toothed comb yet.

We should be careful with the final set of 7251 changes to preserve weak subjectivity invariants as much as possible.

As discussed with @mkalinin, we only want to process a top-up to an an exiting validator (strictly) after withdrawable epoch, to ensure that the topped-up balance never becomes active even when the exiting validator is actually consolidating. In that case, the consolidation gets processed on withdrawable epoch, after which any balance deposited to the validator can only ever be withdrawn.
Co-authored-by: Mikhail Kalinin <noblesse.knight@gmail.com>
Comment on lines 132 to 135
pre_balances = state.balances
yield from run_epoch_processing_with(spec, state, 'process_pending_balance_deposits')
# All deposits are postponed, no balance changes
assert state.balances == pre_balances
Copy link
Contributor

@hwwhww hwwhww Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python mutable trap: pre_balances = state.balances makes pre_balances point to state.balances itself, therefore assert state.balances == pre_balances is always true.

Suggested change
pre_balances = state.balances
yield from run_epoch_processing_with(spec, state, 'process_pending_balance_deposits')
# All deposits are postponed, no balance changes
assert state.balances == pre_balances
pre_balances = state.balances.copy()
yield from run_epoch_processing_with(spec, state, 'process_pending_balance_deposits')
# All deposits are postponed, no balance changes
assert state.balances == pre_balances

I'm going to push commit to fix this file!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Copy link
Contributor

@hwwhww hwwhww left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

not have to be in this PR, but we can set a smaller PENDING_BALANCE_DEPOSITS_LIMIT for minimal preset to test the bound.

Comment on lines +165 to +166
amount01 = spec.EFFECTIVE_BALANCE_INCREMENT
amount2 = spec.MAX_EFFECTIVE_BALANCE_EIP7251
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first, my OCD was triggered, but then I found out it's "amount for 0 and 1".

@philknows philknows mentioned this pull request May 2, 2024
31 tasks
@hwwhww hwwhww added the scope:security General protocol security-related items label May 9, 2024
@fradamt
Copy link
Contributor Author

fradamt commented May 22, 2024

Closing, superseded by #3776

@fradamt fradamt closed this May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Electra scope:security General protocol security-related items
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants