-
Notifications
You must be signed in to change notification settings - Fork 971
Implement weak subjectivity safety checks #7347
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
Changes from 1 commit
448f36d
48ee262
6ac8d99
c2b9f9f
1727167
e6fdd4d
1086b50
c995e6a
54228e0
b5adc67
8cb1a78
c09954a
83f6ac4
3d919f0
c524e98
5db3205
a2886a4
bc60964
5bb7d46
d808c07
73e6eb6
5243aaf
ccfbb8a
490ce0c
2ba18d3
d4b3d34
0b25b1d
8a62893
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 |
|---|---|---|
|
|
@@ -2505,6 +2505,30 @@ impl<E: EthSpec> BeaconState<E> { | |
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Returns the weak subjectivity period for `self`. 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 | ||
| pub fn compute_weak_subjectivity_period(&self, spec: &ChainSpec) -> Result<Epoch, Error> { | ||
| // `SAFETY_DECAY` is defined as the maximum percentage tolerable loss in the one-third | ||
| // safety margin of FFG finality. Thus, any attack exploiting the Weak Subjectivity Period has | ||
| // a safety margin of at least `1/3 - SAFETY_DECAY/100`. | ||
| // Spec: https://github.com/ethereum/consensus-specs/blob/1937aff86b41b5171a9bc3972515986f1bbbf303/specs/phase0/weak-subjectivity.md?plain=1#L50-L71 | ||
| // TODO(ws) move this to config | ||
| const SAFETY_DECAY: u64 = 10; | ||
|
|
||
| let total_active_balance = self.get_total_active_balance()?; | ||
| let balance_churn_limit = self.get_balance_churn_limit(spec)?; | ||
| let epochs_for_validator_set_churn = SAFETY_DECAY | ||
| .safe_mul(total_active_balance)? | ||
| .safe_div(balance_churn_limit.safe_mul(200)?)?; | ||
| let weak_subjectivity_period = spec | ||
| .min_validator_withdrawability_delay | ||
| .safe_mul(epochs_for_validator_set_churn)?; | ||
|
||
|
|
||
| Ok(weak_subjectivity_period) | ||
| } | ||
| } | ||
|
|
||
| impl<E: EthSpec> BeaconState<E> { | ||
|
|
||
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.
Just use the
head_snapshot.beacon_stateto compute the weak subjectivity period. You don't need to fetch the head state's finalize state. For WS sync, the head state = the weak subjectivity checkpoint state. You don't need to fetch any more data:current_epoch <= head_state.epoch + ws_periodNo need to involve the store here