-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gas used mismatch in failed contract calls can lead to wrong gas deductions #46
Comments
Valid issue! For comparison, Ethermint consumes the cumulative gas for all EVM messages contained in the Cosmos tx (transient gas) -> https://github.com/evmos/ethermint/blob/fd8c2d25cf80e7d2d2a142e7b374f979f8f51981/x/evm/keeper/state_transition.go#L260-L261 |
berndartmueller marked the issue as selected for report |
berndartmueller marked the issue as satisfactory |
It's a valid issue but inaccurate.
Specifically, the mistake is that we're not adding to the block gas meter on evm tx failure, and |
For intra-contest severity consistency, I'd like to ask for a reconsideration of the severity here. The impact is the same as #25, so I think they should have the same severity. |
I had a closer look again. I conclude from this that contract calls from within precompile calls are always added to the block gas used. Rendering this issue invalid as it does not explain the real issue. I even think that in the success case, the used gas should not be added to the block gas (in https://github.com/code-423n4/2024-11-nibiru/blob/8ed91a036f664b421182e183f19f6cef1a4e28ea/x/evm/keeper/call_contract.go#L133-L138) and Inviting @OpenCoreCH for comment. |
I first want to note that But yes, after looking at it again, I agree that the success path was previously also wrong (depending on the caller), which would have been an issue on its own. This lead to a wrong recommended mitigation from me because I assumed this path was correct. Nevertheless, the issue that was pointed out in the finding description ("This inconsistency means that failed transactions do not properly contribute to the block's gas tracking") was actually present and would have lead to wrong gas tracking (for instance for |
Hey @OpenCoreCH! Let's clarify what "block gas" i.e. We have to consider this potential issue within two different contexts:
For 1), the precompile call has its own gas meter. Gas usage is bubbled up and handled appropriately in Can we agree on that? For 2), the transient gas meter is not relevant. A regular Cosmos tx has a gas meter with the limit set to the limit provided by the tx sender. This gas meter is used for all messages contained in that tx. That's why I think the reported issue is not an actual issue. Please let me know what you think, happy to hear your thoughts! |
Agree, this was apparently another issue that the gas was added twice in this codepath.
For regular Cosmos TX that contains some EVM calls (such as *It seems like it was indeed done incorrectly after looking at it in more detail, as the transient gas meter is not reset in the ante handler for Cosmos SDK txs. But I think this is a different problem with a different underlying issue (the underlying issue being that it was not reset) and it seems natural to assume that the code was written with the intended functioning that it should add to the transient gas meter there, otherwise this code would not have been in the success path. |
I now agree that within regular Cosmos TXs, it must track the cumulative EVM gas used across all batched Cosmos messages (which invoke an EVM call) and use it with Otherwise, as it is currently the case, |
Sorry for the late reply, but our code doesn't allow for mixing EVM msgs and Cosmos msgs in the same Cosmos tx, see
If a user wants to submit an EVM tx, it will contain the I agree that I see the warden's point for how, in a bundle of EVM msgs in a tx, if the last EVM msg fails, then we reset the entire tx's gas meter and only consume the gas used of the last EVM msg. Now, we have removed the See NibiruChain/nibiru#2167 for the removal of the |
Lines of code
https://github.com/code-423n4/2024-11-nibiru/blob/main/x/evm/keeper/call_contract.go#L118
Vulnerability details
Finding description and impact
In
call_contract.go
, when a contract call fails, the code only consumes gas for the failed transaction but does not account for previously accumulated block gas usage. This creates a mismatch between the actual gas used in the block and what gets consumed in the gas meter.The issue occurs in the error handling path of
CallContractWithInput
where after a failed call, only the gas of the failed transaction is consumed:However, in the success path, the code correctly adds the gas used to the block total:
This inconsistency means that failed transactions do not properly contribute to the block's gas tracking. This is especially bad when the failed transaction is the last one in a block, as it will decrease the gas counter heavily (only the last transaction vs. the sum of all).
Proof of Concept
The issue can be found in call_contract.go#L118:
Compared to the success path at call_contract.go#L133:
Recommended mitigation steps
To fix this issue, the gas accounting should be consistent between success and failure paths. Add the block gas tracking before handling the failure case:
This ensures that all gas used, whether from successful or failed transactions, is properly accounted for in the block total.
The text was updated successfully, but these errors were encountered: