[ad_1]
The Root Cause:
So, basically, the donateToReserve function lets Euler users put some money into a reserved address. Users call this function, they have both Debt Token (DToken) and Equity Token (EToken).
The attack was possible due to a lack of liquidity checks in the donateToReserves function of Etoken. There was a logical error in the donateToReserve() method. As a result, e-DAI tokens were burned, but not d-DAI tokens. This created bad debt that will never be repaid. So, the hacker was able to withdraw from the protocol using their liquidation contract.
The Attack:
- The attacker borrowed 30M DAI through a flash loan, and then deployed two contracts i.e. violator and liquidator.
- 2/3 of the borrowed funds (i.e. 20 million DAI) were deposited to Euler using the deposit() function. In return, the attacker received around 19.5 million eDAI and 200 million dDAI from Euler.
- The attacker called the mint function, which allows users to borrow up to 10 times their deposit, and borrowed 195.6 million eDAI and 200 million dDAI.
- Part of the debt was repaid using the remaining 1/3 of the borrowed funds (i.e. 10 million DAI) with the repay() function, and around 10 million dDAI were burned. The attacker then proceeded to call the mint function again and received 195.6M eDAI and 200M dDAI from Euler.
- The attacker donated 10x of repaid funds using donateToReserves and sent 100 million eDAI to Euler.
- Then, the attacker liquidated a violator’s account using the liquidate() function because eDAI < dDAI. This initiated the liquidation process, and the attacker obtained 310 million dDAI and 259 million eDAI from the violator.
- The attacker called the withdraw function and obtained 38.9 million DAI. Out of this amount, he paid back 30 million DAI for the loan amount and 27,000 DAI interest for the flash loan. The attacker profited 8.87 million DAI from DAI Pool.
The exploiter repeated the attacks on other pools, netting around 197 million dollars. More details are below:
Mar-13–2023- Euler Finance acknowledge the incident and announced it through their twitter.
Mar-13–2023- Euler reached out to the attacker’s address via tx input data.
Mar-14–2023- Sherlock has taken responsibility for missing the vulnerability in their review of EIP-14 last year, and will pay a claim of $4.5M to Euler.
Mar-14–2023- Further Euler Team shared some updates and made some immediate action but the funds we already lost.
Mar-18–2023- The attacker has returned around 3000 ETH to Euler Finance.
Mar-20–2023- The exploiter sent a message to the Euler team regarding returning funds, and the Euler team acknowledged the message and shared the channels for further communication.
Mar-22–2023- Exploiter has reached out to the Euler team over email
March-25–2023- Exploiter returned 51,000 ETH, then again 7,737.25 ETH and 1,230,000 DAI tokens to Euler Finance . More details here.
Reproducing the hack:
We will be using the Foundry framework for POC.
Running Locally:
(Add the Ethereum Mainnet RPC URL in foundry.toml
file and run the test using the command forge test -vvv
)
[ad_2]
Source link