Smart contract vulnerability case, Euler Finance’s $196 million flash loan vulnerability analysis

Smart contract vulnerability case, Euler Finance’s $196 million flash loan vulnerability analysis

At 08:56:35 am +UTC on March 13, 2023, the DeFi lending protocol Euler Finance suffered a flash loan attack.
Euler Finance is a protocol that operates as a permissionless lending protocol. Its main goal is to provide users with lending facilities in various cryptocurrencies. The UK-based tech startup uses mathematical principles to develop non-custodial protocols on Ethereum and other blockchain networks, with a focus on achieving high performance.
According to on-chain data analysis, attackers have successfully executed multiple transactions, resulting in the theft of approximately $196 million, making it the largest hacking attack so far in 2023. Stolen assets include millions worth of DAI, USDC, Staked Ether (StETH) and Wrapped Bitcoin (WBTC).
The details of the stolen assets are as follows:

Detailed analysis

The attack may occur due to the lack of liquidity check in Etoken's donateToReserves function. The attacker performed multiple calls using different currencies to generate profits, resulting in a massive loss of $196 million across six different coins. Currently, the funds remain in the attacker's account.
The attacker's address is: https://etherscan.io/address/0xb66cd966670d962c227b3eaba30a872dbfb995db
The attacker's contract address is: https://etherscan.io/address/0x036cec1a199234fc02f72d29e596a09440825f1c
One of the attack transactions can be found here Found: https://etherscan. io/tx/0xc310a0affe2169d1f6feec1c63dbc 7 f7c62a887fa48795d327d4d2da2d6b111d

  1. The attacker first borrowed 30 million DAI from Aave through flash loans, and then deployed two contracts: one for lending and one for liquidation.
    image.png
  2. The attacker then called the deposit function and pledged 20 million DAI to the Euler protocol contract, receiving 19.5 million eDAI in return.
    image.png
  3. Euler Protocol allows users to borrow up to 10 times their deposit by calling the mint function. The attacker used this feature to borrow 195.6 million eDAI and 200 million dDAI.
    image.png
  4. The attacker calls the repay function, uses flash loan to borrow the remaining 10 million wDai to repay the debt, and destroys 10 million dDAI. Then they called the mint function again to borrow 195.6 million eDAI and 200 million dDAI.
    image.png
  5. The attacker then called the donateToReserves function and donated 10 times the amount needed to repay the debt, sending 100 million eDAI. Then they called the liquidate function to start the liquidation process and obtained 310 million dDAI and 250 million eDAI.
    image.png
  6. The attacker called the withdraw function and obtained 38.9 million DAI, which was used to repay the 30 million DAI borrowed from the flash loan. They made a profit of 8.87 million DAI from this attack.
    image.png

core vulnerability

First, let's look at the donateToReserves function, this is where users tend to get liquidated.
image.png
Comparing the donateToReserves function and the mint function in the figure below, we can see that there is a key step missing in the donateToReserves function, checkLiquidity.
image.png
Next, we followed up and checked the implementation of checkLiquidity. We found the Call InternalModule function, which calls the RiskManager to check and make sure the user's Etoken > Dtoken.
image.png
Each operation requires checking the user's liquidity and calling checkLiquidity.
However, the donateToReserves function does not perform this operation, allowing the user to first put himself in the liquidation state through certain functions of the protocol, and then complete the liquidation.

Official update on the attack

Euler Finance has confirmed the attack on its official Twitter (@eulerfinance) and said they are currently working with security professionals and law enforcement to resolve the issue.
image.png
Euler Finance recently updated their efforts to recover funds for protocol users. They outlined several actions they had taken since the attack, including stopping the direct attack as quickly as possible by disabling the EToken module, which blocked deposits and vulnerable donation functionality.
Additionally, they work with various security organizations such as TRM Labs, Chainalysis, and the broader Ethereum security community to assist with investigations and recovery of funds. Euler Finance also shares information with law enforcement authorities in the United States and the United Kingdom.
Finally, the company attempted to contact the attackers to learn more about potential recovery options.
image.png

in conclusion

The recent attack on the Euler Finance protocol highlights the importance of implementing strict security measures, such as conducting thorough audits and regularly checking for vulnerabilities.
As the decentralized finance ecosystem continues to evolve, projects must prioritize the security of user funds and adopt best practices to reduce the risk of similar attacks in the future.

Guess you like

Origin blog.csdn.net/weixin_28733483/article/details/132898504