Intro

<aside> 🐧

This post was written when MsgForceTransfer and MsgSetBeforeSendHook were vulnerable in the previous x/tokenfactory module versions.

</aside>

The x/tokenfactory module allows users to create their own native tokens. These tokens come with powerful features, such as MsgForceTransfer and MsgSetBeforeSendHook.

What if the token creator is malicious and decides to use these features against the chain itself? 🤔

In the x/gov module, the RefundAndDeleteDeposits function transfers the deposit from the x/gov module address to the depositor. If an error occurs when transferring the funds, a panic will be triggered, causing a chain halt as this function is called within the EndBlocker.

If an attacker deposits the malicious tokens into a proposal and calls MsgForceTransfer to reduce the x/gov module balance (or disallow the funds from being transferred out from the x/gov module account with MsgSetBeforeSendHook), the chain will be halted.

The attack vectors would be:

Example 1: MsgForceTransfer in the x/gov module

MsgSubmitProposal and MsgDeposit allow users to send funds. These funds are not restricted to the minimum deposit tokens (i.e., params.ExpeditedMinDeposit or params.MinDeposit) by the x/gov module (update: the latest version of Cosmos SDK restricts them now). Users can send unrelated funds to the module, which will eventually be refunded or burnt in the EndBlocker.

An attacker can send malicious native tokens created in x/tokenfactory to the x/gov module. When the EndBlocker is executed, the funds are either refunded (via RefundAndDeleteDeposits) or burnt (via DeleteAndBurnDeposits), depending on the params.BurnProposalDepositPrevote configuration. In both cases, the attacker can cause the ABCI methods to panic due to an insufficient funds error, ultimately halting the chain.

Scenario when the deposit is refunded (params.BurnProposalDepositPrevote is false)

  1. Call MsgCreateDenom in the x/tokenfactory module.
  2. Call MsgMint to mint some tokens.
  3. Call MsgSubmitProposal to create a dummy proposal and send the minted tokens.
  4. Call MsgForceTransfer to reduce the x/gov module’s balance by transferring the funds to other accounts.