Enzyme Finance Price Oracle Manipulation Bug Fix Review
Enzyme Finance calculated the price of Idle tokens using a formula that depended on the token's total supply, which could be temporarily changed by taking a flashloan. An attacker could therefore buy fund shares at a discount and redeem them for a profit.
immunefi.com
Published on immunefi.com
In 2020 and at the beginning of 2021, one of the worst phrases you could hear either as a DeFi security researcher or developer was, “Project X was hacked due to Price Oracle manipulation using flashloans.” This was the main vulnerability at the time, and it made it difficult for auditors to sleep at night. Why?
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the price calculation for Idle tokens used the token's total supply, which could be manipulated via a flashloan, instead of a manipulation-resistant oracle.
Impact
An attacker could buy shares at a discount and redeem them for a profit, though the funds at risk were low (~$400k).
What the attacker needed
Malicious contract with WETH; flashloan of IdleUSDCYield tokens; ability to call buyShares and redeemShares
The fix
Enzyme delisted IDLE tokens and IDLE removed the flashloan feature to protect integrators.
How it was found
- Fund a malicious contract with WETH to swap for USDC later.
- Take a flashloan of IdleUSDCYield tokens, which changes the contract's balance and affects GAV calculations.
- During the flashloan, swap WETH to USDC to have the underlying asset for buying shares.
- During the flashloan, call buyShares to purchase shares at a discount because GAV is affected.
- Repay the flashloan.
- After repayment, call redeemShares to sell the shares for a profit.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A flashloan is a way to borrow a large amount of cryptocurrency without collateral, as long as you pay it back in the same transaction. Enzyme used a price formula for Idle tokens that included the token's total supply, and a flashloan could briefly change that supply. This let an attacker buy shares cheaply and sell them back at the normal price for a profit.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.