Skip to content

Commit

Permalink
fix: update param validation to fail on nil dec (#1323)
Browse files Browse the repository at this point in the history
* fix: update param validation to fail on nil dec

* chore: update changelog

(cherry picked from commit 55b6566)

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
jaeseung-bae authored and mergify[bot] committed Mar 28, 2024
1 parent 971875b commit 923a858
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,34 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

### Bug Fixes
<<<<<<< HEAD
* (x/auth) [#1281](https://github.com/Finschia/finschia-sdk/pull/1281) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking. (backport #1274)
* (x/foundation) [\#1283](https://github.com/Finschia/finschia-sdk/pull/1283) add init logic of foundation module accounts to InitGenesis in order to eliminate potential panic (backport #1277)
* (x/collection) [\#1282](https://github.com/Finschia/finschia-sdk/pull/1282) eliminates potential risk for Insufficient Sanity Check of tokenID in Genesis (backport #1276)
* (x/collection) [\#1290](https://github.com/Finschia/finschia-sdk/pull/1290) export x/collection params into genesis (backport #1268)
* (x/foundation) [\#1295](https://github.com/Finschia/finschia-sdk/pull/1295) add missing error handling for migration
=======
* chore(deps) [\#1141](https://github.com/Finschia/finschia-sdk/pull/1141) Bump github.com/cosmos/ledger-cosmos-go from 0.12.2 to 0.13.2 to fix ledger signing issue
* (x/auth, x/slashing) [\#1179](https://github.com/Finschia/finschia-sdk/pull/1179) modify missing changes of converting to tendermint
* (x/auth) [#1274](https://github.com/Finschia/finschia-sdk/pull/1274) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking.
* (x/collection) [\#1276](https://github.com/Finschia/finschia-sdk/pull/1276) eliminates potential risk for Insufficient Sanity Check of tokenID in Genesis
* (x/foundation) [\#1277](https://github.com/Finschia/finschia-sdk/pull/1277) add init logic of foundation module accounts to InitGenesis in order to eliminate potential panic
* (x/collection, x/token) [\#1288](https://github.com/Finschia/finschia-sdk/pull/1288) use accAddress to compare in validatebasic function in collection & token modules
* (x/collection) [\#1268](https://github.com/Finschia/finschia-sdk/pull/1268) export x/collection params into genesis
* (x/collection) [\#1294](https://github.com/Finschia/finschia-sdk/pull/1294) reject NFT coins on FT APIs
* (sec) [\#1302](https://github.com/Finschia/finschia-sdk/pull/1302) remove map iteration non-determinism with keys + sorting
* (client) [\#1303](https://github.com/Finschia/finschia-sdk/pull/1303) fix possible overflow in BuildUnsignedTx
* (types) [\#1299](https://github.com/Finschia/finschia-sdk/pull/1299) add missing nil checks
* (x/staking) [\#1301](https://github.com/Finschia/finschia-sdk/pull/1301) Use bytes instead of string comparison in delete validator queue (backport cosmos/cosmos-sdk#12303)
* (x/gov) [\#1304](https://github.com/Finschia/finschia-sdk/pull/1304) fetch a failed proposal tally from proposal.FinalTallyResult in the gprc query
* (x/staking) [\#1306](https://github.com/Finschia/finschia-sdk/pull/1306) add validation for potential slashing evasion during re-delegation
* (client/keys) [#1312](https://github.com/Finschia/finschia-sdk/pull/1312) ignore error when key not found in `keys delete`
* (store) [\#1310](https://github.com/Finschia/finschia-sdk/pull/1310) fix app-hash mismatch if upgrade migration commit is interrupted(backport cosmos/cosmos-sdk#13530)
* (types) [\#1313](https://github.com/Finschia/finschia-sdk/pull/1313) fix correctly coalesce coins even with repeated denominations(backport cosmos/cosmos-sdk#13265)
* (x/crypto) [\#1316](https://github.com/Finschia/finschia-sdk/pull/1316) error if incorrect ledger public key (backport cosmos/cosmos-sdk#14460, cosmos/cosmos-sdk#19691)
* (x/auth) [#1319](https://github.com/Finschia/finschia-sdk/pull/1319) prevent signing from wrong key in multisig
* (x/mint, x/slashing) [\#1323](https://github.com/Finschia/finschia-sdk/pull/1323) add missing nil check for params validation
>>>>>>> 55b6566bf (fix: update param validation to fail on nil dec (#1323))
### Removed

Expand Down
18 changes: 13 additions & 5 deletions x/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"strings"

yaml "gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"

sdk "github.com/Finschia/finschia-sdk/types"
paramtypes "github.com/Finschia/finschia-sdk/x/params/types"
Expand Down Expand Up @@ -120,7 +120,9 @@ func validateInflationRateChange(i interface{}) error {
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("inflation rate change cannot be nil: %s", v)
}

Check warning on line 125 in x/mint/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/mint/types/params.go#L123-L125

Added lines #L123 - L125 were not covered by tests
if v.IsNegative() {
return fmt.Errorf("inflation rate change cannot be negative: %s", v)
}
Expand All @@ -136,7 +138,9 @@ func validateInflationMax(i interface{}) error {
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("max inflation cannot be nil: %s", v)
}

Check warning on line 143 in x/mint/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/mint/types/params.go#L141-L143

Added lines #L141 - L143 were not covered by tests
if v.IsNegative() {
return fmt.Errorf("max inflation cannot be negative: %s", v)
}
Expand All @@ -152,7 +156,9 @@ func validateInflationMin(i interface{}) error {
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("min inflation cannot be nil: %s", v)
}

Check warning on line 161 in x/mint/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/mint/types/params.go#L159-L161

Added lines #L159 - L161 were not covered by tests
if v.IsNegative() {
return fmt.Errorf("min inflation cannot be negative: %s", v)
}
Expand All @@ -168,7 +174,9 @@ func validateGoalBonded(i interface{}) error {
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("goal bonded cannot be nil: %s", v)
}

Check warning on line 179 in x/mint/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/mint/types/params.go#L177-L179

Added lines #L177 - L179 were not covered by tests
if v.IsNegative() || v.IsZero() {
return fmt.Errorf("goal bonded must be positive: %s", v)
}
Expand Down
12 changes: 9 additions & 3 deletions x/slashing/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ func validateMinSignedPerWindow(i interface{}) error {
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("min signed per window cannot be nil: %s", v)
}

Check warning on line 90 in x/slashing/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/slashing/types/params.go#L88-L90

Added lines #L88 - L90 were not covered by tests
if v.IsNegative() {
return fmt.Errorf("min signed per window cannot be negative: %s", v)
}
Expand Down Expand Up @@ -114,7 +116,9 @@ func validateSlashFractionDoubleSign(i interface{}) error {
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("double sign slash fraction cannot be nil: %s", v)
}

Check warning on line 121 in x/slashing/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/slashing/types/params.go#L119-L121

Added lines #L119 - L121 were not covered by tests
if v.IsNegative() {
return fmt.Errorf("double sign slash fraction cannot be negative: %s", v)
}
Expand All @@ -130,7 +134,9 @@ func validateSlashFractionDowntime(i interface{}) error {
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

if v.IsNil() {
return fmt.Errorf("downtime slash fraction cannot be nil: %s", v)
}

Check warning on line 139 in x/slashing/types/params.go

View check run for this annotation

Codecov / codecov/patch

x/slashing/types/params.go#L137-L139

Added lines #L137 - L139 were not covered by tests
if v.IsNegative() {
return fmt.Errorf("downtime slash fraction cannot be negative: %s", v)
}
Expand Down

0 comments on commit 923a858

Please sign in to comment.