Cointime

Download App
iOS & Android

A Detailed Analysis of Euler Finance’s $197 Million Flash Loan Attack

Validated Project

On 13 March 2023 at 08:56:35 AM +UTC, DeFi lending protocol Euler Finance experienced a Flash Loan Attack.

Euler Finance is a protocol that operates as a permissionless lending protocol. Its primary goal is to facilitate lending and borrowing of various cryptocurrencies for users. The UK-based tech startup utilizes mathematical principles to develop non-custodial protocols on Ethereum and other blockchain networks, with a focus on achieving high performance.

Based on on-chain data analysis, the attacker has successfully executed multiple transactions resulting in the theft of approximately $197 million, making it the largest hack of 2023 thus far. Stolen assets include several million worth of DAI, USDC, Staked Ether (StETH), and Wrapped Bitcoin (WBTC).

The breakdown of the stolen assets are as follows:

Detailed Analysis

The attack was possible due to a lack of liquidity checks in the donateToReserves function of the Etoken. The attacker executed multiple calls with different currencies to generate profit, resulting in a massive loss of $196 million across six different tokens. 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: https://etherscan.io/tx/0xc310a0affe2169d1f6feec1c63dbc7f7c62a887fa48795d327d4d2da2d6b111d

1. The attacker first borrowed 30 million DAI through a flash loan from Aave and then deployed two contracts: one for lending and one for liquidation.

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.

3. The Euler Protocol allows users to borrow up to 10 times their deposit by calling the mint function. The attacker leveraged this capability to borrow 195.6 million eDAI and 200 million dDAI.

4. The attacker called the repay function using the remaining 10 million DAI borrowed through the flash loan to repay their debt and destroy 10 million dDAI. They then proceeded to call the mint function again to borrow 195.6 million eDAI and 200 million dDAI.

5. The attacker then called the donateToReserves function and donated 10 times the amount needed to repay their debt, sending 100 million eDAI. They then called the liquidate function to initiate the liquidation process and obtained 310 million dDAI and 250 million eDAI.

6. The attacker called the withdraw function and obtained 38.9 million DAI, which they used to repay the 30 million DAI borrowed through the flash loan. They profited 8.87 million DAI from the attack.

Core Vulnerability

First, let’s take a look at the donateToReserves function, which is where users become vulnerable to liquidation.

Comparing the donateToReserves function to the mint function in the diagram below, we can see that a key step, checkLiquidity, is missing from the donateToReserves function.

Next, we followed up and examined the implementation of checkLiquidity. We discovered the Call InternalModule function, which calls the RiskManager to check and ensure that Etoken > Dtoken for the user.

It is necessary to check the user’s liquidity each time an operation is performed by calling checkLiquidity.

However, the donateToReserves function does not execute this operation, allowing users to first put themselves in a state of liquidation through certain functions of the protocol, and then complete the liquidation.

Attack Reproduction

The Numen Cyber Lab’s team has managed to reproduce the attack.

You may find out more details on the PoC at https://github.com/numencyber/SmartContractHack_PoC/tree/main/EulerfinanceHack

Conclusion

Euler Finance have confirmed the attack on their official Twitter (@eulerfinance) and have stated that they are currently collaborating with security professionals and law enforcement to address the issue.

The recent attack on the Euler Finance protocol highlights the importance of implementing rigorous security measures, such as conducting thorough audits and regularly checking for vulnerabilities.

As the decentralized finance ecosystem continues to grow, it is crucial for projects to prioritize the security of their users’ funds and adopt best practices to mitigate the risk of similar attacks in the future.

Note

This article was originally posted on our website’s blog. Subsequent articles will be posted first on our website and Medium after a slight delay.

Please stay tuned and follow our Twitter @numencyber for any future updates.

Comments

All Comments

