Usage of **revert** in case of low gas in `L1CrossDomainMessenger` can result in loss of fund
The L1CrossDomainMessenger uses a revert opcode when the gas check fails during relayMessage, which prevents the failed message flag from being set. If the gas check fails after the withdrawal is finalized in OptimismPortal, the user's funds are lost because the withdrawal cannot be replayed.
I am reporting this issue separate from my other report Causing users lose fund if bridging long message from L2 to L1 due to uncontrolled out-of-gas error, as I think they provide different attack surface and vulnerability.
In the previous report, it is explained that if the forwarded gas passes the gas condition in OptimismPortal, but goes out of gas in L1CrossDomainMessenger, it will result in loss of fund since baseGas does not consider the effect of memory expansion.
But, in this report, I am going to explain that due to usage of revert opcode instead of return, users can lose fund if for any reason the gas left is not meeting the condition in L1CrossDomainMessenger.
In other words, there is a check for the amount of gas provided in callWithMinGas. This check is invoked twice: One in OptimismPortal.finalizeWithdrawalTransaction and one in L1CrossDomainMessenger.relayMessage. If the first check is passed, and the second check is not passed, the users' withdrawal transactions are considered as finalized, but not considered as failed message. So, they can not replay their withdrawal transactions.
Suppose some time is passed, and an EIP is proposed so that the gas consumption of some opcodes are changed. During this time, still Alice's withdrawal transaction is not executed on L1 yet.
Since, the withdrawal transaction is set as finalized in OptimismPortal but not set as failed in L1CrossDomainMessenger, it can not be replayed, and Alice loses her fund.
Impact
Causing users lose fund.
Code Snippet
Tool used
Manual Review
Recommendation
I would say that the callWithMinGas should return false instead of revert when called during L1CrossDomainMessenger.relayMessage if the condition of required gas is not met. The following modification in L1CrossDomainMessenger.relayMessage is recommended.
This one is tricky.
The recommendation is a good one, and we agree that it is better to avoid reverting on this code path, however it is also speculative as it depends on some future gas schedule changes and lacks a PoC.
GalloDaSballo
Per the rules:
I don't think the pre-conditions"have a reasonable chance of becoming true in the future", as this would require:
Computing incorrect limit
Waiting for Hardfork
Hardfork does change CALL / base level costs (risk of every transfer contract being bricked)
User is oblivious and doesn't fix
Relaying (and getting griefed)
GalloDaSballo
Recommend: Closing as invalid
HE1M
Escalate for 10 USDC
Using revert in L1CrossDomainMessenger clearly breaks the replayability guarantee of the project.
In the report it is mentioned that:
due to usage of revert opcode instead of return, users can lose fund if for any reason the gas left is not meeting the condition in L1CrossDomainMessenger
I agree with your comment regarding Future issues, but the EIP proposed assumption, is just an example for better understanding.
In other words, the project tried to estimate the gas consumption accurately enough when crossing the message from L2 to L1, so that correct amount of gas is forwarded to the target. If, in the middle something happens, there is replayability mechanism to guarantee that the users are able to retry their withdrawal. But, due to this wrong usage of revert all those efforts can be broken, and users' fund can be lost.
Please also note that providing a scenario to reach to the revert opcode in L1CrossDomainMessenger.relayMessage should be considered as a separate bug, because there were lots of effort to calculate the correct gas estimation. So, reaching to this line of code means that something is broken in the middle.
For example, due to math miscalculation of the gas (as reported in this contest like: #40 #5 , ...) the revert is reachable and can result to loss of fund. But, if revert was not used, the message would be considered as failed, and the tx would be able to be replayed. So, other bugs would have less impact.
All in all, this wrong usage of revert is a bug besides other bugs (math miscalculations) that lead to reaching to this line of code.
For example, in the following function sampleFunction, there are lots of processing in Part A to ensure that x is bigger than 10. If x is lower than 10, Part B is reachable and will be executed.
Solidity
function sampleFunction() {
// Part A: all the processing to ensure x is bigger than 10
if(x < 10){
// Part B: some other processing
}
// remaining of the code
}
In this sample code, there are two ways to find bug:
Finding a bug in Part A that leads to x lower than 10
Finding a bug in Part B
You can replace, the gasLeft() with x, 10 with ((_minGasLimit + 200) * 64) / 63), Part A with all the math calculations for the gas estimation, and Part B with the lines.
In this report, I found a bug in Part B which should be considered separate from the bug related to Part A.
sherlock-admin
Escalate for 10 USDC
Using revert in L1CrossDomainMessenger clearly breaks the replayability guarantee of the project.
In the report it is mentioned that:
due to usage of revert opcode instead of return, users can lose fund if for any reason the gas left is not meeting the condition in L1CrossDomainMessenger
I agree with your comment regarding Future issues, but the EIP proposed assumption, is just an example for better understanding.
In other words, the project tried to estimate the gas consumption accurately enough when crossing the message from L2 to L1, so that correct amount of gas is forwarded to the target. If, in the middle something happens, there is replayability mechanism to guarantee that the users are able to retry their withdrawal. But, due to this wrong usage of revert all those efforts can be broken, and users' fund can be lost.
Please also note that providing a scenario to reach to the revert opcode in L1CrossDomainMessenger.relayMessage should be considered as a separate bug, because there were lots of effort to calculate the correct gas estimation. So, reaching to this line of code means that something is broken in the middle.
For example, due to math miscalculation of the gas (as reported in this contest like: #40 #5 , ...) the revert is reachable and can result to loss of fund. But, if revert was not used, the message would be considered as failed, and the tx would be able to be replayed. So, other bugs would have less impact.
All in all, this wrong usage of revert is a bug besides other bugs (math miscalculations) that lead to reaching to this line of code.
For example, in the following function sampleFunction, there are lots of processing in Part A to ensure that x is bigger than 10. If x is lower than 10, Part B is reachable and will be executed.
Solidity
function sampleFunction() {
// Part A: all the processing to ensure x is bigger than 10
if(x < 10){
// Part B: some other processing
}
// remaining of the code
}
In this sample code, there are two ways to find bug:
Finding a bug in Part A that leads to x lower than 10
Finding a bug in Part B
You can replace, the gasLeft() with x, 10 with ((_minGasLimit + 200) * 64) / 63), Part A with all the math calculations for the gas estimation, and Part B with the lines.
In this report, I found a bug in Part B which should be considered separate from the bug related to Part A.
You've created a valid escalation for 10 USDC!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
hrishibhat
Escalation accepted
After further discussions with the Lead judge and the protocol this issue was considered to be a weak version of #40, hence considering this issue a valid solo medium.
sherlock-admin
Escalation accepted
After further discussions with the Lead judge and the protocol this issue was considered to be a weak version of #40, hence considering this issue a valid solo medium.
This issue's escalations have been accepted!
Contestants' payouts and scores will be updated according to the changes made on this issue.
The original report as published on Sherlock, by HE1M. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.
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 a minute. 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
Likely the use of a revert opcode instead of returning false in the gas check within relayMessage, which undoes the entire transaction and prevents the failed message flag from being set.
Impact
Users could lose their funds if the gas check fails during relayMessage, as the withdrawal is finalized but not marked as failed, preventing replay.
What the attacker needed
Victim bridges a message from L2 to L1; attacker finalizes the withdrawal; gas check fails in relayMessage
The fix
The callWithMinGas function should return false instead of reverting when called during relayMessage if the gas condition is not met.
How it was found
Alice bridges a message from L2 to L1 by calling sendMessage.
Bob finalizes Alice's withdrawal transaction by calling finalizeWithdrawalTransaction with the required gas, which passes the gas check in OptimismPortal and sets finalizedWithdrawals to true.
The remaining gas is forwarded to L1CrossDomainMessenger.relayMessage, but the gas check fails due to increased gas consumption.
relayMessage reverts, so the failedMessages flag is not set to true.
Alice's withdrawal is finalized but not marked as failed, so she cannot replay it and loses her funds.
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 a minute. 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
When you move funds between blockchains, a message is sent to the other side. If something goes wrong during processing, the system should mark the message as failed so you can try again. Here, a coding mistake causes the whole process to be undone without marking it as failed, so your funds get stuck.
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.