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

Nibiru EVM module burns only post-fee amount when converting bank coins back to fee-on-transfer ERC20s, leaving unbacked bank coins in circulation.

- Payout: Audit contest
- Severity: medium
- Program: Nibiru
- Found by: 0x41
- Disclosed: 2025-02-24
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-11-nibiru-findings/issues/48
- Library page: https://bugbountylibrary.com/r/c4%3A2024-11-nibiru%3AM-02
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:medium tech:evm technique:source-review vuln:accounting-error vuln:business-logic

**Target:** EVM module FunToken bank<->ERC20 conversion (msg_server.go, funtoken.go)
**Root cause:** convertCoinToEvmBornERC20 burns only actualSentAmount after the ERC20 transfer fee, but the inbound sendToBank already minted bank coins net of fees, so fees are applied twice and the burn under-counts.
**Steps:**
1. Deploy/use a fee-on-transfer ERC20 registered as a FunToken.
2. Call sendToBank with 100 tokens: 95 bank coins minted (fee accounted).
3. Call convertCoinToEvmBornERC20 with 95 bank coins: transfer yields ~90.25 ERC20 to recipient.
4. Observe only 90.25 bank coins burned, leaving 4.75 unbacked bank coins in the module.
**How found:** Code review comparing the two conversion paths: sendToBank uses gotAmount (post-fee) while convertCoinToEvmBornERC20 burns actualSentAmount, contradicting the stated 1:1 supply invariant comment.
**Exploitation:** Repeated round-trip conversions accumulate unbacked bank coins at the EVM module address; per maintainer these are inaccessible, so impact is supply-accounting inflation rather than direct theft.
**Insight:** When a protocol has paired mint/burn paths for wrapped assets, diff how each side computes amounts for fee-on-transfer tokens; asymmetric use of pre- vs post-fee amounts signals invariant breakage.

## Proof of concept (copied exactly from the original report)

**convertCoinToEvmBornERC20 burns only post-fee amount**

```
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))
```

**sendToBank mints only 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))
```

