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: update param validation to fail on nil dec (backport #1323) #1325

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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))
0Tech marked this conversation as resolved.
Show resolved Hide resolved

### 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 @@
"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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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
Loading