Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Keeper interface {
CreditVirtualAccounts(ctx context.Context) error
SendCoinsFromVirtual(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error
SendCoinsToVirtual(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error
SetBalance(ctx context.Context, addr sdk.AccAddress, balance sdk.Coin) error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels like a dangerous method to include in the base interface

i'm (fairly) certain all of these methods here are fool proof, but SetBalance is not. for example, Mint/BurnCoins handles updating the supply for you. SetBalance can be misused and put the state out of whack.

would it make more sense to have an UnsafeBank or SudoBank-esque interface?


DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error
UndelegateCoins(ctx context.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error
Expand Down Expand Up @@ -155,7 +156,7 @@ func (k BaseKeeper) DelegateCoins(ctx context.Context, delegatorAddr, moduleAccA
}

balances = balances.Add(balance)
err := k.setBalance(ctx, delegatorAddr, balance.Sub(coin))
err := k.SetBalance(ctx, delegatorAddr, balance.Sub(coin))
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions x/bank/keeper/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (k BaseSendKeeper) subUnlockedCoins(ctx context.Context, addr sdk.AccAddres

newBalance := balance.Sub(coin)

if err := k.setBalance(ctx, addr, newBalance); err != nil {
if err := k.SetBalance(ctx, addr, newBalance); err != nil {
return err
}
}
Expand All @@ -353,7 +353,7 @@ func (k BaseSendKeeper) addCoins(ctx context.Context, addr sdk.AccAddress, amt s
balance := k.GetBalance(ctx, addr, coin.Denom)
newBalance := balance.Add(coin)

err := k.setBalance(ctx, addr, newBalance)
err := k.SetBalance(ctx, addr, newBalance)
if err != nil {
return err
}
Expand All @@ -368,8 +368,8 @@ func (k BaseSendKeeper) addCoins(ctx context.Context, addr sdk.AccAddress, amt s
return nil
}

// setBalance sets the coin balance for an account by address.
func (k BaseSendKeeper) setBalance(ctx context.Context, addr sdk.AccAddress, balance sdk.Coin) error {
// SetBalance sets the coin balance for an account by address.
func (k BaseSendKeeper) SetBalance(ctx context.Context, addr sdk.AccAddress, balance sdk.Coin) error {
Copy link
Collaborator

@yihuang yihuang Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare SetBalance with SendCoins or Mint/Burn:

  • SetBalance don't check the LockedCoins of vesting accounts.
  • SetBalance don't update supply, it assumes the caller will keep the supply unchanged.
  • SetBalance don't emit events.

Especially the first one, it seems can become a security vulnerability easily if the caller is not careful.

if !balance.IsValid() {
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, balance.String())
}
Expand Down
14 changes: 14 additions & 0 deletions x/gov/testutil/expected_keepers_mocks.go

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

Loading