The real risk of Bad Debt illustrated on CompoundV2
On 23th of february, the @Compound protocol gained (estimations range between 500k and 3 million) bad debt.
But how did that happen?
Let's break down the series of events and mechanisms that led to this situation in a manner that's both engaging and easy to understand.
The Role of Oracles and TWAP in CompoundV2
At the heart of CompoundV2's strategy for ensuring accurate and reliable price information is its dual use of Chainlink's oracle service along with Uniswap's Time-Weighted Average Price (TWAP) as an additional safeguard. Typically, Chainlink provides real-time price feeds that are crucial for the platform's operations, such as lending and borrowing activities. The TWAP, on the other hand, serves as a failsafe mechanism. Unlike instant price snapshots, TWAP calculates the average price over a designated period, aiming to mitigate the impact of price manipulation or faulty oracle prices
The Uniswap Token's Valuation Spike
The plot thickens with a governance proposal within the Uniswap community to activate the fee switch:
This decision had a dramatic effect on the valuation of the Uniswap token (UNI), propelling it from $7.2 to over $11 in a very short period. Such a sharp increase is not uncommon in the crypto world but posed a unique challenge for CompoundV2.
The Discrepancy and Exploitation:
Herein lies the crux of the problem: While the real market valued UNI at $11, CompoundV2's system lagged, still pegging it at $7.2 due to the TWAP mechanism's failsafe. This discrepancy didn't go unnoticed.
MEV bots, which are programmed to exploit price inefficiencies across DeFi platforms abused this price discrepancy.
By borrowing UNI tokens at the outdated price of $7.2, despite their actual market value being $11, these bots were able to game the system.
Example:
A user could deposit 100 USDC as collateral and borrow 10 UNI, which CompoundV2 valued at $72, yet in reality, the market valued the same UNI at $110.
This can be further amplified by selling the UNI, redepositing USDC and then again borrowing UNI.
This discrepancy introduced bad debt into the protocol, as the actual value received far exceeded the system's valuation.
The Ripple Effect
This situation didn't only affect new transactions. Existing positions that should have been liquidated under normal circumstances remained untouched due to the rapid price jump, a larger borrow than collateral value moreover removed the incentive to pay back the loan. The mechanism designed to protect against price manipulation inadvertently opened a window for exploitation, highlighting a critical risk inherent to lending protocols.
Concluding Thoughts:
This incident with CompoundV2 underscores the complexity and challenges of managing lending protocols. It serves as a potent reminder of the delicate balance between security mechanisms and the need for timely, accurate data in a market known for its volatility.