Skip to content

Commit

Permalink
staking: Fix potential division-by-zero
Browse files Browse the repository at this point in the history
`v.DelegatorShares` can be 0 so don't allow division in that case.
  • Loading branch information
jynnantonix authored and joelsmith-2019 committed Jul 10, 2024
1 parent 243e1e3 commit b0d283f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions x/staking/types/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ func (v Validator) InvalidExRate() bool {

// calculate the token worth of provided shares
func (v Validator) TokensFromShares(shares sdk.Dec) math.LegacyDec {
if v.DelegatorShares.IsZero() {
return math.LegacyZeroDec()
}
return (shares.MulInt(v.Tokens)).Quo(v.DelegatorShares)
}

Expand Down

0 comments on commit b0d283f

Please sign in to comment.