Skip to content

Commit f9797f9

Browse files
mkalininjtraglia
authored andcommitted
Update WS period computation for Electra (#4179)
1 parent 37b8dcf commit f9797f9

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

specs/electra/weak-subjectivity.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Electra -- Weak Subjectivity Guide
2+
3+
<!-- mdformat-toc start --slug=github --no-anchors --maxlevel=6 --minlevel=2 -->
4+
5+
- [Introduction](#introduction)
6+
- [Weak Subjectivity Period](#weak-subjectivity-period)
7+
- [Calculating the Weak Subjectivity Period](#calculating-the-weak-subjectivity-period)
8+
- [Modified `compute_weak_subjectivity_period`](#modified-compute_weak_subjectivity_period)
9+
- [Modified `is_within_weak_subjectivity_period`](#modified-is_within_weak_subjectivity_period)
10+
11+
<!-- mdformat-toc end -->
12+
13+
## Introduction
14+
15+
This document is an extension of the [Phase 0 -- Weak Subjectivity
16+
Guide](../phase0/weak-subjectivity.md). All behaviors and definitions defined in this document, and
17+
documents it extends, carry over unless explicitly noted or overridden.
18+
19+
This document is a guide for implementing Weak Subjectivity protections in Electra. The Weak
20+
Subjectivity Period (WSP) calculations have changed in Electra due to EIP-7251, which increases the
21+
maximum effective balance for validators and allows validators to consolidate.
22+
23+
## Weak Subjectivity Period
24+
25+
### Calculating the Weak Subjectivity Period
26+
27+
#### Modified `compute_weak_subjectivity_period`
28+
29+
```python
30+
def compute_weak_subjectivity_period(state: BeaconState) -> uint64:
31+
"""
32+
Returns the weak subjectivity period for the current ``state``.
33+
This computation takes into account the effect of:
34+
- validator set churn (bounded by ``get_balance_churn_limit()`` per epoch)
35+
A detailed calculation can be found at:
36+
https://notes.ethereum.org/@CarlBeek/electra_weak_subjectivity
37+
"""
38+
t = get_total_active_balance(state)
39+
delta = get_balance_churn_limit(state)
40+
epochs_for_validator_set_churn = SAFETY_DECAY * t // (2 * delta * 100)
41+
return MIN_VALIDATOR_WITHDRAWABILITY_DELAY + epochs_for_validator_set_churn
42+
```
43+
44+
A brief reference for what these values look like in practice ([reference
45+
script](https://gist.github.com/jtraglia/457fd9ae7d2080fef1e4034a39b80c46)):
46+
47+
| Safety Decay | Total Active Balance (ETH) | Weak Sub. Period (Epochs) |
48+
| -----------: | -------------------------: | ------------------------: |
49+
| 10 | 1,048,576 | 665 |
50+
| 10 | 2,097,152 | 1,075 |
51+
| 10 | 4,194,304 | 1,894 |
52+
| 10 | 8,388,608 | 3,532 |
53+
| 10 | 16,777,216 | 3,532 |
54+
| 10 | 33,554,432 | 3,532 |
55+
56+
#### Modified `is_within_weak_subjectivity_period`
57+
58+
```python
59+
def is_within_weak_subjectivity_period(store: Store, ws_state: BeaconState, ws_checkpoint: Checkpoint) -> bool:
60+
# Clients may choose to validate the input state against the input Weak Subjectivity Checkpoint
61+
assert ws_state.latest_block_header.state_root == ws_checkpoint.root
62+
assert compute_epoch_at_slot(ws_state.slot) == ws_checkpoint.epoch
63+
64+
ws_period = compute_weak_subjectivity_period(ws_state) # [Modified in Electra]
65+
ws_state_epoch = compute_epoch_at_slot(ws_state.slot)
66+
current_epoch = compute_epoch_at_slot(get_current_slot(store))
67+
return current_epoch <= ws_state_epoch + ws_period
68+
```

0 commit comments

Comments
 (0)