Incorrect calculation of required gas limit during deposit transaction
The deposit transaction gas limit check only enforces a minimum of 21000, not that the gas limit covers the intrinsic gas cost of the data. An attacker could choose a gas limit between 21000 and the calculated burn threshold to avoid burning gas on L1 for L2 execution, causing the sequencer to process long data without compensation.
HE1M Follow with unforgiven
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-03-optimism-judging/issues/9
Found by
HE1M, unforgiven
Summary
It is possible to bypass burning the gas on L1 if _gasLimit is accurately chosen between 21000 and used gas.
Vulnerability Detail
The gas that deposit transactions use on L2 is bought on L1 via a gas burn in ResourceMeterin.sol:
https://github.com/sherlock-audit/2023-03-optimism/blob/main/optimism/packages/contracts-bedrock/contracts/L1/OptimismPortal.sol#L432
https://github.com/sherlock-audit/2023-03-optimism/blob/main/optimism/packages/contracts-bedrock/contracts/L1/ResourceMetering.sol#L162
There is also a condition on the parameter _gasLimit to protect against DoS attack:
https://github.com/sherlock-audit/2023-03-optimism/blob/main/optimism/packages/contracts-bedrock/contracts/L1/OptimismPortal.sol#L443
But, by using this limitation, it does not enforce to burn correct amount of gas on L1. Because, if the following condition is satisfied, the user will not burn any gas for the transaction on L2 (it only pays gas for the L1 transaction):
21000 <= _gasLimit <= [usedGas * max(block.basefee, 1 gwei) / prevBaseFee]
The condition 21000 <= _gasLimit will satisfy the condtion:
https://github.com/sherlock-audit/2023-03-optimism/blob/main/optimism/packages/contracts-bedrock/contracts/L1/OptimismPortal.sol#L443
The condition _gasLimit <= [usedGas * max(block.basefee, 1 gwei) / prevBaseFee] will bypass the condition (so no gas will be burned on L1):
https://github.com/sherlock-audit/2023-03-optimism/blob/main/optimism/packages/contracts-bedrock/contracts/L1/ResourceMetering.sol#L161-L163
For instance, if a user provides a long bytes as _data parameter, the usedGas will be increased, so the margin between 21000 to [usedGas * max(block.basefee, 1 gwei) / prevBaseFee] will be increased as well. By choosing a _gasLimit in this range, the burning gas mechanism can be bypassed. If the _gasLimit is set to the minimum allowed value (21000), this transaction will be failed most probably on L2 due to not enough gas limit. All in all, the sequencer would not be compensated although he processed a long data.
Impact
- Using L2 resources without enough compensation.
- DoS
Code Snippet
Tool used
Manual Review
Recommendation
It is recommended to include the _data length as well as 21000 to the lower bound of gas limit:
require(_gasLimit >= 21_000 + _data.length * 16, "OptimismPortal: gas limit must cover instrinsic gas cost");
Discussion
GalloDaSballo
Sidestepping of cost, no loss of principal, agree with Med
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
Likely the lower bound for the gas limit only checks a fixed minimum (21000) and does not account for the extra gas needed for the size of the transaction data, allowing a gas limit that is below the actual cost to be accepted.
Impact
The sequencer could process long data without being compensated, and this could also lead to a denial of service.
What the attacker needed
Ability to submit a deposit transaction
The fix
The gas limit check should be updated to require that the gas limit is at least 21000 plus the intrinsic gas cost of the data length.
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.
When you send a transaction on a rollup, you pay for the computing power (gas) it will use on the second layer. This report shows that a check on the gas limit was too loose, so someone could set a low gas limit and avoid paying for that second-layer gas, while still making the system process a lot of data.
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.