Gas refunds use block gas instead of transaction gas, leading to incorrect refund amounts #45
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
M-04
primary issue
Highest quality submission among a set of duplicates
🤖_12_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
selected for report
This submission will be included/highlighted in the audit report
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-11-nibiru/blob/84054a4f00fdfefaa8e5849c53eb66851a762319/app/evmante/evmante_gas_consume.go#L100-L105
Vulnerability details
Finding description and impact
There is a mismatch between how gas fees are deducted and refunded in the EVM implementation:
evmante_gas_consume.go
, gas fees are deducted upfront based on each transaction's individual gas limitmsg_server.go
uses the cumulative block gas usage to determine refunds for individual transactionsThis mismatch means users will receive incorrect (lower) refunds than they should. The gas refund should be based on the difference between a transaction's gas limit (what was charged) and its actual gas usage (what was consumed), not the block's total gas usage.
The impact is that users will lose funds as they receive smaller refunds than they should. This becomes especially problematic when multiple transactions are included in a block, as the cumulative block gas increases with each transaction, reducing refunds for subsequent transactions.
Proof of Concept
The issue stems from two pieces of code:
evmante_gas_consume.go
based on transaction gas limit:Where
VerifyFee
returns the fee based on the transaction gas limit:msg_server.go
are calculated using block gas:To demonstrate the impact, consider this scenario:
Recommended mitigation steps
The refund calculation should be based on each transaction's individual gas usage rather than the block gas. Modify the refund logic in
msg_server.go
:This ensures that each transaction's refund is calculated based on its own gas limit and usage, independent of other transactions in the block.
The text was updated successfully, but these errors were encountered: