Skip to content

Commit 43bb358

Browse files
committed
patch-1
1 parent e4a2bfb commit 43bb358

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

x/wasm/keeper/keeper.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,18 @@ func (k Keeper) importCode(ctx sdk.Context, codeID uint64, codeInfo types.CodeIn
266266
return nil
267267
}
268268

269+
func (k Keeper) checkIfFundsAreFromDisallowedModule(ctx sdk.Context, ak types.AccountKeeper, runAs sdk.AccAddress) error {
270+
// Runs on Governance Instantiate & Execute after we check for funds
271+
// Without this check, invariance and halt can be caused from the distribution module
272+
// via a governance proposal if this was allowed.
273+
moduleName := "distribution"
274+
if runAs.String() == ak.GetModuleAddress(moduleName).String() {
275+
return fmt.Errorf("cannot send funds from %s module account", moduleName)
276+
}
277+
278+
return nil
279+
}
280+
269281
func (k Keeper) instantiate(
270282
ctx sdk.Context,
271283
codeID uint64,
@@ -332,6 +344,10 @@ func (k Keeper) instantiate(
332344
}
333345
// deposit initial contract funds
334346
if !deposit.IsZero() {
347+
if err := k.checkIfFundsAreFromDisallowedModule(ctx, k.accountKeeper, creator); err != nil {
348+
return nil, nil, err
349+
}
350+
335351
if err := k.bank.TransferCoins(ctx, creator, contractAddress, deposit); err != nil {
336352
return nil, nil, err
337353
}
@@ -408,6 +424,10 @@ func (k Keeper) execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller
408424

409425
// add more funds
410426
if !coins.IsZero() {
427+
if err := k.checkIfFundsAreFromDisallowedModule(ctx, k.accountKeeper, caller); err != nil {
428+
return nil, err
429+
}
430+
411431
if err := k.bank.TransferCoins(ctx, caller, contractAddress, coins); err != nil {
412432
return nil, err
413433
}

x/wasm/types/expected_keepers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ type AccountKeeper interface {
4343
GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
4444
// Set an account in the store.
4545
SetAccount(ctx sdk.Context, acc authtypes.AccountI)
46+
// Gets an account from the module's human readable name.
47+
GetModuleAddress(moduleName string) sdk.AccAddress
4648
}
4749

4850
// DistributionKeeper defines a subset of methods implemented by the cosmos-sdk distribution keeper

0 commit comments

Comments
 (0)