Skip to content
Business logic Audit finding Intermediate

Inconsistent fee denomination handling in transaction validation and building

The Nibiru EVM module incorrectly handled fee denominations during transaction validation and building, using wei amounts directly as unibi without conversion. This could cause fees to be undervalued by a factor of 10^12, potentially allowing users to pay far fewer fees than intended.

0x41 Follow

Originally disclosed on Code4rena

Submitted by 0x41

The Nibiru EVM module incorrectly handles fee denominations during transaction validation and building, failing to convert wei amounts to the native unibi denomination. This can lead to significant discrepancies in fee calculations and potentially allow users to pay far fewer fees than intended.

The issue occurs in two locations:

  1. Transaction validation in evmante_validate_basic.go.
  2. Transaction building in msg.go.

In both cases, fees that are calculated in wei (1e18 units) are directly used with evm.EVMBankDenom (unibi), without converting from wei to unibi (1e6 units). This causes an undervaluation of fees by a factor of 10^12, as the system expects fees in unibi but receives them in wei.

Proof of Concept

  1. In evmante_validate_basic.go, the fee validation directly uses the wei amount:
txFee = txFee.Add(
    sdk.Coin{
        Denom:  evm.EVMBankDenom,
        Amount: sdkmath.NewIntFromBigInt(txData.Fee()), // Fee() returns wei amount
    },
)

evmante_validate_basic.go#L128

  1. Similarly in msg.go, when building a transaction:
feeAmt := sdkmath.NewIntFromBigInt(txData.Fee())
if feeAmt.Sign() > 0 {
    fees = append(fees, sdk.NewCoin(evmDenom, feeAmt)) // Fee() returns wei amount
}

msg.go#L367

The Fee() function in tx_data_legacy.go calculates fees in wei:

func (tx LegacyTx) Fee() *big.Int {
    return priceTimesGas(tx.GetGasPrice(), tx.GetGas())
}

To demonstrate the impact:

  1. A transaction with a gas price of 1 wei and gas limit of 21000 would result in a fee of 21000 wei.
  2. This should be converted to 0.000021 unibi (21000 / 10^12).
  3. However, the current code would set it as 21000 unibi, which is incorrect by a factor of 10^12.

Recommended mitigation steps

  1. In evmante_validate_basic.go, modify the fee validation to convert from wei to unibi:
txFee = txFee.Add(
    sdk.Coin{
        Denom:  evm.EVMBankDenom,
        Amount: sdkmath.NewIntFromBigInt(evm.WeiToNative(txData.Fee())),
    },
)
  1. In msg.go, update the fee conversion in BuildTx:
feeAmt := sdkmath.NewIntFromBigInt(evm.WeiToNative(txData.Fee()))
if feeAmt.Sign() > 0 {
    fees = append(fees, sdk.NewCoin(evmDenom, feeAmt))
}

k-yang (Nibiru) confirmed

Unique-Divine (Nibiru) commented:

Note that a gas price of 1 wei isn’t possible. The smallest unit of funds that can be transferred is 10^{12} wei, or 1 unibi, meaning the 21000unibi value for fees paid what’s wanted here.

Digging into this now to see which parts are correct or incorrect between msg.go and evmante_validate_basic.go.

Nibiru mitigated:

PR-2157 - Fixed unit inconsistency related to AuthInfo.Fee and txData.Fee.

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 failed to convert fee amounts from wei to unibi before using them in transaction validation and building.

Impact

This could lead to significant discrepancies in fee calculations and potentially allow users to pay far fewer fees than intended, though a developer noted that a gas price of 1 wei is not possible.

What the attacker needed

None

The fix

The issue was fixed by converting wei to unibi using a conversion function in both locations.

How it was found

  1. A transaction is created with a gas price and gas limit, resulting in a fee in wei.
  2. The fee is used directly as unibi in transaction validation and building without conversion.
  3. This causes the fee to be undervalued by a factor of 10^12.

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.

In blockchain systems, fees are often calculated in very small units. Here, the code mixed up two units: wei (1e18) and unibi (1e6). Because it didn't convert between them, the fee amount was treated as much smaller than it should be, so users might pay less than required.

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.