Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: integer overflow #161

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions x/mint/types/minter.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func (m Minter) NextInflationRate(params Params, bondedRatio sdk.Dec) sdk.Dec {
inflationRateChangePerYear := sdk.OneDec().
Sub(bondedRatio.Quo(params.InflationParameters.GoalBonded)).
Mul(params.InflationParameters.InflationRateChange)
inflationRateChange := inflationRateChangePerYear.Quo(sdk.NewDec(int64(params.InflationParameters.BlocksPerYear)))

inflationRateChange := inflationRateChangePerYear.QuoInt(sdk.NewIntFromUint64(params.InflationParameters.BlocksPerYear))
// adjust the new annual inflation for this next cycle
inflation := m.Inflation.Add(inflationRateChange) // note inflationRateChange may be negative
if inflation.GT(params.InflationParameters.InflationMax) {
Expand All @@ -75,6 +75,6 @@ func (m Minter) NextAnnualProvisions(_ Params, totalSupply sdk.Int) sdk.Dec {
// BlockProvision returns the provisions for a block based on the annual
// provisions rate.
func (m Minter) BlockProvision(params Params) sdk.Coin {
provisionAmt := m.AnnualProvisions.QuoInt(sdk.NewInt(int64(params.InflationParameters.BlocksPerYear)))
provisionAmt := m.AnnualProvisions.QuoInt(sdk.NewIntFromUint64(params.InflationParameters.BlocksPerYear))
return sdk.NewCoin(params.MintDenom, provisionAmt.TruncateInt())
}
1 change: 1 addition & 0 deletions x/mint/types/minter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
)

Expand Down