Skip to content
3 changes: 2 additions & 1 deletion x/distribution/keeper/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ func (k Keeper) incrementReferenceCount(ctx context.Context, valAddr sdk.ValAddr
if err != nil {
return err
}

historical.ReferenceCount++
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of the panic condition when the reference count exceeds 2 in the incrementReferenceCount function aligns with the PR's objective to mitigate the identified vulnerability. However, this approach introduces a hard stop in the execution flow, which could lead to unhandled panics in production. Consider implementing a more graceful error handling mechanism that allows the calling function to manage the error, enhancing the robustness of the system.

if historical.ReferenceCount > 2 {
panic("reference count should never exceed 2")
}
historical.ReferenceCount++
return k.ValidatorHistoricalRewards.Set(ctx, collections.Join(valAddr, period), historical)
}

Comment on lines 124 to 134
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [198-204]

The call to incrementReferenceCount within updateValidatorSlashFraction does not account for the potential panic introduced by the new logic in incrementReferenceCount. This oversight could lead to unhandled exceptions during slashing events. It's crucial to wrap this call in a try-catch or equivalent error handling structure to prevent crashes and ensure the system's resilience.

Expand Down