Cointime

Download App
iOS & Android

2022 Year in Review: Lending Protocols

Validated Project

DeFi lending is relatively straightforward. Lenders deposit cryptocurrencies to the lending pool and earn interest on the assets they deposit. The borrower can provide collateral on the platform in exchange for the right to borrow other assets provided by the lender. Lending platform utilizes price oracle to determine the value of collateral to calculate the amount of assets that can be borrowed. When the value of the collateral drops below a certain threshold, liquidators can repay the debts of the borrower and receive the liquidation reward.

Mango Market Exploit

On October 11, 2022, Mango Market on Solana was attacked, causing $116m in bad debt. The attacker exploited a vulnerability that allowed projects to use low-liquidity tokens as collateral, and borrowed more assets on the platform than he was supposed to.

MNGO was only offered on a couple of centralized exchanges (CEXs) meaning there were very few markets with any meaningful liquidity. One of the oracle Switchboards uses Raydium as a price feed, and the following snapshot was taken on Radium. It describes the extremely poor liquidity in the MNGO/USDC pair on radium. Although Mango uses a price oracle and TWAP, a sophisticated and well-capitalized attacker would be able to spoof liquidity, especially if a token is only offered on a few exchanges.

The attacker used the first account to offer 483M units of MNGO perps (short) on the order book using over $5 million in tokens deposited into the protocol. Then the attacker used the second account to buy 483M units of MNGO perps (long), at a price of $0.0382 per unit, which raised the spot price. The market continued to raise the price, peaking at $0.91 per unit. The peak price resulted in the second account achieving a profit of approximately $423 million and allowed the second account to borrow many other valuable assets. The attacker then used the second account to take out a loan of $116 million, draining the liquidity from the protocol. The price then dropped to about $0.02 per unit, which put the first account also in profit and would have allowed another drain if any valuable assets were available.

After draining all liquidity, the attacker left the first account with a total value of $11,306,771.61 uncollectible debt and the second account with $115,182,674.43 bad debt.

For a full analysis of the Mango exploit, see here.

Deus Finance Exploit

On April 28, 2022, Deus Finance was exploited, leading to a loss of around $15.7M. The attacker manipulated the price of DEI and withdrew a large amount of DEI from the DeiLenderSolidex contract while only providing a small amount of collateral. It’s the second attack on Deus in 2022.

Above is the snapshot of the DeiLenderSolidex implementation, the on-chain price here is the price of a pairing pool, and the input price is the VWAP price coming from Muon oracle. The hacker needed to manipulate the off-chain oracle (Muon oracle) as well as the on-chain price feed. The Muon oracle monitors transactions within the Solidly USDC/DEI pool to calculate the Volume Weighted Average Price (VWAP). A series of flash-swaps inside the same pool outputs a manipulated price, which is read by the Muon oracle. The root cause of this exploit is that the muon oracle implementation only used Solidly as a price source. The swap used flashswap() that wasn’t filtered out properly by Muon, leading to a short-term VWAP price discrepancy.

Inverse Finance

On April 02, 2022, Inverse Finance was exploited, leading to ~$14.5M worth of asset loss. The root cause is the price manipulation in the external price oracle dependency. The attacker is able to manipulate the price and borrow assets at the tilted price.

Inverse used a Keep3r oracle, which relied entirely upon DEX price data. It relies upon a TWAP oracle generated from a single thinly traded DEX trading pair with a 30-min time window to mitigate market manipulation risks. The attacker is able to bypass this restriction by submitting two transactions in a very short time period (~15s) so that the current reserve is used to calculate the price.

The attacker first deploys a malicious contract to manipulate the price of INV / XINV in SushiSwap/Curve.fi SushiSwap:INV (INV-ETH Pair). They then deposited the INV above and minted 1746(374+1372) XINV tokens. Since the price of XINV was calculated based on the reserve in SushiSwap:INV (INV-ETH Pair), the price of INV was manipulated and thus each XINV worthed $20926(346*3444/57.7).

Therefore, with the price of XINV being tilted, the attacker was able to borrow assets as his profit with the minted XINV tokens. The borrowed assets include 1588 ETH, 94 WBTC, 3999_669 DOLA and 39 YFI; approximately $14.5M worth of assets was stolen and transferred to Tornado Cash.

We also performed a thorough analysis on this incident a few months ago.

Cashio Exploit

On March 23, 2022, the Solana-based Cashio stable coin CASH was exploited by the type of “infinite mint” vulnerability, leading to ~$50 M worth of asset loss. The root cause stems from the verification design. Lacking necessary validation for common.crate_collateral_tokens and depositor_source, the attacker is able to inject fake accounts to bypass the verifications and mint Cash tokens.

To mint new CASH tokens, a user needs to deposit collateral. The correctness of the minting process relies on the implicit validation that users need to first transfer “collateral” to the project. In the validation process for crate_collateral_tokens, the contract checked if the token type matched that of the saber_swap.arrow account.

