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.
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:
- Transaction validation in
evmante_validate_basic.go. - 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
- 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
- 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
}
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:
- A transaction with a gas price of 1 wei and gas limit of 21000 would result in a fee of 21000 wei.
- This should be converted to 0.000021 unibi (
21000 / 10^12). - However, the current code would set it as 21000 unibi, which is incorrect by a factor of
10^12.
Recommended mitigation steps
- 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())),
},
)
- In
msg.go, update the fee conversion inBuildTx:
feeAmt := sdkmath.NewIntFromBigInt(evm.WeiToNative(txData.Fee()))
if feeAmt.Sign() > 0 {
fees = append(fees, sdk.NewCoin(evmDenom, feeAmt))
}
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 the21000unibivalue for fees paid what’s wanted here.Digging into this now to see which parts are correct or incorrect between
msg.goandevmante_validate_basic.go.
Nibiru mitigated:
PR-2157 - Fixed unit inconsistency related to
AuthInfo.FeeandtxData.Fee.
Status: Mitigation confirmed.
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
- A transaction is created with a gas price and gas limit, resulting in a fee in wei.
- The fee is used directly as unibi in transaction validation and building without conversion.
- 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.