-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Electra: Update WS period computation #4179
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f32744a
Electra: Update WS period computation
mkalinin c9cd560
Update Weak Subjectivity calculations for Electra (#4243)
CarlBeek 89abee9
Add updated table
jtraglia 3dac8a9
Change value in denominator from 4 to 2
jtraglia e87f7ce
Merge branch 'dev' into mkalinin-patch-4
jtraglia 114eaaf
Fix lint & simplify table
jtraglia 9ea6ba6
Simplify table
jtraglia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # Electra -- Weak Subjectivity Guide | ||
|
|
||
| ## Table of contents | ||
|
|
||
| <!-- TOC --> | ||
| <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
| <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
|
|
||
| - [Introduction](#introduction) | ||
| - [Weak Subjectivity Period](#weak-subjectivity-period) | ||
| - [Calculating the Weak Subjectivity Period](#calculating-the-weak-subjectivity-period) | ||
| - [Modified `compute_weak_subjectivity_period`](#modified-compute_weak_subjectivity_period) | ||
| - [Modified `is_within_weak_subjectivity_period`](#modified-is_within_weak_subjectivity_period) | ||
|
|
||
| <!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
| <!-- /TOC --> | ||
|
|
||
| ## Introduction | ||
|
|
||
| This document is an extension of the [Phase 0 -- Weak Subjectivity | ||
| Guide](../phase0/weak-subjectivity.md). All behaviors and definitions defined in this document, and | ||
| documents it extends, carry over unless explicitly noted or overridden. | ||
|
|
||
| This document is a guide for implementing Weak Subjectivity protections in Electra. The Weak | ||
| Subjectivity Period (WSP) calculations have changed in Electra due to EIP-7251, which increases the | ||
| maximum effective balance for validators and allows validators to consolidate. | ||
|
|
||
| ## Weak Subjectivity Period | ||
|
|
||
| ### Calculating the Weak Subjectivity Period | ||
|
|
||
| #### Modified `compute_weak_subjectivity_period` | ||
|
|
||
| ```python | ||
| def compute_weak_subjectivity_period(state: BeaconState) -> uint64: | ||
| """ | ||
| Returns the weak subjectivity period for the current ``state``. | ||
| This computation takes into account the effect of: | ||
| - validator set churn (bounded by ``get_balance_churn_limit()`` per epoch) | ||
| A detailed calculation can be found at: | ||
| https://notes.ethereum.org/@CarlBeek/electra_weak_subjectivity | ||
| """ | ||
| t = get_total_active_balance(state) | ||
| delta = get_balance_churn_limit(state) | ||
| epochs_for_validator_set_churn = SAFETY_DECAY * t // (4 * delta * 100) | ||
| return MIN_VALIDATOR_WITHDRAWABILITY_DELAY + epochs_for_validator_set_churn | ||
| ``` | ||
|
|
||
| A brief reference for what these values look like in practice ([reference | ||
| script](https://gist.github.com/jtraglia/af88887a0718b12f0543580dc195dd09)): | ||
|
|
||
| | Safety Decay | Avg. Val. Balance (ETH) | Val. Count | Weak Sub. Period (Epochs) | | ||
| | ---- | ---- | ---- | ---- | | ||
| | 10 | 28000000000 | 32768 | 435 | | ||
| | 10 | 28000000000 | 65536 | 614 | | ||
| | 10 | 28000000000 | 131072 | 972 | | ||
| | 10 | 28000000000 | 262144 | 1689 | | ||
| | 10 | 28000000000 | 524288 | 1894 | | ||
| | 10 | 28000000000 | 1048576 | 1894 | | ||
| | 10 | 32000000000 | 32768 | 460 | | ||
| | 10 | 32000000000 | 65536 | 665 | | ||
| | 10 | 32000000000 | 131072 | 1075 | | ||
| | 10 | 32000000000 | 262144 | 1894 | | ||
| | 10 | 32000000000 | 524288 | 1894 | | ||
| | 10 | 32000000000 | 1048576 | 1894 | | ||
| | 10 | 36000000000 | 32768 | 486 | | ||
| | 10 | 36000000000 | 65536 | 716 | | ||
| | 10 | 36000000000 | 131072 | 1177 | | ||
| | 10 | 36000000000 | 262144 | 1894 | | ||
| | 10 | 36000000000 | 524288 | 1894 | | ||
| | 10 | 36000000000 | 1048576 | 1894 | | ||
|
|
||
| #### Modified `is_within_weak_subjectivity_period` | ||
|
|
||
| ```python | ||
| def is_within_weak_subjectivity_period(store: Store, ws_state: BeaconState, ws_checkpoint: Checkpoint) -> bool: | ||
| # Clients may choose to validate the input state against the input Weak Subjectivity Checkpoint | ||
| assert ws_state.latest_block_header.state_root == ws_checkpoint.root | ||
| assert compute_epoch_at_slot(ws_state.slot) == ws_checkpoint.epoch | ||
|
|
||
| ws_period = compute_weak_subjectivity_period(ws_state) # [Modified in Electra] | ||
| ws_state_epoch = compute_epoch_at_slot(ws_state.slot) | ||
| current_epoch = compute_epoch_at_slot(get_current_slot(store)) | ||
| return current_epoch <= ws_state_epoch + ws_period | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.