Skip to content

Commit fcb9d84

Browse files
authored
fix(x/authz,x/feegrant): check blocked address (#20102)
1 parent 0a682f7 commit fcb9d84

File tree

11 files changed

+62
-6
lines changed

11 files changed

+62
-6
lines changed

x/authz/expected_keepers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ type AccountKeeper interface {
2020
type BankKeeper interface {
2121
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
2222
IsSendEnabledCoins(ctx context.Context, coins ...sdk.Coin) error
23+
BlockedAddr(addr sdk.AccAddress) bool
2324
}

x/authz/keeper/keeper.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Keeper struct {
3434
cdc codec.Codec
3535
router baseapp.MessageRouter
3636
authKeeper authz.AccountKeeper
37+
bankKeeper authz.BankKeeper
3738
}
3839

3940
// NewKeeper constructs a message authorization Keeper
@@ -46,6 +47,13 @@ func NewKeeper(storeService corestoretypes.KVStoreService, cdc codec.Codec, rout
4647
}
4748
}
4849

50+
// Super ugly hack to not be breaking in v0.50 and v0.47
51+
// DO NOT USE.
52+
func (k Keeper) SetBankKeeper(bk authz.BankKeeper) Keeper {
53+
k.bankKeeper = bk
54+
return k
55+
}
56+
4957
// Logger returns a module-specific logger.
5058
func (k Keeper) Logger(ctx context.Context) log.Logger {
5159
sdkCtx := sdk.UnwrapSDKContext(ctx)

x/authz/keeper/keeper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ func (s *TestSuite) SetupTest() {
6868
// gomock initializations
6969
ctrl := gomock.NewController(s.T())
7070
s.accountKeeper = authztestutil.NewMockAccountKeeper(ctrl)
71-
7271
s.accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes()
7372

7473
s.bankKeeper = authztestutil.NewMockBankKeeper(ctrl)
7574
banktypes.RegisterInterfaces(s.encCfg.InterfaceRegistry)
7675
banktypes.RegisterMsgServer(s.baseApp.MsgServiceRouter(), s.bankKeeper)
76+
s.bankKeeper.EXPECT().BlockedAddr(gomock.Any()).Return(false).AnyTimes()
7777

78-
s.authzKeeper = authzkeeper.NewKeeper(storeService, s.encCfg.Codec, s.baseApp.MsgServiceRouter(), s.accountKeeper)
78+
s.authzKeeper = authzkeeper.NewKeeper(storeService, s.encCfg.Codec, s.baseApp.MsgServiceRouter(), s.accountKeeper).SetBankKeeper(s.bankKeeper)
7979

8080
queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, s.encCfg.InterfaceRegistry)
8181
authz.RegisterQueryServer(queryHelper, s.authzKeeper)

x/authz/keeper/msg_server.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func (k Keeper) Grant(goCtx context.Context, msg *authz.MsgGrant) (*authz.MsgGra
3838
ctx := sdk.UnwrapSDKContext(goCtx)
3939
granteeAcc := k.authKeeper.GetAccount(ctx, grantee)
4040
if granteeAcc == nil {
41+
if k.bankKeeper.BlockedAddr(grantee) {
42+
return nil, sdkerrors.ErrUnauthorized.Wrapf("%s is not allowed to receive funds", grantee)
43+
}
44+
4145
granteeAcc = k.authKeeper.NewAccountWithAddress(ctx, grantee)
4246
k.authKeeper.SetAccount(ctx, granteeAcc)
4347
}

x/authz/module/module.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ type AppModule struct {
113113
func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak authz.AccountKeeper, bk authz.BankKeeper, registry cdctypes.InterfaceRegistry) AppModule {
114114
return AppModule{
115115
AppModuleBasic: AppModuleBasic{cdc: cdc, ac: ak.AddressCodec()},
116-
keeper: keeper,
116+
keeper: keeper.SetBankKeeper(bk), // Super ugly hack to not be api breaking in v0.50 and v0.47
117117
accountKeeper: ak,
118118
bankKeeper: bk,
119119
registry: registry,

x/authz/testutil/expected_keepers_mocks.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x/feegrant/expected_keepers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ type AccountKeeper interface {
2424
type BankKeeper interface {
2525
SpendableCoins(ctx context.Context, addr sdk.AccAddress) sdk.Coins
2626
SendCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
27+
BlockedAddr(addr sdk.AccAddress) bool
2728
}

x/feegrant/keeper/keeper.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Keeper struct {
2424
cdc codec.BinaryCodec
2525
storeService store.KVStoreService
2626
authKeeper feegrant.AccountKeeper
27+
bankKeeper feegrant.BankKeeper
2728
}
2829

2930
var _ ante.FeegrantKeeper = &Keeper{}
@@ -37,6 +38,13 @@ func NewKeeper(cdc codec.BinaryCodec, storeService store.KVStoreService, ak feeg
3738
}
3839
}
3940

41+
// Super ugly hack to not be breaking in v0.50 and v0.47
42+
// DO NOT USE.
43+
func (k Keeper) SetBankKeeper(bk feegrant.BankKeeper) Keeper {
44+
k.bankKeeper = bk
45+
return k
46+
}
47+
4048
// Logger returns a module-specific logger.
4149
func (k Keeper) Logger(ctx sdk.Context) log.Logger {
4250
return ctx.Logger().With("module", fmt.Sprintf("x/%s", feegrant.ModuleName))
@@ -52,6 +60,10 @@ func (k Keeper) GrantAllowance(ctx context.Context, granter, grantee sdk.AccAddr
5260
// create the account if it is not in account state
5361
granteeAcc := k.authKeeper.GetAccount(ctx, grantee)
5462
if granteeAcc == nil {
63+
if k.bankKeeper.BlockedAddr(grantee) {
64+
return errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "%s is not allowed to receive funds", grantee)
65+
}
66+
5567
granteeAcc = k.authKeeper.NewAccountWithAddress(ctx, grantee)
5668
k.authKeeper.SetAccount(ctx, granteeAcc)
5769
}

x/feegrant/keeper/keeper_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type KeeperTestSuite struct {
3131
atom sdk.Coins
3232
feegrantKeeper keeper.Keeper
3333
accountKeeper *feegranttestutil.MockAccountKeeper
34+
bankKeeper *feegranttestutil.MockBankKeeper
3435
}
3536

3637
func TestKeeperTestSuite(t *testing.T) {
@@ -49,10 +50,11 @@ func (suite *KeeperTestSuite) SetupTest() {
4950
for i := 0; i < len(suite.addrs); i++ {
5051
suite.accountKeeper.EXPECT().GetAccount(gomock.Any(), suite.addrs[i]).Return(authtypes.NewBaseAccountWithAddress(suite.addrs[i])).AnyTimes()
5152
}
52-
5353
suite.accountKeeper.EXPECT().AddressCodec().Return(codecaddress.NewBech32Codec("cosmos")).AnyTimes()
54+
suite.bankKeeper = feegranttestutil.NewMockBankKeeper(ctrl)
55+
suite.bankKeeper.EXPECT().BlockedAddr(gomock.Any()).Return(false).AnyTimes()
5456

55-
suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, runtime.NewKVStoreService(key), suite.accountKeeper)
57+
suite.feegrantKeeper = keeper.NewKeeper(encCfg.Codec, runtime.NewKVStoreService(key), suite.accountKeeper).SetBankKeeper(suite.bankKeeper)
5658
suite.ctx = testCtx.Ctx
5759
suite.msgSrvr = keeper.NewMsgServerImpl(suite.feegrantKeeper)
5860
suite.atom = sdk.NewCoins(sdk.NewCoin("atom", sdkmath.NewInt(555)))

x/feegrant/module/module.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ type AppModule struct {
120120
func NewAppModule(cdc codec.Codec, ak feegrant.AccountKeeper, bk feegrant.BankKeeper, keeper keeper.Keeper, registry cdctypes.InterfaceRegistry) AppModule {
121121
return AppModule{
122122
AppModuleBasic: AppModuleBasic{cdc: cdc, ac: ak.AddressCodec()},
123-
keeper: keeper,
123+
keeper: keeper.SetBankKeeper(bk),
124124
accountKeeper: ak,
125125
bankKeeper: bk,
126126
registry: registry,

0 commit comments

Comments
 (0)