However, there was no validation of the mint field, as shown in the following checks within the saber_swap.arrow account. The attacker could create a fake saber_swap.arrow account, which would further allow it to create a fake crate_collateral_tokens account and allow the deposit of fake collateral.

Another aspect of the attack involved a missing check for the depositor_source, which is supposed to ensure that the token type being deposited matches the collateral.

Users can set the collateral token type by owning a bank, which can be created using the crate_mint function without restriction, and the system failed to confirm that the token associated with the bank and the one being minted were the same.

Therefore, the attacker was able to create a fake bank and deposit worthless collateral, allowing him to mint real CASH tokens and drain the fund from the protocol. This resulted in a $52 million hack and the collapse of the stablecoin's value.

Fei Protocol Exploit

On April 30, 2022, Fei Protocol announced that they were aware of and looking into a reentrancy attack on various Rari Fuse pools. The total loss is about $80 Million. The attacker took advantage of the vulnerable borrow function. The exitMarket function verifies that a deposit is no longer used as collateral for a loan and then allows it to be withdrawn. However, the borrow() function does not follow the check-effect-interaction pattern and transfers ETH to the attacker’s contract before updating the attacker’s borrow records.

As the above code illustrates, the “doTransferOut()” is invoked before the borrow records are updated. The doTransferOut() function transfers ETH to the receiver via a low-level call. When the borrow function sends the loaned amount to the borrower, it has not yet updated its internal state to reflect the fact that the deposited asset is currently being used as collateral. With the attacker’s borrow record not updated, the attacker made a reentrant call to exitmarket() that allows the attacker to withdraw their collateral (150M USDC).

Full analysis here.

Fantasm Exploit

On March 09, 2022, Fantasm Finance's collateral reserve pool got exploited, leading to a loss of $2.7m. The attacker took advantage of a flaw in the error-checking code _minFtmIn of the protocol’s mint function.

The purpose of the error-checking code was to ensure that a user deposited FTM tokens into the contract when minting XFTM tokens. Based on the implementation, if only FSM is invested, the amount of xFTM coinage is calculated according to the proportion of FSM. The part beyond the proportion of FSM needs to be made up by FTM. However, the code actually compared with msg.value, which measures the amount of ETH sent along with a transaction, to the minimum amount of FTM tokens that would be accepted for minting. In the first red box, the important _minFtmIn parameter is ignored and the variable is not even declared, only the FSM is needed (the second red box). When only FSM is invested, there is no need to replenish FTM collateral. If FSM accounts for 10%, then 10u xFTM can be minted with 1u FSM.

As a result, the attacker was able to mint XFTM tokens when depositing only a fraction of their true value. The minted XFTM tokens were then sold back to the project, enabling the attacker to extract value from the protocol and buy more FSM tokens for follow-on attacks.

How to Protect Lending Protocols

Two thousand twenty-two was a dark year for the security of the global blockchain industry. Attacks on lending protocols have caused more than 300 million dollar loss in 2022, according to our statistical result. This leads to a greater and more pressing demand for security expectations in the following years.

Add Flashloan Protection

Flashloans allow anyone to take out large loans without collateral. They have been used in incidents that have resulted in significant losses. To mitigate this risk, developers should consider limiting the use of flashloans by only allowing non-contract addresses to interact with the contract, if possible. Another measure to prevent the abuse of flashloans is to prevent critical transactions from occurring within the same block. This can effectively eliminate the risk associated with flashloan attacks.

Add Reentrancy Protection

Reentrancy is a relatively common vulnerability in smart contracts. Reentrancy can lead to significant consequences such as draining the lending pool and manipulating borrow records, especially when combined with other vulnerabilities. To protect reentrancy, projects can use the reentrancy guard provided by OpenZeppelin and follow the check-effect-interaction pattern.

Select a Robust Oracle

Avoid using oracles that only depend on single pair price, as it only takes one pool to manipulate the price feed. The oracle should be able to filter out obscure swaps and to use multiple data sources. Recommended oracles such as Chainlink or Band Protocol can limit the impact of obviously inaccurate values from DEXs.

Be Cautious When Selecting Collateral Tokens

From an economic perspective, it is recommended to limit or not to offer leverage on illiquid tokens. Using highly volatile tokens to be collateral can increase the overall risk, since when the token price fluctuates significantly, the value of the collateral changes greatly. This increases the chances of an economic attack, like the case of Mango Market, and it also affects the overall health of the system. If the value of the overall collateral is too low, the system may not be able to operate normally.

Be Aware of Contract Configurations

Although auditing smart contracts can eliminate many human errors and ensure consistency, there are still sensitive parameters in lending protocols that require manual configuration. Improperly setting these parameters can result in severe consequences, like wrongly configured oracle contracts would feed wrong data. Developers and project operators should exercise an abundance of caution when configuring these parameters.

Comments

All Comments

