Progressive balances optimisation is incorrect with slashed validators #4826
Labels
bug
Something isn't working
consensus
An issue/PR that touches consensus code, such as state_processing or block verification.
tree-states
Upcoming state and database overhaul
Description
While testing Deneb + tree-states, I found a bug in our current progressive balances cache implementation: we update the unslashed participating balances incorrectly for slashed validators. First we remove the balance with
on_slashing
:lighthouse/consensus/types/src/beacon_state/progressive_balances_cache.rs
Lines 67 to 74 in 441fc16
Later, when processing effective balance changes, we update the total by the difference in the slashed validator's effective balance, which is incorrect, because the validator's balance has already been removed:
lighthouse/consensus/state_processing/src/per_epoch_processing/effective_balance_updates.rs
Lines 58 to 66 in 441fc16
The result is that the total unslashed participating balance can be off by
O(num_slashed_validators)
. This is unlikely to cause issues in practice, because:--progressive-balances fast
, the worst-case is a temporary view split, which would require a lot of validators to be slashed. If the slashing is small, it's unlikely to cause a view split, because the attesting balances will only be off by a small amount.Version
Lighthouse v4.5.0
Steps to resolve
Guard the
on_effective_balance_change
call by!validator.slashed()
. On tree-states, I've forced the caller to pass the validator'sis_slashed
status toon_effective_balance_change
:lighthouse/consensus/state_processing/src/per_epoch_processing/single_pass.rs
Lines 623 to 630 in b77de69
We should make a similar change on
unstable
, with an accompanying regression test. The conditions necessary to trigger this are:The text was updated successfully, but these errors were encountered: