Sitemap

An Analysis of the Attack on Yearn Finance

4 min readMay 8, 2023
Press enter or click to view image in full size

According to SlowMist Zone Intelligence, on April 13, 2023, the decentralized yield aggregation platform Yearn Finance was attacked, resulting in the theft of over ten million dollars for the project. The SlowMist Security Team shares the following insights.

Relevant Information

Yearn’s yUSDT contract is designed with aUSDT, dydx positions, iUSDC, and cUSDT reserves. When users deposit or withdraw, the corresponding share or required deposit amount is calculated based on the reserve balances.

Cause of Attack

The attack was caused by the attacker exploiting an incorrect setting of the fulcrum address in the yUSDT contract, manipulating the stablecoin reserve balance within the yUSDT contract, allowing the attacker to profit by depositing USDT into yUSDT and receiving an unexpectedly large number of yUSDT tokens.

Press enter or click to view image in full size

Detailed Analysis

1. The attacker began by borrowing a large amount of DAI, USDC, and USDT through flash loans, then exchanged DAI and USDC for USDT using Curve’s ySwap to deplete aUSDT reserves in the yUSDT contract.

2. The attacker then repaid debts for users with negative balances on Aave Pool v1, aiming to increase the amount of USDT in Aave Pool v1 so that aUSDT in yUSDT could be redeemed smoothly.

Press enter or click to view image in full size

3. Next, the attacker called the yUSDT contract’s deposit function to deposit USDT, receiving the corresponding yUSDT tokens. This prepared for clearing the aUSDT reserves in yUSDT through the withdraw function later.

4. To ensure that the aUSDT reserves in yUSDT could be cleared during the withdraw process, the attacker called the iUSDC contract’s mint function to mint iUSDC, and then directly transferred the iUSDC to the yUSDT contract, increasing the reserve depth for the yUSDT contract.

Press enter or click to view image in full size

5. The attacker then called the withdraw function of yUSDT contract to withdraw money. Since the provider was specified as AAVE, yUSDT would redeem USDT to the drawer through Aave Pool v1.

6. Since the attacker had previously increased the reserves in the contract through iUSDC, the aUSDT reserves in yUSDT could be completely emptied in this withdrawal.

Press enter or click to view image in full size

7. At this point, the aUSDT, dydx positions and cUSDT reserves in yUSDT contracts were manipulated to 0. Finally, to empty the iUSDC reserves, the attacker called the yUSDT contract’s rebalance function to update the reserves.

8. As only iUSDC remained in yUSDT, the contract’s new provider would be directed to iUSDC, causing the Rebalance function to perform _withdrawAll operation before updating reserves using the remaining balance.

Press enter or click to view image in full size

9. The _withdrawAll operation burned the iUSDC to get the USDC token. However, when the reserve was updated, the balance of USDT in the yUSDT contract was used. Therefore, the fulcrum reserve was misdirected to iUSDC, causing the yUSDT contract reserve to be manipulated to 0.

10. The attacker transferred 1 wei of USDT into the yUSDT contract in order to ensure that he could obtain a large amount of yUSDT through deposits.

Press enter or click to view image in full size

11. Finally, the attacker called yUSDT’s deposit function, deposited 10,000 USDT, obtained 1,252,660,242,850,000 yUSDT, and changed yUSDT into a large number of yDAI, yUSDC, yTUSD through curve.

Summary

The attack was caused by the misconfiguration of Yearn Finance’s yUSDT contract. The SlowMist Security Team recommends that when configuring the protocol, all parameters should be carefully checked as expected and adequate testing should be performed to ensure the security of the protocol.

Reference link:

About SlowMist

SlowMist is a blockchain security firm established in January 2018. The firm was started by a team with over ten years of network security experience to become a global force. Our goal is to make the blockchain ecosystem as secure as possible for everyone. We are now a renowned international blockchain security firm that has worked on various well-known projects such as Huobi, OKX, Binance, imToken, Crypto.com, Amber Group, Klaytn, EOS, 1inch, PancakeSwap, TUSD, Alpaca Finance, MultiChain, O3Swap, etc.

Website:
https://www.slowmist.com
Twitter:
https://twitter.com/SlowMist_Team
Github:
https://github.com/slowmist/

SlowMist
SlowMist

Written by SlowMist

SlowMist is a Blockchain security firm established in 2018, providing services such as security audits, security consultants, red teaming, and more.