Calling generateFLNQuote twice in every block prevents any migration
The public function generateFLNQuote can be called twice in the same block, causing the two most recent quotes to have the same block number. This makes the price stability check revert, blocking any migration that relies on it.
Submitted by camden, also found by GeekyLumberjack, kirk-baird, and shw
https://github.com/code-423n4/2022-01-behodler/blob/71d8e0cfd9388f975d6a90dffba9b502b222bdfe/contracts/UniswapHelper.sol#L138 In the Uniswap helper, generateFLNQuote is public, so any user can generate the latest quote. If you call this twice in any block, then the two latest flan quotes will have a blockProduced value of the current block’s number.
These quotes are used in the _ensurePriceStability function. The last require statement here is key: https://github.com/code-423n4/2022-01-behodler/blob/71d8e0cfd9388f975d6a90dffba9b502b222bdfe/contracts/UniswapHelper.sol#L283-L285
This function will revert if this statement is false:
localFlanQuotes[0].blockProduced - localFlanQuotes[1].blockProduced > VARS.minQuoteWaitDuration
Since VARS.minQuoteWaitDuration is a uint256, it is at least 0
localFlanQuotes[0].blockProduced - localFlanQuotes[1].blockProduced > 0
But, as we’ve shown above, we can create a transaction in every block that will make localFlanQuotes[0].blockProduced - localFlanQuotes[1].blockProduced == 0. In any block we can make any call to _ensurePriceStability revert.
_ensurePriceStability is called in the ensurePriceStability modifier: https://github.com/code-423n4/2022-01-behodler/blob/71d8e0cfd9388f975d6a90dffba9b502b222bdfe/contracts/UniswapHelper.sol#L70
This modifier is used in stabilizeFlan: https://github.com/code-423n4/2022-01-behodler/blob/71d8e0cfd9388f975d6a90dffba9b502b222bdfe/contracts/UniswapHelper.sol#L162
Lastly, stabilizeFlan is used in migrate in Limbo.sol https://github.com/code-423n4/2022-01-behodler/blob/71d8e0cfd9388f975d6a90dffba9b502b222bdfe/contracts/Limbo.sol#L234
Therefore, we can grief a migration in any block. In reality, the minQuoteWaitDuration would be set to a much higher value than 0, making this even easier to grief for people (you only need to call generateFLNQuote every minQuoteWaitDuration - 1 blocks to be safe).
Mitigation
Mitigation is to just use a time weighted oracle for uniswap.
gititGoro (Behodler) acknowledged and commented:
I appreciate the write up. You’re not technically incorrect on the problem. The solution isn’t ideal because Uniswap can’t tell us what’s happening on Behodler.
UniswapHelper can be replaced without much trouble. So if the oracle functionality does fail, we can deploy a better one. But for now, I doubt that the incentive exists to perpetually grief migrations on Limbo. If someone does start to grief, we can add flash governance to the flan quote generation and then burn the EYE belonging to griefers but I was reluctant to call on the big guns right from the start.
gititGoro (Behodler) changed to confirmed and commented:
I’ve changed this to confirmed because a cryptoeconomic layer should be added. Flash governance for sampling an oracle is too extreme and adding a require to force the duration can still be griefed.
Instead I think the solution is to force the caller to pay EYE if the interval is below the min required. The EYE is then burnt. So the idea is that if you wish to grief migrations, it’s going to cost you more than just gas and the community will benefit from your griefing.
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 price stability check assumes quotes are always from different blocks, but the public quote function allows two quotes in the same block, making the difference zero.
Impact
An attacker can repeatedly prevent migrations from succeeding, though the report notes the incentive to do so perpetually is doubted.
What the attacker needed
Ability to call a public smart contract function; pay gas for transactions
The fix
The project acknowledged the issue and suggested forcing the caller to pay and burn EYE tokens if the interval is below the minimum, but no fix was implemented in the text.
How it was found
- Call generateFLNQuote twice in the same block.
- This makes the two latest quotes have the same blockProduced value.
- Any call to _ensurePriceStability in that block will revert.
- This blocks stabilizeFlan and therefore migrate.
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.
A smart contract has a public function that anyone can call to update a price quote. If someone calls it twice quickly, the contract's safety check thinks the price is unstable and refuses to proceed, which stops a migration from happening.
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.