---
tags: rewards
---
# Rewards and Penalties
# награды
#### BaseReward
базовая награда за аттестацию включенную в блок, вычисляется для каждой аттестации
*BaseReward takes state and validator index and calculate individual validator's base reward.*
$BaseReward = {validator.EffectiveBalance() \over cfg.EffectiveBalanceIncrement} * {cfg.EffectiveBalanceIncrement * cfg.BaseRewardFactor \over \sqrt{activeBalance}}$
>validator.EffectiveBalance - баланс заданного валидатора
>activeBalance - сумма EffectiveBalance всех активных валидаторов
>EffectiveBalanceIncrement=1 * 1e9
>BaseRewardFactor=64
## награда за создание блока в координирующей сети
### proposerReward := proposerRewardNumerator / d
$proposerReward := {proposerRewardNumerator \over d}$
>proposerReward=687281
proposerRewardNumerator=307901952
d=448
__где:__
__d__ - denominator
$d:= {{(cfg.WeightDenominator - cfg.ProposerWeight) * cfg.WeightDenominator} \over cfg.ProposerWeight}$
>cfg.ProposerWeight=8
cfg.WeightDenominator=64
__proposerRewardNumerator__
$proposerRewardNumerator = \sum_{i=1}^{len(bl.atts)} SourceReward_i + TargetReward_i + HeadReward_i$
__где:__
Сумма значений вычисляемых для каждой аттестации включенной в блок
$SourceReward_i = BaseReward_i * cfg.TimelySourceWeight * SourceCondition_i$
$TargetReward_i = BaseReward_i * cfg.TimelyTargetWeight * TargetCondition_i$
$HeadReward_i = BaseReward_i * cfg.TimelyHeadWeight * HeadCondition_i$
$BaseReward_i$ - базовая награда за аттестацию включенную в блок, вычисляется для каждой аттестации
>$cfg.TimelySourceWeight$=14 (TIMELY_SOURCE_WEIGHT is the factor of how much source rewards receives)
$cfg.TimelyTargetWeight$=26 (TIMELY_TARGET_WEIGHT is the factor of how much target rewards receives)
$cfg.TimelyHeadWeight$=14 (TIMELY_HEAD_WEIGHT is the factor of how much head rewards receives)
$SourceCondition_i, TargetCondition_i, HeadCondition_i ∈ \{0, 1\}$ - условие начисления. зависит от наличие соотв. данных в аттестации (тут не очень понятен механизм) и добавлялись ли данные ранее (чтобы исключить повторное добавление уже добавленных)
## награда за агрегацию аттестаций в координирующей сети
Нет
## награда за аттестацию в координирующей сети
Cрабатывает в конце эпохи.
$reward = SourceReward_i + TargetReward_i + HeadReward_i$
__где:__
$SourceReward_i ={
BaseReward_i * cfg.TimelySourceWeight * {bal.PrevEpochAttested \over cfg.EffectiveBalanceIncrement}
\over {activeIncrement * cfg.WeightDenominator}} * rwdSourceCondition_i$
$TargetReward_i ={
BaseReward * cfg.TimelyTargetWeight * {bal.PrevEpochTargetAttested \over cfg.EffectiveBalanceIncrement}
\over {activeIncrement * cfg.WeightDenominator}} * rwdTargetCondition_i$
$HeadReward_i ={
BaseReward * cfg.TimelyHeadWeight * {bal.PrevEpochHeadAttested \over cfg.EffectiveBalanceIncrement}
\over {activeIncrement * cfg.WeightDenominator}} * rwdHeadCondition_i$
__где:__
$activeIncrement := {bal.ActiveCurrentEpoch \over cfg.EffectiveBalanceIncrement}$
$rwdSourceCondition_i, rwdTargetCondition_i, rwdHeadCondition_i ∈ \{0, 1\}$ - условие начисления соотв. награды
```
rwdSourceCondition_i = val.IsPrevEpochSourceAttester && !val.IsSlashed && !inactivityLeak && eligible ? 1 : 0
rwdTargetCondition_i = val.IsPrevEpochTargetAttester && !val.IsSlashed && !inactivityLeak && eligible ? 1 : 0
rwdHeadCondition_i = val.IsPrevEpochHeadAttester && !val.IsSlashed && !inactivityLeak && eligible ? 1 : 0
// if the validator was active prev epoch or slashed
eligible = val.IsActivePrevEpoch || (val.IsSlashed && !val.IsWithdrawableCurrentEpoch)
```
## SyncCommittee: награда за агрегацию аттестаций рута стейта предшествующего слота (currentSlot - 1) для поддержки LightClient
Нет
## SyncCommittee: награда за аттестацию рута стейта предшествующего слота (currentSlot - 1) для поддержки LightClient
Cрабатывает на каждом слоте начиная с __Альтаир__.
$participantReward = {{BaseReward * cfg.SyncRewardWeight} \over {cfg.WeightDenominator * cfg.SlotsPerEpoch * cfg.SyncCommitteeSize}}$
> SyncRewardWeight=2 (SYNC_REWARD_WEIGHT is the factor of how much sync committee rewards receives)
> WeightDenominator=64
> SlotsPerEpoch=32 (SLOTS_PER_EPOCH is the number of slots in an epoch)
> SyncCommitteeSize=512 (SYNC_COMMITTEE_SIZE for light client sync committee size)
## SyncCommittee: награда пропозеру за включение аттестаций рута стейта предшествующего слота (currentSlot - 1) для поддержки LightClient
Начисляется только за голосовавших участников
$reward = \sum_{i=1}^{bl.SyncAggregate.Len()} proposerReward * IsVotedIndex_i$
__где:__
$proposerReward = {{participantReward * cfg.ProposerWeight} \over {cfg.WeightDenominator - cfg.ProposerWeight}}$
> ProposerWeight=8 (PROPOSER_WEIGHT is the factor of how much proposer rewards receives)
> WeightDenominator=64 (WEIGHT_DENOMINATOR accounts for total rewards denomination)
## награда за Слэшинг в координирующей сети
> whistleBlower (обличитель) - устанавливает факт слэшинг-нарушения
> In phase 0, the proposer is the whistleblower
> тот же функционал используется и для Альтаира
для расчетов используется значение
##### whistleblowerReward := slashValidator.EffectiveBalance / cfg.WhistleBlowerRewardQuotient
> WhistleBlowerRewardQuotient=512
награда состоит состоит из двух частей (ресипиент один и тот же):
### 1. пропозеру за слешинг (одного валидатора)
#### proposerReward := whistleblowerReward / cfg.ProposerRewardQuotient
> ProposerRewardQuotient=8
### 2. обличителю за слешинг (одного валидатора)
#### whistleblowerReward := whistleblowerReward - proposerReward
# штрафы
## штраф за пропуск аттестации
Cрабатывает в конце эпохи.
$penalty = SourcePenalty_i + TargetPenalty_i + InactivityPenalty_i$
__где:__
$SourcePenalty_i ={{baseReward * cfg.TimelySourceWeight} \over cfg.WeightDenominator} * penaltySourceCondition_i$
$TargetPenalty_i ={{baseReward * cfg.TimelyTargetWeight} \over cfg.WeightDenominator} * penaltyTargetCondition_i$
$InactivityPenalty_i = {{val.effectiveBalance * val.InactivityScore} \over {cfg.InactivityScoreBias * cfg.InactivityPenaltyQuotientAltair}} * penaltyInactivityCondition_i$
__где:__
$penaltySourceCondition_i, penaltyTargetCondition_i, penaltyInactivityCondition_i ∈ \{0, 1\}$ - условие начисления соотв. штрафа
```
penaltySourceCondition_i = val.IsPrevEpochSourceAttester && !val.IsSlashed && eligible ? 0 : 1
penaltyTargetCondition_i = val.IsPrevEpochTargetAttester && !val.IsSlashed && eligible ? 0 : 1
$penaltyInactivityCondition_i = (!val.IsPrevEpochTargetAttester || val.IsSlashed) && eligible ? 1 : 0
// if the validator was active prev epoch or slashed
eligible = val.IsActivePrevEpoch || (val.IsSlashed && !val.IsWithdrawableCurrentEpoch)
```
/*
2.1. source penalty:
condition !(validator.IsPrevEpochSourceAttester && !validator.IsSlashed)
penalty = baseReward * cfg.TimelySourceWeight / cfg.WeightDenominator
2.2. target penalty:
condition !(validator.IsPrevEpochTargetAttester && !validator.IsSlashed)
penalty = baseReward * cfg.TimelyTargetWeight / cfg.WeightDenominator
#### 2.3. an additional penalty to validators that did not vote on the correct target or slashed:
##### condition (!validator.IsPrevEpochTargetAttester || validator.IsSlashed)
##### penalty = (validator.CurrentEpochEffectiveBalance * validator.InactivityScore) / (cfg.InactivityScoreBias * cfg.InactivityPenaltyQuotientAltair)
*/
## SyncCommittee: штраф за пропуск аттестации рута предшествующего блока
*такой же как и соотв. награда за аттестацию рута*
$participantReward = {{BaseReward * cfg.SyncRewardWeight} \over {cfg.WeightDenominator * cfg.SlotsPerEpoch * cfg.SyncCommitteeSize}}$
> SyncRewardWeight=2 (SYNC_REWARD_WEIGHT is the factor of how much sync committee rewards receives)
> WeightDenominator=64
> SlotsPerEpoch=32 (SLOTS_PER_EPOCH is the number of slots in an epoch)
> SyncCommitteeSize=512 (SYNC_COMMITTEE_SIZE for light client sync committee size)
## Штраф за Слэшинг в координирующей сети (первоначальный - начисляется сразу по факту обнаружения)
> The slashing amount is represented by epochs per slashing vector. The validator's effective balance is then applied to that amount.
#### penalty = slashValidator.EffectiveBalance/cfg.MinSlashingPenaltyQuotientAltair
> MinSlashingPenaltyQuotientAltair=64
## Штраф за Слэшинг в координирующей сети (каждую эпоху) версия 1 *(проверить)*
> `beacon-chain/core/epoch/epoch_processing.go:169`
> `func ProcessSlashings(state state.BeaconState, slashingMultiplier uint64) (state.BeaconState, error)`
> ProcessSlashings processes the slashed validators during epoch processing,
##### minSlashing := math.Min(totalSlashedValidators * cfg.ProportionalSlashingMultiplierAltair, totalActiveValidatorBalance)
> ProportionalSlashingMultiplierAltair=2
> totalActiveValidatorBalance - суммарный баланс всех активных валидаторов
### penalty := (slashValidator.EffectiveBalance / cfg.EffectiveBalanceIncrement * minSlashing) / totalActiveValidatorBalance * cfg.EffectiveBalanceIncrement
## Штраф за Слэшинг в координирующей сети (каждую эпоху) версия 2 *(проверить)*
> `beacon-chain/core/epoch/precompute/slashing.go:15`
> `// This is an optimized version by passing in precomputed total epoch balances.`
> `func ProcessSlashingsPrecompute(s state.BeaconState, pBal *Balance) error`
##### minSlashing := math.Min(totalSlashedValidators * cfg.ProportionalSlashingMultiplier, pBal.ActiveCurrentEpoch)
> Balance.ActiveCurrentEpoch - is the total effective balance of all active validators during current epoch.
### penalty := (slashValidator.EffectiveBalance / cfg.EffectiveBalanceIncrement * minSlashing) / pBal.ActiveCurrentEpoch * cfg.EffectiveBalanceIncrement