On March 14th, 2023, Euler Finance suffered an exploit that resulted in the loss of over 190 million USD. A single transaction in the attack generated 110 million USD. In this blog post, we’ll examine the attacker’s strategy and demonstrate how the exploit was executed.
Overview of the Attack
The attack can be summarized in four main steps:
- The attacker takes a flash loan and deposits it into Euler.
- Euler mints tokens for the deposit.
- The attacker donates these minted tokens, making them eligible for liquidation.
- The attacker liquidates themselves for profit.
The core issue lies in the fact that the attacker’s self-liquidation resulted in a profit greater than their debt. Now, let’s examine the entire process in code.
Step 1: Taking a Flash Loan
First, the attacker takes a flash loan of wstETH from Balancer.
Step 2: Depositing Flash Loan and Donating Minted Tokens
The attacker then deposits the flash loan into Euler and mints corresponding tokens. These tokens are subsequently donated via the donateToReserves function, allowing the attacker to liquidate themselves.
Step 3: Self-Liquidation
The liquidation process allows the attacker to liquidate themselves for a corresponding collateral value greater than their debt position.
Profit and Exploit Reproduction
The profit from this exploit amounts to 66,000 ETH or 110 million USD. A full proof-of-concept for the community’s education can be found in this GitHub repository.
The fundamental question we sought to answer: If the attacker took on a borrow position — partially donated the backing of this position and then liquidated themselves — how could they come out with more money than they started with?
To answer that we must understand Euler's mechanics:
Euler issues ETokens (interest earning tokens) to account for deposited money into the protocol and issues DTokens (Debt tokens) to account for borrowed money from the protocol.
This is relevant in the case of a liquidation event. A user who lacks the collateral to maintain their borrowing position — known as a violator — will have their collateral AND debt seized by a liquidator.
And in order for a liquidator to want to seize someone else's debt, there must be some sort of incentive. The greater the debt, the bigger this incentive must be.
Note that a high ratio of D to E tokens means that the liquidator will be taking on more debt.Ordinarily, the transfer of ETokens requires a liquidity check. However, this check was absent in the donateToReserves function.
The attacker exploited precisely this absence and donated their E tokens to create the aforementioned incentive. In fact, the exact formula used to determine the liquidators profit can be seen in the image below.
By donating their E Tokens, the position becomes unhealthier, and by extension, the liquidation discount is higher. As the conversion rate increases, the liquidator's yield becomes more fruitful.
The outcome: A USD 100M exploit. Economic incentive bugs are hard. They cannot be caught by static analyzers or automated tooling and require a deep understanding of the protocol's customised system.
In summary, the attacker took advantage of a flash loan to deposit a large sum, then liquidated themselves to end up with more money than they initially had.
At Zellic, we do post-mortems on hacks because we want to stay on top of every current attack, and to build professional knowledge of threats. We share this information because the community deserves to know what went wrong and what can be done differently in the future.