Skip to content

Commit

Permalink
fix(x/auth): ensure nil .BaseAccounts are reported in ModuleAccount.V…
Browse files Browse the repository at this point in the history
…alidate (backport cosmos#16554) (cosmos#16570)

Co-authored-by: Emmanuel T Odeke <emmanuel@orijtech.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
  • Loading branch information
3 people authored and GAtom22 committed Jul 12, 2023
1 parent 62f2e31 commit 7364088
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

* (deps) [#16553](https://github.com/cosmos/cosmos-sdk/pull/16553) Bump CometBFT to [v0.34.29](https://github.com/cometbft/cometbft/blob/v0.34.29/CHANGELOG.md#v03429).

### Bug Fixes

* (x/auth) [#16554](https://github.com/cosmos/cosmos-sdk/pull/16554) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking.

## [v0.46.13-ledger.3](https://github.com/evmos/cosmos-sdk/releases/tag/v0.46.13-ledger.3) - 2023-06-08

Expand Down
4 changes: 4 additions & 0 deletions x/auth/types/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ func (ma ModuleAccount) Validate() error {
return errors.New("module account name cannot be blank")
}

if ma.BaseAccount == nil {
return errors.New("uninitialized ModuleAccount: BaseAccount is nil")
}

if ma.Address != sdk.AccAddress(crypto.AddressHash([]byte(ma.Name))).String() {
return fmt.Errorf("address %s cannot be derived from the module name '%s'", ma.Address, ma.Name)
}
Expand Down
5 changes: 5 additions & 0 deletions x/auth/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,8 @@ func TestGenesisAccountsContains(t *testing.T) {
genAccounts = append(genAccounts, acc)
require.True(t, genAccounts.Contains(acc.GetAddress()))
}

func TestModuleAccountValidateNilBaseAccount(t *testing.T) {
ma := &types.ModuleAccount{Name: "foo"}
_ = ma.Validate()
}

0 comments on commit 7364088

Please sign in to comment.