Keepers will suffer significant losses due to miss compensation for L1 rollup fees
The keeper compensation mechanism only accounts for L2 execution gas and ignores the often much larger L1 rollup fee, so keepers can lose money when submitting transactions. This can cause keepers to stop working, blocking oracle price updates and order execution.
KingNFT
While keepers submits transactions to L2 EVM chains, they need to pay both L2 execution fee and L1 rollup fee. Actually, L1 fees are much higher than L2 fees. In many case, L2 fees can be practically negligible. The current implementation only compensate and incentive keepers based on L2 gas consumption, keepers will suffer significant losses.
Vulnerability Detail
As shown of keep() modifier (L40-57), only L2 execution fee are compensated.
Typically, L1 fees are dynamic and determined by the calldata length and smoothed Ethereum gas prices. To submit Pyth oracle price, the VAA calldata will be 1700+ bytes, keepers need to pay much L1 rollup fee.
1 comment(s) were left on this issue during the judging contest.
141345 commented:
m
arjun-io
The Kept helper supports a buffer amount which can be used for this use case.
ydspa
Escalate
Using Kept buffer can't solve this problem, as the ratio of L1GasPrice / L2GasPrice changes in every block and can vary with a extreme wide range.
Let's say
Solidity
CurrentL1GasPrice = 20 Gwei // it refers to smoothed recent Ethereum gas price provided by L2 system contract
CurretnL2GasPrice = 2 Gwei // it refers to block.basefee
L1RollupGas = 40,000
L1RollupFee = L1RollupGas * CurrentL1GasPrice = 40,000 * 20 = 800,000 Gwei
Therefore, regardless of how we set buffer, as it's a fixed value, sometimes keepers suffer losses, and other times keepers earn extra profit.
During periods that keepers suffer losses, they are likely to stop working and the system is blocked.
And other periods , the protocol suffer losses.
About the severity:
(1) As the users' orders will be held until keepers become profitable, the waiting time may be short as some minutes, may be long as some hours, or even some days. Users' financial losses are foreseeable.
(2) while keepers earn extra profit, proper ratio of L1GasPrice / L2GasPrice and block.basefee could make keeperReward > settlementFee, then a new attack vector become feasible,keepers can set 1 wei orders by self to drain fund from protocol, as self.fee ~= 0, profit ~= keeperReward - self.keeper = keeperReward - settlementFee
Using Kept buffer can't solve this problem, as the ratio of L1GasPrice / L2GasPrice changes in every block and can vary with a extreme wide range.
Let's say
Solidity
CurrentL1GasPrice = 20 Gwei // it refers to smoothed recent Ethereum gas price provided by L2 system contract
CurretnL2GasPrice = 2 Gwei // it refers to block.basefee
L1RollupGas = 40,000
L1RollupFee = L1RollupGas * CurrentL1GasPrice = 40,000 * 20 = 800,000 Gwei
Therefore, regardless of how we set buffer, as it's a fixed value, sometimes keepers suffer losses, and other times keepers earn extra profit.
During periods that keepers suffer losses, they are likely to stop working and the system is blocked.
And other periods , the protocol suffer losses.
About the severity:
(1) As the users' orders will be held until keepers become profitable, the waiting time may be short as some minutes, may be long as some hours, or even some days. Users' financial losses are foreseeable.
(2) while keepers earn extra profit, proper ratio of L1GasPrice / L2GasPrice and block.basefee could make keeperReward > settlementFee, then a new attack vector become feasible,keepers can set 1 wei orders by self to drain fund from protocol, as self.fee ~= 0, profit ~= keeperReward - self.keeper = keeperReward - settlementFee
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.
arjun-io
Thanks for the thorough explanation on why a buffer won't work. We agree that we should modify the Kept function to estimate L1 gas costs, thanks for the report!
Medium:
viable scenario (even if unlikely) that could cause the protocol to enter a state where a material amount of funds can be lost.
The attack path is possible with assumptions that either mimic on-chain conditions or reflect conditions that have a reasonable chance of becoming true in the future.
High:
This vulnerability would result in a material loss of funds, and the cost of the attack is low.
Here the imbalanced L1/L2 gas fee would not be too frequent. Most of the time, the buffer will be good to compensate for the keeper. The described loss will incur when all the special conditions are met, and the fixed buffer is not enough to cover the keeper's cost.
@ydspa tend to agree with this comment: #91 (comment) A valid medium
I think the conclusion of Here the imbalanced L1/L2 gas fee would not be too frequent is not correct, the ratio of L1GasPrice / L2GasPrice vary frequently in a very wide range. The following table shows 3 typical 2-hours range of Ethereum VS Optimistic gas price in the past two weeks. We can see the Ratio can vary from e1 to as large as e9.
It will cause users' orders been held up to some hours in 2 ways:
Let's say we set buffer according Ratio = 2e8 and plus up to 100% intended reward for keepers, which means the system can only work well while Ratio is during (2e8, 4e8).
So, in 2023-08-27 02:00 ~ 04:00 the system works, but in most cases, the system doesn't work such as
(1) in 2023-08-22 02:00 ~ 04:00, the Ratio is too high, keepers would suffer loss which might lead them to stop pushing price and users' orders are held.
(2) in 2023-08-17 10:00 ~ 12:00, the Ratio is too low, keepers earn too much reward, which will trigger the following protection, then no new price can be pushed to chain, all users' orders are held entirely.
Solidity
File: packages\perennial-oracle\contracts\OracleFactory.sol
93: function claim(UFixed6 amount) external {
94: if (amount.gt(maxClaim)) revert OracleFactoryClaimTooLargeError();
...
97: }
To be emphasized:
Regardless of how we set buffer, it can only work in a extreme narrow Ratio range as compared to (e1, e9).
Just in the past 2 weeks, we can easily find more examples like the above ones that would block users' orders for up to 2 hours. It's almost 100% sure this bug would be repeatedly triggered during the long lifetime of the protocol.
As a perpetual exchange APP, users' orders are held up to some hours, especially in the above case (2), the service is stopped entirely, users' financial losses are foreseeable, the impact is high.
Hence, the issue is with both high probability of occurrence and high impact, undoubtedly should be a high issue.
141345
Yes the fee ratio could vary across a wide span. Extreme high L1 gas fee is intermittent, and will repeat.
However, the protocol can set some fix buffer at 90% percentile of the L1/L2 fee ratio (maybe at e8 level), then the loss will only emerge in some certain scenarios.
Still seems medium due to conditional loss.
ydspa
Yes the fee ratio could vary across a wide span. Extreme high L1 gas fee is intermittent, and will repeat. However, the protocol can set some fix buffer at 90% percentile of the L1/L2 fee ratio (maybe at e8 level), then the loss will only emerge in some certain scenarios.
Still seems medium due to conditional loss.
(1)I'm convinced that you can't find a buffer that works at 90% percentile, it is even hard to work at 50%, you can set buffer with a fixed Ratio plus some intended reward such as 100% (in perennial testcase, it's only 50%), then verify data in the past 1 year
(2) conditional loss of 1 % probability VS 99% probability are not the same thing, i think the later should be treated as unconditional .
141345
Even the distribution is Pareto distribution (power law), percentile still works. 50%, 90% can be found.
ydspa
Even the distribution is Pareto distribution (power law), percentile still works. 50%, 90% can be found.
Give your specific parameters please
141345
you can't find a buffer that works at 90% percentile, it is even hard to work at 50%
percentile always can be found, such as medium number(50%).
On the opposite, mean value could be hard to find, those extreme high gas fee can make mean not converge.
ydspa
More proof: if we set buffer according e8 level as recommended above, then we can find lots of examples the actual Ratio falls below e6 which keepers would earn too much rewards (10,000% level) to trigger system protection to block price submission.
The instances are all from the past one month, and sample interval is 1 hour, that's mean, averagely speaking, the system will be blocked for about 127 hours (5+ days) in one month if we set buffer according e8 level.
The main point is, there is some parameter, considering the trade off, can balance the loss and overpayment. e8 is just an example.
ydspa
The main point is, there is some parameter, considering the trade off, can balance the loss and overpayment. e8 is just an example.
What my meaning is the parameter doesn't exist at all, mathematically speaking, L1Price and L2Price are enough independent, we can't calculate the following result by only L2Price
Solidity
Optimism Transaction Fee = [ Fee Scalar * L1 Gas Price * (Calldata + Fixed Overhead) ] + [ L2 Gas Price * L2 Gas Used ]
This is why no matter we set buffer according e1, e2, ..., e9 or any other value, the issue would be repeatedly triggered. So, actually it's a unconditional issue.
ydspa
you can't find a buffer that works at 90% percentile, it is even hard to work at 50%
percentile always can be found, such as medium number(50%).
On the opposite, mean value could be hard to find, those extreme high gas fee can make mean not converge.
Here is a mistake in thoughts, set buffer according the number of 90% percentile, not means the setting will work from 0% percentile to 90% percentile, actually it might only work for (85%, 95%).
141345
0.001, 0.02, 0.3, 4, 5, 6, 7, 8, 9, 10000.
For this skewed distribution, 90% percentile is 9.
Why only work for around 9?
ydspa
0.001, 0.02, 0.3, 4, 5, 6, 7, 8, 9, 10000.
For this skewed distribution, 90% percentile is 9. Why only work for around 9?
Let's say, at e9, keeper get $1, then at e8 it becomes $10, at e7 it would be $100...
141345
repeatedly triggered
My understanding, something like, it could be triggered 10-20% of the time in a certain time span, such as 1 month, 1 week.
It still falls into the category with condition:
Per criteria
The attack path is possible with assumptions that either mimic on-chain conditions or reflect conditions that have a reasonable chance of becoming true in the future.
ydspa
My understanding about the probability of issue occurrence, which i learned when i work for other audit firms, are like this:
If the issue will occur even once with high probability in a reasonable period such as 3 months, then it's high probability.
It's far away from the thought that only if a issue will keep occurring in most the time, let's say, in 2 of the 3 months, then it's high probability.
So, in my opinion, if a issue might occur hundred times a month, it's obviously a high probability. And with high probability and high impact issue, we mark it as high.
Actually, we can think the situation much more simple:
If an exchange's service would be suspended randomly sum up to average 7 days per month, is it critical, high or medium?
I will choose critical though Sherlock doesn't have this level.
hrishibhat
Result:
High
Unique
After considering further points raised by Watson given the frequency of the condition mentioned in the example above. The impact is not just about the loss for the keeper but also keepers not submitting txs and executing orders. This can be looked at as a severe issue overall. Considering this issue a valid high.
The original report as published on Sherlock, by KingNFT. 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
The keeper reward calculation uses only the L2 gas used and the L2 base fee, ignoring the L1 data fee that depends on calldata size and Ethereum gas prices.
Impact
Keepers may suffer losses and stop submitting oracle prices and executing orders, which could block the system; the report also notes that a fixed buffer cannot reliably cover the variable L1/L2 fee ratio.
What the attacker needed
Keeper submits transactions on an L2; L1 rollup fee exceeds L2 fee
The fix
The Kept helper and Pyth oracle were updated to estimate L1 gas costs, as confirmed by the project team.
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
On layer-2 blockchains like Optimism, every transaction pays two fees: a small fee for computation on the layer-2 chain, and a larger fee for posting data to Ethereum (layer 1). The code only reimbursed the small fee, so the people running the system (keepers) could end up paying more than they earned. If keepers stop because they lose money, the system stops updating prices and processing orders.
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.