Revert Lend - n1punp's results

A lending protocol specifically designed for liquidity providers on Uniswap v3.

General Information

Platform: Code4rena

Start Date: 04/03/2024

Pot Size: $88,500 USDC

Total HM: 31

Participants: 105

Period: 11 days

Judge: ronnyx2017

Total Solo HM: 7

Id: 342

League: ETH

Revert

Findings Distribution

Researcher Performance

Rank: 97/105

Findings: 1

Award: $10.29

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

10.2896 USDC - $10.29

Labels

bug
downgraded by judge
grade-b
primary issue
QA (Quality Assurance)
sponsor disputed
sufficient quality report
:robot:_03_group
Q-43

External Links

Lines of code

https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/V3Oracle.sol#L324

Vulnerability details

Impact

When price rallies, for example, in the case of UNI price spiked recently, TWAP may not be able to catch up easily with Chainlink price oracle. Hence, if the price diff is set too small, then the V3Oracle will revert. This means users will not be able to modify any of the positions, including liquidators. If price continues to rally, then this can end up with bad debt into the system due to underwater positions (see CompoundV2's case here: https://twitter.com/ChainLinkGod/status/1761061618983841828. This event has caused $3m bad debt to Compound v2 since TWAP did not catch up, causing oracle reverts during the UNI price pump).

Proof of Concept

The V3Oracle can read the price from 2 main sources: Chainlink and TWAP to sanity check the values. If the difference exceeds the set threshold, then the oracle reverts.

Now, if the threshold is too low, then the oracle reverts as in the UNI case mentioned above. If it is set too high, then the spot price becomes more manipulatable (since the same threshold is used for TWAP deviation and the spot price deviation), and the Uniswap V3 position can be priced incorrectly and can lead to bad liquidation (for example, the liquidator can manipulate the price of LP to be lower than what it should be, and triggers the liquidation, and getting higher shares of LP -> getting even more value).

Tools Used

Manual Review

Assessed type

Oracle

#0 - c4-pre-sort

2024-03-19T10:05:26Z

0xEVom marked the issue as sufficient quality report

#1 - c4-pre-sort

2024-03-19T10:05:28Z

0xEVom marked the issue as primary issue

#2 - 0xEVom

2024-03-25T08:52:34Z

Medium severity due to external assumptions.

Related: #223

#3 - kalinbas

2024-03-27T16:16:00Z

Initial thoughts: There is another parameter which is TWAP period which we plan to set much lower than for example compound to react faster to price changes. Of course there is still the same risk but it is much smaller. Because we use TWAP only to verify prices the period may be lower, as manipulation only leads to temporary disabled liquidations.

#4 - kalinbas

2024-03-27T16:19:41Z

"This means users will not be able to modify any of the positions" - this is not 100% true. You may always repay positions

#5 - mariorz

2024-03-27T20:20:42Z

There seem to be a few misunderstandings regarding how our protocol works that make this report invalid.

  1. "Hence, if the price diff is set too small, then the V3Oracle will revert. This means users will not be able to modify any of the positions, including liquidators." Important to note that what would revert in that case would be liquidations and new loans, existing loans would be able to settle any outstanding debt.
  2. "If price continues to rally, then this can end up with bad debt into the system due to underwater positions" A lending asset will only be 1 stablecoin, and any rally in the whitelisted collateral assets would not put the protocol at risk of bad debt.
  3. "(see CompoundV2's case here: https://twitter.com/ChainLinkGod/status/1761061618983841828. This event has caused $3m bad debt to Compound v2 since TWAP did not catch up, causing oracle reverts during the UNI price pump)."

The case of Compound is different in a few important ways:

  1. When their oracle sees a price deviation, it ignores the latest price and continues functioning with an outdated stale price. Revert Lend instead stops any new loans or liquidations until the deviation in prices seen by the oracle is corrected.
  2. Compound allows for the borrowing of volatile assets, Revert Lend only allows for borrowing of a stablecoin.

What happened with the UNI example with Compound

  1. Price increase on UNI suddenly and drastically and chainlink feed had the correct price but univ3 TWAP is outdated
  2. Compound ignores the new reported prices and continues operating with the outdated price
  3. Exploiters take out UNI loans with less collateral that should be possible at correct prices
  4. Protocol accrues bad debt.

What would have happened to Revert Lend:

  1. Price increase on UNI suddenly and drastically and chainlink feed had the correct price but univ3 TWAP is outdated
  2. Revert lend pauses any new loans and liquidations
  3. Borrowers with UNI collateral now have healthier positions.
  4. No new borrows or liquidations are possible until the TWAP catches up with the chainlink price (e.g. 1 minute)
  5. All good.

While it's true that there is a risk where in the inverse case, when the price of a collateral asset crashes suddenly and the TWAP price lags, liquidations will be halted potentially putting the protocol in a bad debt state for a subset of positions. We believe this an acceptable trade-off given our TWAP period length, and collateral asset caps, in order to not solely depend on chainlink as the only price source. You will notice that, for example Maker, has a longer threshold for price updates than our TWAP period.

#6 - c4-sponsor

2024-03-27T20:20:47Z

mariorz (sponsor) disputed

#7 - jhsagd76

2024-03-30T23:48:16Z

I believe that the warden, the sponsor, myself have no technical misunderstanding regarding this issue, and I don't think it meets the criteria for an H/M severity level.

For an H severity, the rules require the issue to be able to cause definite loss to the protocol without harsh preconditions. This issue has very rare preconditions and clearly does not meet the standard for high severity.

Secondly, for an M level, we require the issue to cause a functional disruption to the protocol. We all understand that TWAP is designed to work this way, and the sponsor has also explained that their use of and the risks associated with TWAP are completely in line with expectations and design. Therefore, I don't believe it really breaks any functionality.

#8 - c4-judge

2024-03-30T23:49:13Z

jhsagd76 changed the severity to QA (Quality Assurance)

#9 - jhsagd76

2024-03-30T23:49:37Z

N

#10 - c4-judge

2024-03-31T03:47:34Z

jhsagd76 marked the issue as grade-b

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