diff --git a/math/int.go b/math/int.go index dc945b13d283..d5ed342d7094 100644 --- a/math/int.go +++ b/math/int.go @@ -264,10 +264,6 @@ func (i Int) Mul(i2 Int) (res Int) { panic("Int overflow") } res = Int{mul(i.i, i2.i)} - // Check overflow if sign of both are same - if res.i.BitLen() > MaxBitLen { - panic("Int overflow") - } return } diff --git a/types/coin.go b/types/coin.go index 136295eed295..41c526e5d104 100644 --- a/types/coin.go +++ b/types/coin.go @@ -314,6 +314,8 @@ func (coins Coins) Add(coinsB ...Coin) Coins { return coins.safeAdd(coinsB) } +var zeroInt = math.NewInt(0) + // safeAdd will perform addition of two coins sets. If both coin sets are // empty, then an empty set is returned. If only a single set is empty, the // other set is returned. Otherwise, the coins are compared in order of their @@ -339,7 +341,7 @@ func (coins Coins) safeAdd(coinsB Coins) (coalesced Coins) { } for denom, cL := range uniqCoins { //#nosec - comboCoin := Coin{Denom: denom, Amount: math.NewInt(0)} + comboCoin := Coin{Denom: denom, Amount: zeroInt} for _, c := range cL { comboCoin = comboCoin.Add(c) } @@ -820,9 +822,6 @@ var _ sort.Interface = Coins{} // Sort is a helper function to sort the set of coins in-place func (coins Coins) Sort() Coins { - // sort.Sort(coins) does a costly runtime copy as part of `runtime.convTSlice` - // So we avoid this heap allocation if len(coins) <= 1. In the future, we should hopefully find - // a strategy to always avoid this. if len(coins) > 1 { sort.Sort(coins) }