Gas is not consumed when precompile method fail, allowing resource consumption related DOS
Precompile methods in Nibiru's EVM did not consume gas when they failed, allowing an attacker to repeatedly trigger failures and consume computational resources without paying the corresponding gas. This could lead to a denial-of-service attack by exhausting block gas limits.
When a precompile method fails (e.g., due to an error), gas is not consumed as the method returns early before invoking the gas consumption logic. This issue affects all three precompiles in the system:
FunToken
Wasm
Oracle
The lack of gas consumption on failure allows attackers to perform denial-of-service (DoS) attacks by exploiting the failure conditions to consume excessive resources without paying for them. The code snippet below demonstrates the issue:
if err != nil {
return nil, err
}
// Gas consumed by a local gas meter
contract.UseGas(startResult.CacheCtx.GasMeter().GasConsumed())
Impact:
Resource Consumption without Gas Payment: Since gas is not consumed on failure, an attacker can repeatedly trigger precompile failures, consuming large amounts of resources without the associated cost.
Potential DoS Attack: This can lead to a DoS attack, where an attacker fills the block with failed precompile executions, causing network slowdowns, failures, or even halting the chain.
Block Gas Limit Exploitation: Before the precompile.Run method is called, a small amount of requiredGas is consumed. However, once this is consumed, attackers can continue to use gas at no cost, potentially exhausting the block gas limit.
Proof of Concept
Create an EVM Contract: Design an EVM contract that calls the wasm.execute function repeatedly, up to the maxMultistoreCacheCount (10) times.
Trigger the DoS: Call the contract with a transaction that uses a large amount of gas limit.
Exploit the Failure: In the wasm.execute function, consume almost all of the available gas and then revert the transaction. This will allow the attacker to consume gas without paying for it, leveraging the bug in the precompile failure handling.
Recommended mitigation steps
Use gas before returning the err:
// Gas consumed by a local gas meter
contract.UseGas(startResult.CacheCtx.GasMeter().GasConsumed())
if err != nil {
return nil, err
}
Moving contract.UseGas() before the error handling does not make sense. See the reasons below:
User must specify a gas limit when sending an Ethereum tx.
Before precompile execution, an isolated gas meter is created with the specified gas limit.
If, during the execution (could be in the beginning or in the middle), gas consumption exceeds the user-specified gas limit, the gas meter throws an OutOfGas exception and reverts the transaction.
In case of transaction failure (as well as success), the user pays almost 100% of the gas specified in the transaction. This is done to encourage users to be more accurate and to call EstimateGas() before execution. There is a potential 20% refund (see here), but this is not a significant factor.
Therefore, a potential attacker WILL still pay gas regardless of whether the transaction succeeds or reverts.
@onikonychev - due to not consuming the precompile gas in the case of an error, a user can repeatedly call the precompile, have it purposefully error and thus consume more computational resources than the user would be eligible for with the paid gas.
The original report as published on Code4rena, by 0x007. 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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The precompile methods returned early on error before calling the gas consumption function, so gas was not deducted for the work performed before the failure.
Impact
An attacker could repeatedly trigger precompile failures to consume resources without paying gas, potentially causing a denial-of-service by exhausting the block gas limit.
What the attacker needed
Ability to deploy and call EVM contracts; a wasm contract that can be made to fail after consuming gas
How it was found
Create an EVM contract that calls the wasm.execute function repeatedly, up to the maxMultistoreCacheCount (10) times.
Call the contract with a transaction that uses a large amount of gas limit.
In the wasm.execute function, consume almost all of the available gas and then revert the transaction.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
In blockchain systems like Ethereum, users pay 'gas' to run code, which prevents spam. This report found that when certain built-in functions (precompiles) failed, the system did not charge gas for the work done before the failure. An attacker could exploit this to make the network do lots of work for free, potentially slowing it down or stopping it.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.