Skip to content

Commit

Permalink
add check for SafeSub
Browse files Browse the repository at this point in the history
  • Loading branch information
kamuikatsurgi committed Jan 16, 2025
1 parent 69a02b6 commit 0bb18b7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion x/gov/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,11 @@ func (keeper Keeper) DistributeAndDeleteDeposits(ctx context.Context, proposalID

// Calculate any remaining amount due to truncating issues
usedAmount := amountPerValidator.MulInt(sdkmath.NewInt(int64(numValidators)))
remainingAmount, _ := totalDeposits.SafeSub(usedAmount...)
remainingAmount, isNegative := totalDeposits.SafeSub(usedAmount...)
if isNegative {
keeper.Logger(ctx).Error("subtraction resulted in a negative amount", "totalDeposits", totalDeposits, "usedAmount", usedAmount)
return fmt.Errorf("subtraction resulted in a negative amount")
}

if !remainingAmount.IsZero() {
// Send remaining amount to the first validator
Expand Down

0 comments on commit 0bb18b7

Please sign in to comment.