Skip to content
Business logic Audit finding Intermediate

Double fee application breaks supply invariant for fee-on-transfer ERC20s

The EVM module incorrectly handles fee-on-transfer tokens when converting bank coins back to ERC20s, burning only the amount after fees instead of the full input. This leaves unbacked bank coins in circulation, breaking the 1:1 supply invariant between ERC20 tokens and their bank coin representations.

0x41 Follow

Originally disclosed on Code4rena

Submitted by 0x41

The EVM module incorrectly handles fee-on-transfer tokens when converting bank coins back to ERC20s, resulting in unbacked bank coins remaining in circulation. This breaks the intended 1:1 supply tracking invariant between ERC20 tokens and their bank coin representations.

When converting from ERC20 to bank coins via sendToBank, the code correctly accounts for transfer fees by only minting bank coins equal to the amount actually received. However, when converting these bank coins back to ERC20s via convertCoinToEvmBornERC20, the code:

  1. Takes in X bank coins from the user.
  2. Tries to transfer X ERC20 tokens.
  3. Due to fees, only Y tokens are received (Y < X).
  4. Only burns Y bank coins.

This creates a discrepancy since the original conversion already accounted for fees. The transfer fees are effectively applied twice:

  1. First fee: 100 ERC20 -> 95 bank coins (correct).
  2. Second fee: 95 bank coins -> ~90.25 ERC20 (and only burn 90.25 bank coins).

This leaves 4.75 unbacked bank coins in circulation (95 - 90.25), as the code only burns what was actually transferred in the second conversion.

The impact is monetary - it creates unbacked bank coins that can be used in the rest of the system but don’t have corresponding ERC20 tokens backing them in the EVM module’s account. Over time, this could lead to significant supply inflation of the bank coin representation.

Proof of Concept

The first conversion correctly handles fees in funtoken.go:

// First conversion correctly uses actual received amount
gotAmount, transferResp, err := p.evmKeeper.ERC20().Transfer(erc20, caller, transferTo, amount, ctx)
if err != nil {
    return nil, fmt.Errorf("error in ERC20.transfer from caller to EVM account: %w", err)
}
coinToSend := sdk.NewCoin(funtoken.BankDenom, math.NewIntFromBigInt(gotAmount))

funtoken.go#L162-L170

But when converting back in msg_server.go, it incorrectly applies fees again:

actualSentAmount, _, err := k.ERC20().Transfer(
    erc20Addr,
    evm.EVM_MODULE_ADDRESS,
    recipient,
    coin.Amount.BigInt(),
    ctx,
)
if err != nil {
    return nil, errors.Wrap(err, "failed to transfer ERC-20 tokens")
}

// Only burns the amount after fees, even though fees were already accounted for
burnCoin := sdk.NewCoin(coin.Denom, sdk.NewIntFromBigInt(actualSentAmount))
err = k.Bank.BurnCoins(ctx, evm.ModuleName, sdk.NewCoins(burnCoin))

msg_server.go#L597-L613

The code explicitly aims to maintain a supply invariant:

// to preserve an invariant on the sum of the FunToken's bank and ERC20 supply,
// we burn the coins here in the BC → ERC20 conversion.

msg_server.go#L603

Recommended mitigation steps

When converting bank coins back to ERC20s in convertCoinToEvmBornERC20, the code should burn the full input amount of bank coins, not just the amount after fees. This ensures fees are only applied once in the entire conversion cycle.

// In msg_server.go convertCoinToEvmBornERC20:
actualSentAmount, _, err := k.ERC20().Transfer(
    erc20Addr,
    evm.EVM_MODULE_ADDRESS,
    recipient,
    coin.Amount.BigInt(),
    ctx,
)
if err != nil {
    return nil, errors.Wrap(err, "failed to transfer ERC-20 tokens")
}

// Burn the full input amount, not the amount after fees
err = k.Bank.BurnCoins(ctx, evm.ModuleName, sdk.NewCoins(coin))

This maintains the supply invariant since:

  1. First conversion: 100 ERC20 -> 95 bank coins (after 5% fee).
  2. Second conversion: 95 bank coins -> ~90.25 ERC20 (after another 5% fee), burn full 95 bank coins.

The documentation should also be updated to explicitly describe how fee-on-transfer tokens are handled and that fees will apply on both conversions.

k-yang (Nibiru) confirmed and commented:

I don’t think it has a monetary impact on the financial ecosystem though because those unburned coins that accumulate at the EVM module address are inaccessible. It’s the logical equivalent of being burned, except that it still shows up in total supply calculations. We’ll fix it for accounting purposes, but it’s not an infinite mint bug where the attacker can actually use the funds.

Nibiru mitigated:

PR-2139 - Ensure bank coins are properly burned after converting back to ERC20.

Status: Mitigation confirmed.


The original report as published on Code4rena, by 0x41. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code burns only the amount actually received after transfer fees, even though the initial conversion already accounted for fees, effectively applying fees twice and leaving unbacked bank coins.

Impact

This creates unbacked bank coins that can be used in the rest of the system but lack corresponding ERC20 backing; however, the unburned coins accumulate at the EVM module address and are inaccessible, so there is no direct monetary gain for an attacker.

What the attacker needed

Fee-on-transfer ERC20 token; use of sendToBank and convertCoinToEvmBornERC20

The fix

The code should burn the full input amount of bank coins, not just the amount after fees, to maintain the supply invariant.

How it was found

  1. Convert ERC20 tokens to bank coins via sendToBank, which correctly mints bank coins equal to the amount received after fees.
  2. Convert those bank coins back to ERC20s via convertCoinToEvmBornERC20, which transfers ERC20 tokens and burns only the amount after fees.
  3. Observe that the full input bank coins are not burned, leaving unbacked bank coins in circulation.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Some tokens take a small fee when transferred, so the receiver gets less than the sender sent. This system converts between two representations of the same token: an ERC20 token and a 'bank coin'. When converting back, it only destroyed the smaller amount after the fee, leaving extra bank coins that no longer have ERC20 tokens backing them.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by 0x41

View all

5 more disclosed reports, best first.

More from Nibiru

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.