Skip to content

Commit

Permalink
fix(x/authz,x/feegrant): check blocked address (#20102)
Browse files Browse the repository at this point in the history
(cherry picked from commit fcb9d84)

# Conflicts:
#	x/authz/expected_keepers.go
#	x/authz/keeper/keeper.go
#	x/authz/keeper/keeper_test.go
#	x/authz/module/module.go
#	x/feegrant/expected_keepers.go
#	x/feegrant/keeper/keeper.go
#	x/feegrant/keeper/keeper_test.go
#	x/feegrant/module/module.go
  • Loading branch information
julienrbrt authored and mergify[bot] committed Apr 21, 2024
1 parent 3d03c1b commit 2a865cb
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 0 deletions.
6 changes: 6 additions & 0 deletions x/authz/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ type AccountKeeper interface {

// BankKeeper defines the expected interface needed to retrieve account balances.
type BankKeeper interface {
<<<<<<< HEAD

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected '}', found '<<' (typecheck)

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected '}', found '<<'

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected ';', found '<<'

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 17 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expecting ~ term or type
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins

Check failure on line 18 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected ) after top level declaration

Check failure on line 18 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

syntax error: unexpected ) after top level declaration

Check failure on line 18 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected ) after top level declaration

Check failure on line 18 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ) after top level declaration

Check failure on line 18 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ) after top level declaration

Check failure on line 18 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ) after top level declaration

Check failure on line 18 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ) after top level declaration

Check failure on line 18 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ) after top level declaration

