# Gas refunds use block gas instead of transaction gas, leading to incorrect refund amounts

Nibiru EVM refunded gas using cumulative tx gas instead of per-message gas, so users bundling multiple EVM messages received smaller refunds than owed.

- 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/45
- Library page: https://bugbountylibrary.com/r/c4%3A2024-11-nibiru%3AM-04
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:go technique:source-review vuln:accounting-error vuln:business-logic

**Target:** EVM module gas refund logic (msg_server.go, evmante_gas_consume.go)
**Root cause:** Fees are deducted per EVM message based on its gas limit, but refunds subtract the cumulative gas used across all bundled EVM messages in the Cosmos tx, so later messages get under-refunded.
**Steps:**
1. Bundle two EVM messages in one Cosmos tx: msg A gas limit 100k uses 50k, msg B gas limit 100k uses 40k.
2. Observe fee deduction in `evmante_gas_consume.go` uses each message's gas limit via `VerifyFee`.
3. Observe refund in `msg_server.go`: `blockGasUsed, _ := k.AddToBlockGasUsed(ctx, evmResp.GasUsed)` then `refundGas = evmMsg.Gas() - blockGasUsed`.
4. For msg B refund becomes 100k - (50k+40k) = 10k instead of 100k - 40k = 60k; user loses 50k gas worth of refund.
**How found:** Code-reading comparison of the fee-deduction path (per-message gas limit) against the refund path (cumulative gas tracker), spotting the mismatch in accounting basis.
**Insight:** When auditing fee/refund accounting, verify that the quantity charged and the quantity refunded are measured on the same basis (per-message vs cumulative); a variable named like block/tx scope may actually be a running accumulator reset per tx.

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

**Refund calculation using blockGasUsed in msg_server.go**

```
blockGasUsed, err := k.AddToBlockGasUsed(ctx, evmResp.GasUsed)
if err != nil {
    return nil, errors.Wrap(err, "EthereumTx: error adding transient gas used to block")
}

refundGas := uint64(0)
if evmMsg.Gas() > blockGasUsed {
    refundGas = evmMsg.Gas() - blockGasUsed
}
```

**Fee deduction based on tx gas limit**

```
fees, err := keeper.VerifyFee(
			txData,
			evm.EVMBankDenom,
			baseFeeMicronibiPerGas,
			ctx.IsCheckTx(),
		)
```