Recommended for you

  • Taiwan’s Ministry of Interior has approved the establishment of a cryptocurrency industry association

    Taiwan's Ministry of the Interior has approved the application of the local cryptocurrency industry to establish an industry association. The local cryptocurrency industry working group, which was established last year to prepare for the establishment of the industry association, said that the working group now needs to complete all preparations and officially establish the cryptocurrency industry association by the end of June as required by the government. The working group is currently composed of 22 cryptocurrency companies, including Taiwan's major exchanges such as MaiCoin and BitoPro. The working group pointed out that ACE Exchange has been expelled from the group because the troubled exchange is under investigation by prosecutors for improper behavior by its former executives.

  • Grayscale ETH Trust negative premium rate is 22.77%

    According to ChainCatcher news and Coinglass data, the Grayscale Bitcoin Trust Fund (GBTC) has a premium rate of 0.02%. The Grayscale ETH Trust has a negative premium rate of 22.77%, and the ETC Trust has a negative premium rate of 36.58%.In addition, the Grayscale BCH Trust has a premium rate of 238.13%, the LTC Trust has a premium rate of 380.60%, the SOL Trust has a premium rate of 515.93%, the MANA Trust has a premium rate of 726.65%, the LINK Trust has a premium rate of 713.66%, and the FIL Trust has a premium rate of 3057.89%.

  • Net inflows into spot Bitcoin ETFs reached $179 million on March 28

    Spot on Chain, a blockchain data monitoring platform, posted on social media that the net inflow of spot bitcoin ETF on March 28th reached 179 million US dollars, a decrease of 26.9% compared to the previous trading day. After 54 trading days, the total net inflow accumulated to 12.13 billion US dollars, which is the level before the last fully negative trading week. BlackRock's iShares Bitcoin ETF (IBIT) and Grayscale's GBTC both saw a significant slowdown in daily inflows and outflows on March 28th.

  • Bitcoin spot ETF had a total net inflow of US$179 million yesterday, and the ETF net asset ratio reached 4.25%

    According to SoSoValue data, the Bitcoin spot ETF had a total net inflow of $179 million yesterday (March 28th, US Eastern Time).Yesterday, Grayscale's ETF GBTC had a net outflow of $104 million, and its historical net outflow is $14.77 billion. The Bitcoin spot ETF with the highest net inflow yesterday was BlackRock's ETF IBIT, with a net inflow of approximately $95.12 million, and its historical total net inflow has reached $13.96 billion. The second is Fidelity's ETF FBTC, with a net inflow of approximately $68.09 million yesterday, and its historical total net inflow has reached $7.56 billion.As of now, the total net asset value of Bitcoin spot ETF is $59.1 billion, and the ETF net asset ratio (market value compared to the total market value of Bitcoin) is 4.25%, with a historical total net inflow of $12.12 billion.

  • Ethereum Inscription ETHS rose over 95% in 24H

    CoinGecko data shows that Ethereum Inscription ETHS has risen by 95.9% in the last 24 hours, now reporting at 7.51 USDT. Earlier, Ethereum founder Vitalik released the latest long article "Ethereum has blobs. Where do we go from here?". As a result of this news, the price of Ethereum Inscription ETHS soared.

  • Binance exec sues Nigeria’s National Security Agency over detention

    According to CoinGape, Tigran Gambaryan, a detained executive of Binance, has filed a lawsuit against the National Security Adviser (NSA) and the Economic and Financial Crimes Commission (EFCC) in Nigeria. Local media reported that on March 28th, Tigran Gambaryan sued the National Security Agency, accusing it of violating his basic human rights and seeking five major remedies from the court.He urged the court to approve the return of his passport and to release him immediately after more than three weeks of detention. He also requested a ban on future detention in similar investigations and demanded public apologies from the National Security Agency and the EFCC.In addition, he requested that the court pay the full amount of compensation for the lawsuit.

  • Vitalik: As L2 transaction costs decrease, there’s no reason why Ethereum can’t be widely adopted

    After the upgrade and introduction of blobs on Ethereum Dencun, Ethereum founder Vitalik Buterin shared his insights on the future direction of Ethereum's expansion. Vitalik emphasized the transformation of Ethereum's expansion from basic expansion work to centralized, progressive enhancement. Vitalik also stated that developers' focus will shift to the application layer. Ethereum will maintain its roadmap centered on L2, and applications will migrate from L1 to L2 to benefit from faster and more cost-effective transactions. An upcoming upgrade is Data Availability Sampling (DAS), which aims to increase the data space for each slot to 16 MB. Progressive expansion improvements include gradually increasing blob capacity, improving data compression, and EIP-7623 (aimed at reducing maximum block size). Vitalik pointed out that with the reduction of L2 transaction costs, there is no reason why Ethereum should not be widely adopted.

  • RWA project Midas completes US$8.75 million in seed round financing

    According to Jinse Finance, RWA project Midas has completed a seed round of financing worth $8.75 million, led by BlockTower, Framework, and HV Capital, with participation from institutions such as Coinbase Ventures, Ledger, GSR, Hack VC, Axelar, and FJ Labs.

  • Two Different Sentences for FTX Founder Sam Bankman-Fried: 25 Years and $11 Billion vs. 16 Months and $8 Billion Losses

    The founder of FTX, Sam Bankman-Fried, has been sentenced to 16 months in prison and charged with eight criminal counts, including money laundering and conspiracy. He was involved in a scheme that caused customers to lose $8 billion and allegedly diverted customer funds to Alameda. Bankman-Fried's lawyers had requested a lighter sentence, but the judge rejected their argument that the collapsed company had vowed to return money to its customers. Prosecutors had sought up to 50 years in prison for Bankman-Fried.

  • SBF ordered to forfeit more than $11 billion

    SBF has been ordered to confiscate more than 11 billion US dollars. SBF has now been sentenced to 25 years in prison.