diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index b0b4fdce5..7f9d3964a 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1482,7 +1482,9 @@ def process_slashings(state: BeaconState) -> None: total_balance = get_total_active_balance(state) for index, validator in enumerate(state.validators): if validator.slashed and epoch + EPOCHS_PER_SLASHINGS_VECTOR // 2 == validator.withdrawable_epoch: - penalty = validator.effective_balance * min(sum(state.slashings) * 3, total_balance) // total_balance + increment = EFFECTIVE_BALANCE_INCREMENT # Factored out from penalty numerator to avoid uint64 overflow + penalty_numerator = validator.effective_balance // increment * min(sum(state.slashings) * 3, total_balance) + penalty = penalty_numerator // total_balance * increment decrease_balance(state, ValidatorIndex(index), penalty) ``` diff --git a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_slashings.py b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_slashings.py index 7be23a04d..c58da5a4a 100644 --- a/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_slashings.py +++ b/test_libs/pyspec/eth2spec/test/phase_0/epoch_processing/test_process_slashings.py @@ -66,8 +66,13 @@ def test_small_penalty(spec, state): spec.process_slashings(state) yield 'post', state - assert state.balances[0] == pre_slash_balances[0] - (state.validators[0].effective_balance - * 3 * total_penalties // total_balance) + expected_penalty = ( + state.validators[0].effective_balance // spec.EFFECTIVE_BALANCE_INCREMENT + * (3 * total_penalties) + // total_balance + * spec.EFFECTIVE_BALANCE_INCREMENT + ) + assert state.balances[0] == pre_slash_balances[0] - expected_penalty @with_all_phases @@ -121,5 +126,10 @@ def test_scaled_penalties(spec, state): for i in slashed_indices: v = state.validators[i] - penalty = v.effective_balance * total_penalties * 3 // total_balance - assert state.balances[i] == pre_slash_balances[i] - penalty + expected_penalty = ( + v.effective_balance // spec.EFFECTIVE_BALANCE_INCREMENT + * (3 * total_penalties) + // (total_balance) + * spec.EFFECTIVE_BALANCE_INCREMENT + ) + assert state.balances[i] == pre_slash_balances[i] - expected_penalty