Prevent overflow during inactivity leak

This commit is contained in:
Shane Bammel 2022-12-13 16:59:50 -06:00
parent e154590063
commit fd231a618a

View File

@ -345,11 +345,11 @@ func attestationDelta(
// Process finality delay penalty // Process finality delay penalty
// Apply an additional penalty to validators that did not vote on the correct target or slashed // Apply an additional penalty to validators that did not vote on the correct target or slashed
if !val.IsPrevEpochTargetAttester || val.IsSlashed { if !val.IsPrevEpochTargetAttester || val.IsSlashed {
n, err := math.Mul64(effectiveBalance, val.InactivityScore) // effectiveBalance * val.InactivityScore / inactivityDenominator
if err != nil { inactivityPenalty := new(big.Int).SetUint64(effectiveBalance)
return &AttDelta{}, err inactivityPenalty.Mul(inactivityPenalty, new(big.Int).SetUint64(val.InactivityScore))
} inactivityPenalty.Div(inactivityPenalty, new(big.Int).SetUint64(inactivityDenominator))
attDelta.InactivityPenalty = n / inactivityDenominator attDelta.InactivityPenalty = inactivityPenalty.Uint64()
} }
return attDelta, nil return attDelta, nil