Recommended for you

  • Vitalik: Ethereum Foundation is Not the Central Manager of the ETH Ecosystem, Future Development Will Shift to 'Small and Long-term' Approach

    On May 25, Ethereum founder Vitalik shared his views on the future development direction of the Ethereum Foundation in a post on the X platform. He emphasized that this is just his personal opinion. The board does not consist solely of him, and he does not have more special powers than other board members. Aya Miyaguchi is leading most of the execution work for this transformation, while his own involvement is more focused on technical issues. The board is currently expanding, and his influence within the organization will continue to decline in the future, which, frankly, is what he hopes to see. By 2025, the Ethereum Foundation has made significant improvements in its execution capabilities. Many issues have been resolved, and the foundation continues to benefit from greater efficiency and a stronger focus on specific goals. However, as these issues were addressed, he began to care more about another concern: he often sees people saying, 'Vitalik has always talked about Ethereum needing to be decentralized, having privacy, and becoming a shelter technology, but why do the actions of the Ethereum Foundation not reflect these ideals?' Of course, there are those who hold completely different views. Some do not feel there is a crisis at all, but rather believe that the Ethereum Foundation has finally begun to take execution and business development seriously, and the next focus should be to continue along this path faster and stronger. Vitalik believes that this difference essentially reflects varying sensitivities to different types of criticism, and he is more easily hurt by criticisms regarding deviations from values. Vitalik stated that the Ethereum Foundation should not be 'the center of Ethereum,' but rather 'a node with clear responsibilities, existing alongside other nodes.' In the past, they have always said this, but many people in the ecosystem, including some within the foundation, hoped the foundation would become a true center. Now, they are taking concrete actions to ensure the foundation becomes the latter. This is particularly important because the Ethereum Foundation is essentially a resource-limited and organizationally limited entity. The foundation currently holds only about 0.16% of all ETH, which is even lower than many large ETH holders; whereas many other blockchain projects' 'central foundations' typically control 10%-50% of their tokens. The current Ethereum Foundation has decided to use its remaining resources to pursue 'long-term viability' rather than continuous expansion (which also means they will sell less ETH). The foundation will focus on those things that are crucial for Ethereum to become a censorship-resistant, control-resistant, open, private, and secure system, but that no one else would do if the foundation does not. This means they must make difficult choices. Some projects and individuals they highly respect may no longer belong to the foundation's system in the future. In fact, if they want important tasks to attract external capital, it may be necessary to keep some talented individuals, influential public figures, and those who share the mission and CROPS philosophy outside the foundation. This also means that the Ethereum Foundation will take a clearer and more principled stance on a cultural level.

  • ETH Surpasses $2100

    Market data shows that ETH has surpassed $2100, currently priced at $2101.04, with a 24-hour increase of 1.9%. The market is experiencing significant volatility, so please ensure proper risk management.

  • U.S. Officials: Agreement with Iran Expected Not to Be Signed on Sunday, Some Issues Remain

    On May 24, Axios reported, citing a U.S. official, that Iran's Supreme Leader has approved the overall framework of the agreement. There are some important statements for us and some significant wording for Iran. It is expected that the agreement with Iran will not be signed on Sunday, as there are still some issues that need to be resolved. The current status of the Iranian regime is progressing slowly, and completing the necessary approvals will take a few days.

  • ETH Falls Below $2100

    Market data shows that ETH has fallen below $2100, currently priced at $2096.81, with a 24-hour increase of 2.47%. The market is experiencing significant volatility, so please ensure proper risk management.

  • PAYS Officially Launches on Nivex, Surges 100% on Debut

    At 15:18 on May 24, 2026, PAYS officially launched on the Nivex exchange and opened for trading globally.

  • U.S. Secretary of State: Announcement on Agreement with Iran Possible Later Sunday

    On May 24, U.S. Secretary of State Rubio stated that an announcement regarding an agreement with Iran may be made later on Sunday.

  • BTC Surpasses $77,000

    Market data shows that BTC has surpassed $77,000, currently priced at $77,073.6, with a 24-hour increase of 1.32%. The market is experiencing significant volatility, so please ensure proper risk management.

  • Trump: Calls with Multiple World Leaders, Iran Agreement Nearly Finalized

    On May 24, Trump stated on social media that he had "very good calls" in the Oval Office with leaders from Saudi Arabia, the UAE, Qatar, Pakistan, Turkey, Egypt, Jordan, Bahrain, and others regarding Iran and a peace memorandum. Trump claimed that the agreement has been largely negotiated and is pending finalization by the U.S., Iran, and other relevant countries. Additionally, his call with Israeli Prime Minister Netanyahu was also "very smooth." The final details of the agreement are under discussion and will be announced soon. Trump specifically noted that, in addition to several aspects of the agreement, the Strait of Hormuz will be opened.

  • BTC Surpasses $76,000

    Market data shows that BTC has surpassed $76,000, currently priced at $76,001.27, with a 24-hour increase of 0.05%. The market is experiencing significant volatility, so please ensure proper risk management.

  • US and Iran Expected to Announce Final Peace Agreement Within 24 Hours

    On May 24, according to the Washington Times citing sources close to the negotiations, the United States and Iran are expected to announce the finalization of a peace agreement within 24 hours after negotiating representatives approved a draft agreement to end all combat on the front lines. The agreement still awaits final approval from both governments.