Check failure on line 18 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ) after top level declaration
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error
=======
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error
BlockedAddr(addr sdk.AccAddress) bool
>>>>>>> fcb9d84ed (fix(x/authz,x/feegrant): check blocked address (#20102))

Check failure on line 24 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

invalid character U+0023 '#' (typecheck)

Check failure on line 24 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal character U+0023 '#' (typecheck)

Check failure on line 24 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / golangci-lint

invalid character U+0023 '#') (typecheck)

Check failure on line 24 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'

Check failure on line 24 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 24 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 24 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 24 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 24 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 24 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'

Check failure on line 24 in x/authz/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'
}
15 changes: 15 additions & 0 deletions x/authz/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ import (
const gasCostPerIteration = uint64(20)

type Keeper struct {
<<<<<<< HEAD
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
router *baseapp.MsgServiceRouter
authKeeper authz.AccountKeeper
=======
storeService corestoretypes.KVStoreService
cdc codec.Codec
router baseapp.MessageRouter
authKeeper authz.AccountKeeper
bankKeeper authz.BankKeeper
>>>>>>> fcb9d84ed (fix(x/authz,x/feegrant): check blocked address (#20102))
}

// NewKeeper constructs a message authorization Keeper
Expand All @@ -40,6 +48,13 @@ func NewKeeper(storeKey storetypes.StoreKey, cdc codec.BinaryCodec, router *base
}
}

// Super ugly hack to not be breaking in v0.50 and v0.47
// DO NOT USE.
func (k Keeper) SetBankKeeper(bk authz.BankKeeper) Keeper {
k.bankKeeper = bk
return k
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", authz.ModuleName))
Expand Down
10 changes: 10 additions & 0 deletions x/authz/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,21 @@ func (s *TestSuite) SetupTest() {
// gomock initializations
ctrl := gomock.NewController(s.T())
s.accountKeeper = authztestutil.NewMockAccountKeeper(ctrl)
<<<<<<< HEAD

Check failure on line 66 in x/authz/keeper/keeper_test.go

View workflow job for this annotation

GitHub Actions / tests (01)

expected statement, found '<<'
=======
s.accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()

>>>>>>> fcb9d84ed (fix(x/authz,x/feegrant): check blocked address (#20102))
s.bankKeeper = authztestutil.NewMockBankKeeper(ctrl)
banktypes.RegisterInterfaces(s.encCfg.InterfaceRegistry)
banktypes.RegisterMsgServer(s.baseApp.MsgServiceRouter(), s.bankKeeper)
s.bankKeeper.EXPECT().BlockedAddr(gomock.Any()).Return(false).AnyTimes()

<<<<<<< HEAD
s.authzKeeper = authzkeeper.NewKeeper(key, s.encCfg.Codec, s.baseApp.MsgServiceRouter(), s.accountKeeper)
=======
s.authzKeeper = authzkeeper.NewKeeper(storeService, s.encCfg.Codec, s.baseApp.MsgServiceRouter(), s.accountKeeper).SetBankKeeper(s.bankKeeper)
>>>>>>> fcb9d84ed (fix(x/authz,x/feegrant): check blocked address (#20102))

queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, s.encCfg.InterfaceRegistry)
authz.RegisterQueryServer(queryHelper, s.authzKeeper)
Expand Down
4 changes: 4 additions & 0 deletions x/authz/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func (k Keeper) Grant(goCtx context.Context, msg *authz.MsgGrant) (*authz.MsgGra
// create the account if it is not in account state
granteeAcc := k.authKeeper.GetAccount(ctx, grantee)
if granteeAcc == nil {
if k.bankKeeper.BlockedAddr(grantee) {
return nil, sdkerrors.ErrUnauthorized.Wrapf("%s is not allowed to receive funds", grantee)
}

granteeAcc = k.authKeeper.NewAccountWithAddress(ctx, grantee)
k.authKeeper.SetAccount(ctx, granteeAcc)
}
Expand Down
5 changes: 5 additions & 0 deletions x/authz/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,13 @@ type AppModule struct {
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak authz.AccountKeeper, bk authz.BankKeeper, registry cdctypes.InterfaceRegistry) AppModule {
return AppModule{
<<<<<<< HEAD
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
=======
AppModuleBasic: AppModuleBasic{cdc: cdc, ac: ak.AddressCodec()},
keeper: keeper.SetBankKeeper(bk), // Super ugly hack to not be api breaking in v0.50 and v0.47
>>>>>>> fcb9d84ed (fix(x/authz,x/feegrant): check blocked address (#20102))
accountKeeper: ak,
bankKeeper: bk,
registry: registry,
Expand Down
14 changes: 14 additions & 0 deletions x/authz/testutil/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions x/feegrant/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ type AccountKeeper interface {

// BankKeeper defines the expected supply Keeper (noalias)
type BankKeeper interface {
<<<<<<< HEAD

Check failure on line 20 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected '}', found '<<'

Check failure on line 20 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected ';', found '<<'

Check failure on line 20 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 20 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 20 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 20 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expecting ~ term or type

Check failure on line 20 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expecting ~ term or type
SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins

Check failure on line 21 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected ) after top level declaration

Check failure on line 21 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ) after top level declaration

Check failure on line 21 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ) after top level declaration

Check failure on line 21 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ) after top level declaration
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
=======
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
BlockedAddr(addr sdk.AccAddress) bool
>>>>>>> fcb9d84ed (fix(x/authz,x/feegrant): check blocked address (#20102))

Check failure on line 27 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'

Check failure on line 27 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 27 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 27 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 27 in x/feegrant/expected_keepers.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'
}
18 changes: 18 additions & 0 deletions x/feegrant/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ import (
// Keeper manages state of all fee grants, as well as calculating approval.
// It must have a codec with all available allowances registered.
type Keeper struct {
<<<<<<< HEAD

Check failure on line 21 in x/feegrant/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected '}', found '<<'

Check failure on line 21 in x/feegrant/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected ';', found '<<'
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
authKeeper feegrant.AccountKeeper
=======
cdc codec.BinaryCodec
storeService store.KVStoreService
authKeeper feegrant.AccountKeeper
bankKeeper feegrant.BankKeeper
>>>>>>> fcb9d84ed (fix(x/authz,x/feegrant): check blocked address (#20102))

Check failure on line 30 in x/feegrant/keeper/keeper.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'
}

var _ ante.FeegrantKeeper = &Keeper{}
Expand All @@ -34,6 +41,13 @@ func NewKeeper(cdc codec.BinaryCodec, storeKey storetypes.StoreKey, ak feegrant.
}
}

// Super ugly hack to not be breaking in v0.50 and v0.47
// DO NOT USE.
func (k Keeper) SetBankKeeper(bk feegrant.BankKeeper) Keeper {
k.bankKeeper = bk
return k
}

// Logger returns a module-specific logger.
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", fmt.Sprintf("x/%s", feegrant.ModuleName))
Expand All @@ -44,6 +58,10 @@ func (k Keeper) GrantAllowance(ctx sdk.Context, granter, grantee sdk.AccAddress,
// create the account if it is not in account state
granteeAcc := k.authKeeper.GetAccount(ctx, grantee)
if granteeAcc == nil {
if k.bankKeeper.BlockedAddr(grantee) {
return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", grantee)
}

granteeAcc = k.authKeeper.NewAccountWithAddress(ctx, grantee)
k.authKeeper.SetAccount(ctx, granteeAcc)
}
Expand Down
12 changes: 12 additions & 0 deletions x/feegrant/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type KeeperTestSuite struct {
atom sdk.Coins
feegrantKeeper keeper.Keeper
accountKeeper *feegranttestutil.MockAccountKeeper
bankKeeper *feegranttestutil.MockBankKeeper
}

func TestKeeperTestSuite(t *testing.T) {
Expand All @@ -41,12 +42,23 @@ func (suite *KeeperTestSuite) SetupTest() {
// setup gomock and initialize some globally expected executions
ctrl := gomock.NewController(suite.T())
suite.accountKeeper = feegranttestutil.NewMockAccountKeeper(ctrl)
<<<<<<< HEAD

Check failure on line 45 in x/feegrant/keeper/keeper_test.go

View workflow job for this annotation

GitHub Actions / tests (02)

expected statement, found '<<'
suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[0]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[0])).AnyTimes()
suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[1]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[1])).AnyTimes()
suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[2]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[2])).AnyTimes()
suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[3]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[3])).AnyTimes()

suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, key, suite.accountKeeper)
=======
for i := 0; i < len(suite.addrs); i++ {
suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[i]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[i])).AnyTimes()
}
suite.accountKeeper.EXPECT().AddressCodec().Return(codecaddress.NewBech32Codec("cosmos")).AnyTimes()
suite.bankKeeper = feegranttestutil.NewMockBankKeeper(ctrl)
suite.bankKeeper.EXPECT().BlockedAddr(gomock.Any()).Return(false).AnyTimes()

suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, runtime.NewKVStoreService(key), suite.accountKeeper).SetBankKeeper(suite.bankKeeper)
>>>>>>> fcb9d84ed (fix(x/authz,x/feegrant): check blocked address (#20102))
suite.ctx = testCtx.Ctx
suite.msgSrvr = keeper.NewMsgServerImpl(suite.feegrantKeeper)
suite.atom = sdk.NewCoins(sdk.NewCoin("atom", sdk.NewInt(555)))
Expand Down
5 changes: 5 additions & 0 deletions x/feegrant/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,13 @@ type AppModule struct {
// NewAppModule creates a new AppModule object
func NewAppModule(cdc codec.Codec, ak feegrant.AccountKeeper, bk feegrant.BankKeeper, keeper keeper.Keeper, registry cdctypes.InterfaceRegistry) AppModule {
return AppModule{
<<<<<<< HEAD
AppModuleBasic: AppModuleBasic{cdc: cdc},
keeper: keeper,
=======
AppModuleBasic: AppModuleBasic{cdc: cdc, ac: ak.AddressCodec()},
keeper: keeper.SetBankKeeper(bk),
>>>>>>> fcb9d84ed (fix(x/authz,x/feegrant): check blocked address (#20102))
accountKeeper: ak,
bankKeeper: bk,
registry: registry,
Expand Down
14 changes: 14 additions & 0 deletions x/feegrant/testutil/expected_keepers_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2a865cb

Please sign in to comment.