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(x/distribution): add nil check in Params.ValidateBasic (backport #17236) #17241

Merged
merged 1 commit into from
Aug 1, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (baseapp) [#17159](https://github.com/cosmos/cosmos-sdk/pull/17159) Validators can propose blocks that exceed the gas limit.
* (x/group) [#17146](https://github.com/cosmos/cosmos-sdk/pull/17146) Rename x/group legacy ORM package's error codespace from "orm" to "legacy_orm", preventing collisions with ORM's error codespace "orm".
* (x/bank) [#17170](https://github.com/cosmos/cosmos-sdk/pull/17170) Avoid empty spendable error message on send coins.
* (x/distribution) [#17236](https://github.com/cosmos/cosmos-sdk/pull/17236) Using "validateCommunityTax" in "Params.ValidateBasic", preventing panic when field "CommunityTax" is nil.

### API Breaking Changes

Expand Down
18 changes: 16 additions & 2 deletions tests/integration/distribution/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,20 @@ func TestMsgUpdateParams(t *testing.T) {
expErr: true,
expErrMsg: "invalid authority",
},
{
name: "community tax is nil",
msg: &distrtypes.MsgUpdateParams{
Authority: f.distrKeeper.GetAuthority(),
Params: distrtypes.Params{
CommunityTax: math.LegacyDec{},
WithdrawAddrEnabled: withdrawAddrEnabled,
BaseProposerReward: math.LegacyZeroDec(),
BonusProposerReward: math.LegacyZeroDec(),
},
},
expErr: true,
expErrMsg: "community tax must be not nil",
},
{
name: "community tax > 1",
msg: &distrtypes.MsgUpdateParams{
Expand All @@ -693,7 +707,7 @@ func TestMsgUpdateParams(t *testing.T) {
},
},
expErr: true,
expErrMsg: "community tax should be non-negative and less than one",
expErrMsg: "community tax too large: 2.000000000000000000",
},
{
name: "negative community tax",
Expand All @@ -707,7 +721,7 @@ func TestMsgUpdateParams(t *testing.T) {
},
},
expErr: true,
expErrMsg: "community tax should be non-negative and less than one",
expErrMsg: "community tax must be positive: -0.200000000000000000",
},
{
name: "base proposer reward set",
Expand Down
8 changes: 1 addition & 7 deletions x/distribution/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ func DefaultParams() Params {

// ValidateBasic performs basic validation on distribution parameters.
func (p Params) ValidateBasic() error {
if p.CommunityTax.IsNegative() || p.CommunityTax.GT(math.LegacyOneDec()) {
return fmt.Errorf(
"community tax should be non-negative and less than one: %s", p.CommunityTax,
)
}

return nil
return validateCommunityTax(p.CommunityTax)
}

func validateCommunityTax(i interface{}) error {
Expand Down
1 change: 1 addition & 0 deletions x/distribution/types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestParams_ValidateBasic(t *testing.T) {
{"negative bonus proposer reward (must not matter)", fields{toDec("0.1"), toDec("0"), toDec("-0.1"), false}, false},
{"total sum greater than 1 (must not matter)", fields{toDec("0.2"), toDec("0.5"), toDec("0.4"), false}, false},
{"community tax greater than 1", fields{toDec("1.1"), toDec("0"), toDec("0"), false}, true},
{"community tax nil", fields{sdkmath.LegacyDec{}, toDec("0"), toDec("0"), false}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down