add REWARD_OVERFLOW_INCREMENT to avoid overflow in rewards calculation
This commit is contained in:
parent
a14708afcb
commit
2d4ec7d52f
|
@ -194,6 +194,7 @@ The following values are (non-configurable) constants used throughout the specif
|
||||||
| `MAX_EFFECTIVE_BALANCE` | `Gwei(2**5 * 10**9)` (= 32,000,000,000) |
|
| `MAX_EFFECTIVE_BALANCE` | `Gwei(2**5 * 10**9)` (= 32,000,000,000) |
|
||||||
| `EJECTION_BALANCE` | `Gwei(2**4 * 10**9)` (= 16,000,000,000) |
|
| `EJECTION_BALANCE` | `Gwei(2**4 * 10**9)` (= 16,000,000,000) |
|
||||||
| `EFFECTIVE_BALANCE_INCREMENT` | `Gwei(2**0 * 10**9)` (= 1,000,000,000) |
|
| `EFFECTIVE_BALANCE_INCREMENT` | `Gwei(2**0 * 10**9)` (= 1,000,000,000) |
|
||||||
|
| `REWARD_OVERFLOW_INCREMENT` | `Gwei(2**6)` (= 64) |
|
||||||
|
|
||||||
### Initial values
|
### Initial values
|
||||||
|
|
||||||
|
@ -1313,7 +1314,9 @@ def get_attestation_deltas(state: BeaconState) -> Tuple[Sequence[Gwei], Sequence
|
||||||
attesting_balance = get_total_balance(state, unslashed_attesting_indices)
|
attesting_balance = get_total_balance(state, unslashed_attesting_indices)
|
||||||
for index in eligible_validator_indices:
|
for index in eligible_validator_indices:
|
||||||
if index in unslashed_attesting_indices:
|
if index in unslashed_attesting_indices:
|
||||||
rewards[index] += get_base_reward(state, index) * attesting_balance // total_balance
|
increment = REWARD_OVERFLOW_INCREMENT # Factored out from reward numerator to avoid uint64 overflow
|
||||||
|
reward_numerator = get_base_reward(state, index) // increment * attesting_balance
|
||||||
|
rewards[index] = reward_numerator // total_balance * increment
|
||||||
else:
|
else:
|
||||||
penalties[index] += get_base_reward(state, index)
|
penalties[index] += get_base_reward(state, index)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from eth2spec.test.context import spec_state_test, with_all_phases, spec_test, \
|
from eth2spec.test.context import (
|
||||||
misc_balances, with_custom_state, default_activation_threshold, single_phase
|
spec_state_test, with_all_phases, spec_test,
|
||||||
|
misc_balances, with_custom_state, default_activation_threshold,
|
||||||
|
single_phase,
|
||||||
|
)
|
||||||
from eth2spec.test.helpers.state import (
|
from eth2spec.test.helpers.state import (
|
||||||
next_epoch,
|
next_epoch,
|
||||||
next_slot,
|
next_slot,
|
||||||
|
|
Loading…
Reference in New Issue