anti-flashloan mechanism may lead to protocol default
A price check meant to block flash-loan attacks could prevent liquidations during a sustained market downturn, leaving the protocol under-collateralised. An attacker could not directly exploit this, but the design flaw could cause bad debt for lenders.
Submitted by gzeon
There is a price check to avoid flash loan attacks which significantly moved the price. If current price is 5% lower than the stored twap price, the liquidation will fail. This design can be dangerous as it is to openleverage’s benefit to close under-collateralized position ASAP when there is a huge market drawdown. When the market keep trading downward, it is possible that the spot price keep trading 5% lower than the twap, which prevent any liquidation from happening and causing the protocol to be under-collateralized.
Proof of Concept
// Avoid flash loan
if (prices.price < prices.cAvgPrice) {
uint differencePriceRatio = prices.cAvgPrice.mul(100).div(prices.price);
require(differencePriceRatio - 100 < maxLiquidationPriceDiffientRatio, 'MPT');
}
Recommended Mitigation Steps
Instead of revert with maxLiquidationPriceDiffientRatio, use the twap price to determine if the position is healthy.
ColaM12 (OpenLeverage) disputed
0xleastwood (judge) commented:
From first impression, this finding seems legitimate. Can I get some more details on why it was disputed? @ColaM12
ColaM12 (OpenLeverage) commented:
There is always a chance to front run a flash loan transaction before trading in OpenLev. Also, see in line 196, position is considered not healthy only if all three price check failed including the twap price.
0xleastwood (judge) commented:
It looks like only one condition would need to be satisfied for
isPositionHealthyto return false as it uses||and not&&.
ColaM12 (OpenLeverage) commented:
Do you mean return true? All 3 price checks should fail when liquidating. But the position may still hold funds to pay off debt. by using maxLiquidationPriceDiffientRatio, under-priced-swaps can be limited . Otherwise, all remaining funds in the position could be drained from a flash loan attack which directly leads to a bad debt to lender.
0xleastwood (judge) commented:
Ahh sorry my mistake. I misinterpreted that.
I agree with the sponsor here. The issue outlined by the warden seems to be safeguarded by the two other checks in
isPositionHealthy()
0xleastwood (judge) commented:
Actually thinking about this more, I think the warden raised an issue related to the liquidations continuing to fail if the price keeps trending downward at an accelerated pace. I don’t think the protocol would be able to respond to such events if this reverts.
0xleastwood (judge) commented:
After discussion with the sponsor, we have agreed that this issue is valid. It is expected that the TWAP is only valid for 1 min. By removing this condition, there is potential for even larger security issues. So the sponsor has decided to make this a wont-fix but I’ll keep the issue open as it is valid.
This was an awesome find!
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 liquidation function reverts when the spot price is more than 5% below the stored TWAP, without considering that a sustained price drop could keep this condition true and block all liquidations.
Impact
During a sustained market decline, liquidations could repeatedly fail, leaving the protocol under-collateralised and potentially causing bad debt for lenders.
What the attacker needed
Sustained market downturn; spot price stays >5% below TWAP
The fix
The sponsor decided not to fix it, but the report suggests using the TWAP price to determine position health instead of reverting.
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.
This is a smart contract for lending. It has a rule that stops liquidations if the current price is much lower than a stored average price, to stop quick price manipulation. But if the price keeps falling, that rule can block all liquidations, so bad loans are not closed and the protocol can lose money.
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.