@@ -266,6 +266,18 @@ func (k Keeper) importCode(ctx sdk.Context, codeID uint64, codeInfo types.CodeIn
266
266
return nil
267
267
}
268
268
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
+
269
281
func (k Keeper ) instantiate (
270
282
ctx sdk.Context ,
271
283
codeID uint64 ,
@@ -332,6 +344,10 @@ func (k Keeper) instantiate(
332
344
}
333
345
// deposit initial contract funds
334
346
if ! deposit .IsZero () {
347
+ if err := k .checkIfFundsAreFromDisallowedModule (ctx , k .accountKeeper , creator ); err != nil {
348
+ return nil , nil , err
349
+ }
350
+
335
351
if err := k .bank .TransferCoins (ctx , creator , contractAddress , deposit ); err != nil {
336
352
return nil , nil , err
337
353
}
@@ -408,6 +424,10 @@ func (k Keeper) execute(ctx sdk.Context, contractAddress sdk.AccAddress, caller
408
424
409
425
// add more funds
410
426
if ! coins .IsZero () {
427
+ if err := k .checkIfFundsAreFromDisallowedModule (ctx , k .accountKeeper , caller ); err != nil {
428
+ return nil , err
429
+ }
430
+
411
431
if err := k .bank .TransferCoins (ctx , caller , contractAddress , coins ); err != nil {
412
432
return nil , err
413
433
}
0 commit comments