OpenLeverage contest - gzeon's results

Permissionless lending and margin trading protocol that enables traders to long/short any trading pair on DEXs efficiently and securely.

General Information

Platform: Code4rena

Start Date: 27/01/2022

Pot Size: $75,000 USDT

Total HM: 6

Participants: 29

Period: 7 days

Judge: leastwood

Total Solo HM: 6

Id: 72

League: ETH

OpenLeverage

Findings Distribution

Researcher Performance

Rank: 3/29

Findings: 3

Award: $5,901.25

🌟 Selected for report: 4

🚀 Solo Findings: 1

Findings Information

🌟 Selected for report: gzeon

Labels

bug
2 (Med Risk)

Awards

4882.8125 USDT - $4,882.81

External Links

Handle

gzeon

Vulnerability details

Impact

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

https://github.com/code-423n4/2022-01-openleverage/blob/501e8f5c7ebaf1242572712626a77a3d65bdd3ad/openleverage-contracts/contracts/OpenLevV1Lib.sol#L191

// Avoid flash loan if (prices.price < prices.cAvgPrice) { uint differencePriceRatio = prices.cAvgPrice.mul(100).div(prices.price); require(differencePriceRatio - 100 < maxLiquidationPriceDiffientRatio, 'MPT'); }

Instead of revert with maxLiquidationPriceDiffientRatio, use the twap price to determine if the position is healthy.

#0 - 0xleastwood

2022-02-19T11:23:43Z

From first impression, this findings seems legitimate. Can I get some more details on why it was disputed? @ColaM12

#1 - ColaM12

2022-02-21T02:23:29Z

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.

#2 - 0xleastwood

2022-02-21T06:29:35Z

It looks like only one condition would need to be satisfied for isPositionHealthy to return false as it uses || and not &&.

#3 - ColaM12

2022-02-21T07:42:47Z

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.

#4 - 0xleastwood

2022-02-21T08:10:57Z

Ahh sorry my mistake. I misinterpreted that.

#5 - 0xleastwood

2022-02-21T08:12:17Z

I agree with the sponsor here. The issue outlined by the warden seems to be safeguarded by the two other checks in isPositionHealthy()

#6 - 0xleastwood

2022-02-21T09:01:29Z

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.

#7 - 0xleastwood

2022-02-21T09:41:04Z

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.

#8 - 0xleastwood

2022-02-21T09:41:34Z

This was an awesome find!

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter