The theft of $160,000 in assets was an oolong incident? Brief Analysis of Yeld.finance "Flash Loan Attack" Event
成都链安
2021-02-28 08:36
本文约1576字,阅读全文需要约6分钟
$160,000 in assets stolen? False alarm.

1. Event overview

1. Event overview

https://yeldf.medium.com/the-yeld-dai-earn-vault-has-been-hacked-93f27d475b1b 

On February 27, 2021, Beijing time, public opinion monitoring of [Chain Bi’an-Blockchain Security Situational Awareness Platform (Beosin-OSINT)], Yeld.finance, a well-known DeFi project, issued an official announcement stating that the project’s DAI pool was hit by lightning Loan attack, the original link is as follows:

2. Event analysis

2. Event analysis

image description

As shown in Figure 1, the transaction is for a user named 0xf0f225e0, who called the deposit function of the 0xe780cab7ca8014543f194fc431e6bf7dc5c16762 contract. It has been confirmed that the 0xef80cab7 contract is the DAI pool of the project party. This transaction generated a total of 6 token transfers, denoted by T1 to T6 respectively. So, what exactly caused these token transfers? Analyze the code below:

image description

△Figure 2 deposit function source code

Obviously, the 538th line of code generates the token transfer with the sequence number T1, transferring the token (that is, DAI) to the yDAI contract. This is an ordinary token transfer, indicating that the user deposited 9,377 DAI into the yDAI contract.

Then enter the rebalance function on line 555 to analyze the logic of the function.

△Figure 3 rebalance function source code

image description

Line 732 of the code will calculate newProvider, which will call the recommend function (as shown in Figure 4), and the recommend function will call the IEarnAPRWithPool contract to query the project with the highest annual interest rate (APR) among the 4 Defi projects DYDX, COMPOUND, AAVE, and FULCRUM , the query result is shown in Figure 5:

image description

Among them, dYdX pool has the highest APR, and newProvider is set to dYdX pool. The current pool is the AAVE pool, enter the if code block on line 736, and call the internal function _withdrawAll.

image description

△Figure 6 _withdrawAll function source code

The 778th line of code will propose all the DAI in the AAVE pool, resulting in a token transfer with the serial number T3-T5. For the specific code, please refer to the code related to the redeem function of the AAVE (0xfC1E690f61EFd961294b3e1Ce3313fBD8aa4f85d) contract, which will not be described in detail here.

The last line is the 741st line of code, which deposits more than 166,000 DAI from AAVE into the dYdX contract, and generates a token transfer with the serial number T6, which means depositing 166,000 DAI into the dYdX pool.

It is worth noting that dYdX played the role of a "conscience merchant" in this incident, and was not an accomplice in previous flash loan attacks.

3. Security Recommendations

3. Security Recommendations

Although this incident was judged to be false after analysis by the security team of Chengdu Chain Security (Beosin), it is still necessary to remind all project parties that it is still necessary to provide early warning and protection against flash loan attacks in daily security protection work. Take precautions.

成都链安
作者文库