Enzyme Finance Price Oracle Manipulation Bug Fix Postmortem
Enzyme Finance calculated the price of Idle tokens using a formula that could be manipulated by taking a flashloan of Idle tokens, which temporarily reduced the token's total supply and thus inflated the price. An attacker could buy shares at a discount and then redeem them for a profit.
medium.com
Published on medium.com
Enzyme Finance
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.
Context
Enzyme Finance is an Ethereum-based protocol for decentralised on-chain asset management. Users and investors create and invest in funds. A fund owner configures the rules of the fund: fees and policies, the denomination asset by which share price and performance are measured, and the time-lock between share actions (buying or redeeming shares) for a given user.
When someone invests in a fund, they send the underlying asset of the fund to the vault and receive shares that represent their part in the fund. The entry point is the buyShares() function on ComptrollerLib.sol. The caller supplies the amount of underlying assets they will use to purchase shares and the minimal amount of shares they are willing to accept.

The price of a share is calculated by the public function calcGav(), which computes the gross asset value (GAV) of the fund. It tells the protocol how much a user must pay for a share based on the current value of the fund's assets. From the price it returns, the protocol mints X shares to the user or redeems Y shares.

calcGav consults VaultInterpreter.sol and IDerivativePriceFeed.sol for the canonical asset total value in a fund. The price feed relevant here is IdlePriceFeed.sol, used for Idle Tokens such as idleUSDCYield. In that case the underlying asset is USDC and the derivative asset is idleUSDCYield.

IdlePriceFeed obtains the unit price of an Idle Token by calling the tokenPrice function of the token. The return value of that function is what an attacker would need to manipulate in order to get better prices for a share when buying and later selling for a profit.

In the code, the price is calculated as net asset value (NAV) divided by total supply. NAV represents the per share or per unit price of the fund at a specific date or time. Looking at the totNav calculation, one value looked potentially manipulable: the current balance of the Idle Token contract's backing assets. The route to changing it was the contract's internal flashloan functionality, which could temporarily empty the contract by flashloaning the maximum amount from the IdleToken.

Setup
The report contained a working proof of concept that detailed all the steps needed to reproduce the attack.
The relevant preconditions are:
- Enzyme integrates Idle Tokens through
IdlePriceFeed.sol, and share pricing flows throughcalcGav(). - The Idle Token version in use exposes an internal flashloan function. The initial Idle Token integration was with v4, which had no flashloan logic. Flashloan logic was added in v5, which unintentionally introduced the bug into Enzyme Finance.
- The attacker has a contract funded with WETH and can swap it for USDC within the same transaction.
Finding it
The researcher, setuid0 of SSLab at Georgia Tech, reported a critical vulnerability on 17 November in the way Enzyme Finance calculated the prices of Idle tokens when buying shares. The core observation is that IdlePriceFeed derives the unit price of an Idle Token from tokenPrice, which is computed as NAV divided by total supply. The NAV side depends on the current balance of the Idle Token contract's backing assets, and that balance can be moved within a single transaction using the Idle Token contract's own flashloan functionality.
A flashloan from IdleTokenGovernance.sol affects the totalSupply of the Idle tokens used in the price calculation. Price calculations were based on totalNav / totalSupply of the tokens. Because the attacker can drain the contract's backing assets temporarily, the GAV computed during the flashloan is wrong, and shares can be bought at a discount.
The report notes that this is not a common flashloan-enabled AMM price manipulation: the flashloans and the price feeds are all inside the IdleTokenGovernance contract. The attacker exploits the logic of Idle tokens without a traditional AMM oracle manipulation.
The report was escalated within five minutes, which the write-up attributes to the working proof of concept, and was confirmed by the Enzyme team early the next day. Enzyme issued a payout of $90,000 to setuid0 the same week.
Exploitation
The attack is described as a sequence of steps executed around a single flashloan.
Step 1: Fund the malicious contract with WETH
The attacker contract is funded with WETH so that it can later be swapped for USDC to pay for the flashloan.
Step 2: Flashloan IdleUSDCYield tokens
The attacker takes a flashloan of IdleUSDCYield tokens. This affects GAV calculations because it greatly impacts the contract balance of IdleUSDCYield tokens.
Step 3: Swap WETH to USDC during the flashloan
While the flashloan is outstanding, the attacker swaps WETH to USDC. This USDC is what will later be used to buy shares, since the underlying asset is used for buying shares.
Step 4: Call buyShares during the flashloan
Still inside the flashloan, the attacker calls buyShares. Because GAV calculations are affected, the shares are effectively bought at a discount.
Step 5: Repay the flashloan
The flashloan is repaid before the transaction ends.
Step 6: Call redeemShares after repayment
Once the flashloan is repaid, the attacker calls redeemShares to sell all the bought shares of the Idle Fund for a profit.
Step 7: Keep the profit
The difference between the discounted purchase price and the redemption value is the attacker's profit.
Root cause
The mistake is in the price source. IdlePriceFeed trusts tokenPrice on the Idle Token, and tokenPrice is derived from NAV divided by total supply, where NAV depends on the contract's current backing-asset balance. That balance is not a stable input: the Idle Token contract's own flashloan functionality lets a caller temporarily empty the contract, so the balance, and therefore the price, can be moved within one transaction.
The integration was originally written against Idle Token v4, which had no flashloan logic. Flashloan logic arrived in v5, and the integration was not revisited when that happened.
Impact
An attacker could buy fund shares at a discount during a flashloan and redeem them afterwards for a profit. Not much was at risk, around $400k according to the write-up. Enzyme nonetheless issued a generous payout to incentivise whitehats to find similar vulnerabilities in future.
Fix
Enzyme Finance delisted IDLE tokens and will have a larger discussion with its council and auditors about Idle tokens and other future integrations with upgradable protocols. IDLE additionally removed the flashloan feature to protect other potential integrators that may have been affected by the same issue.
Variants to test
- Derivative price feeds that read a live contract balance. For any
IDerivativePriceFeedimplementation, check whether the price depends on a balance that a caller can change inside the same transaction. A positive result is a price that moves when you deposit, withdraw or borrow against the derivative within one transaction. - Integrations written against an older version of an upgradable dependency. Compare the version the integration was written for with the deployed version and look for newly added functions such as flashloans, hooks or callbacks. A positive result is a new entry point that changes a value the integration's price feed reads.
- Share pricing that calls into the derivative during
buySharesandredeemShares. TracecalcGav()and confirm whether the value it returns can differ between the buy and the redeem in the same transaction. A positive result is a buy at one GAV and a redeem at a higher GAV after the temporary state change is undone. - Protocol-internal flashloans rather than AMM pools. Look for lending or yield contracts that expose their own flashloan function and whose internal accounting feeds a price. A positive result is a price that can be pushed by draining the contract's backing assets and restored by repaying before the transaction ends.
What happened, in plain words
Enzyme Finance is a piece of software that runs on Ethereum, a public blockchain. You can think of Ethereum as a giant shared notebook that anyone can read and that nobody can quietly edit: every entry is checked by thousands of computers at once. Enzyme lets people pool their money into "funds", a bit like a group savings pot with a manager. Investors put money in and get a receipt called a share, which records how much of the pot belongs to them.
The problem was in how Enzyme worked out the price of one particular kind of receipt. To decide how much a new investor should pay for a share, Enzyme asked another contract, an Idle Token, "what is one of your units worth right now?" The Idle Token answered by dividing the value of everything it holds by the number of units in existence. That answer was correct at the moment it was given, but it could be pushed around by anyone who could temporarily move the Idle Token's holdings. Idle Tokens had a feature, a flashloan, that let a caller borrow nearly everything the contract held, as long as it was returned before the same transaction finished. A transaction is one indivisible bundle of actions: either all of it happens or none of it does.
So an attacker could, inside one transaction, borrow almost all of the Idle Token's holdings, which made the Idle Token look poor, buy Enzyme fund shares cheaply at that artificially low price, give the borrowed tokens back, and then sell the shares at the normal price. The difference was profit.
A security researcher called setuid0, from SSLab at Georgia Tech, found this and reported it on 17 November. The report came with a working demonstration, called a proof of concept, that walked through every step needed to reproduce the attack. It was escalated within five minutes, which the write-up puts down to that working proof of concept, and the Enzyme team confirmed it early the next day. Enzyme paid $90,000 to setuid0 the same week. The amount actually at risk was low, around $400k according to the write-up, but Enzyme paid generously to encourage more people to report problems like this in future.

The rest of this article explains the background concepts, then walks through the vulnerability, the attack step by step, the underlying mistake, the impact and the fix.
Background: price oracles and flashloans
Before the bug itself, two ideas need explaining, because the whole attack is built from them.
What a price oracle is
A price oracle is simply a tool that tells a program what something is worth. If you have ever checked the price of a currency before exchanging money, you have used an oracle in real life. In the world of decentralised finance (DeFi, meaning financial services built on blockchains rather than run by banks), programs constantly need to know the price of a token, meaning how much it is worth against another asset or against a stablecoin such as DAI, USDC or USDT. A stablecoin is a token designed to stay at roughly one US dollar.
There are two main kinds of oracle:
- Onchain oracles are themselves smart contracts, small programs that live on the blockchain. Many DeFi projects read prices from automated market makers (AMMs), which are decentralised exchanges such as Uniswap, Sushiswap, PancakeSwap, Curve, Bancor and Balancer. In a simple AMM like UniswapV2, the price of one token against another is just the ratio of the two amounts sitting in the pool. If a pool holds a certain amount of ETH and a certain amount of DAI, dividing one by the other gives the current price of an ETH.
- Offchain oracles such as Chainlink work differently: a decentralised network of computers reports prices into a smart contract, and programs read the latest reported price from there. To get the price of ETH in US dollars, you ask the Chainlink aggregator contract, which holds the latest figure reported by the Chainlink nodes.
Each kind has trade-offs. With offchain oracles you have to trust the network to post correct prices, and only a limited set of assets is covered: a brand new token probably will not appear in a Chainlink feed straight away. Onchain oracles let anyone create a pool for a new token against ETH or DAI, but the price they give is a spot price, the price right now, and spot prices can swing wildly. If someone wants to sell a very large amount of a token for ETH, the pool's ratio moves a long way during that sale.
That last point matters: a wealthy user, sometimes called a whale, can move the price of a token in either direction within a single transaction. The question this article answers is whether an ordinary attacker can do the same thing. The answer involves flashloans.
What a flashloan is
Everyone understands an ordinary loan: you go to a bank, show proof of income or put up collateral (an asset the bank can keep if you do not repay), and the bank lends you money. A flashloan is a loan with no collateral at all, borrowed from a lending protocol such as Aave, on one strict condition: it must be repaid within the same transaction, plus a small fee. If it is not repaid, the whole transaction is reversed as if it never happened.
Because a transaction is all-or-nothing, the rule is easy to enforce in code. A flashloan transaction has three parts:
- Receive the loan.
- Do something with the loan.
- Repay the loan.
All three must happen inside one transaction. If step 3 fails, steps 1 and 2 are undone too.
The main legitimate use is arbitrage: buying an asset on one exchange and selling it on another where it is slightly more expensive. You cannot keep a flashloan for the long term, since it must be repaid immediately, but you can use it to capture a small price difference. A 1% difference may sound trivial, but on a very large borrowed amount it is a substantial sum.
Flashloans can also be used for harm, and that is why they matter here. With a large amount of WETH (a wrapped form of ETH, meaning ETH packaged as a token so that contracts can handle it) borrowed temporarily, an attacker can swap it for any other asset through an AMM. The swap does not even need to be direct: if the token you want only has a pool against DAI, you can swap the borrowed ETH for DAI and then use some of that DAI to buy the token, moving its price along the way.
The vulnerability
Enzyme Finance is an Ethereum-based protocol for decentralised on-chain asset management. Users and investors create and invest in funds. A fund owner sets the rules: fees and policies, the denomination asset by which share price and performance are measured (the asset the fund is priced in), and the time-lock between share actions, meaning a waiting period before a given user can buy or redeem shares again.
When someone invests in a fund, they send the fund's underlying asset to the vault, a contract that holds the fund's assets, and receive shares representing their part of the fund. The entry point is the buyShares() function on ComptrollerLib.sol. The caller supplies two things: the amount of underlying assets they will use to purchase shares, and the minimal number of shares they are willing to accept.

The price of a share is calculated by a public function called calcGav(), which computes the gross asset value (GAV) of the fund, meaning the total value of everything the fund holds. It tells the protocol how much a user must pay for a share based on the current value of the fund's assets. From the price it returns, the protocol creates (mints) X shares for the user, or destroys (redeems) Y shares.

calcGav consults VaultInterpreter.sol and IDerivativePriceFeed.sol for the canonical asset total value in a fund, meaning the agreed, authoritative total. The price feed relevant here is IdlePriceFeed.sol, used for Idle Tokens such as idleUSDCYield. In that case the underlying asset is USDC (a stablecoin pegged to the US dollar) and the derivative asset is idleUSDCYield, a token whose value is derived from USDC deposited into Idle.

IdlePriceFeed obtains the unit price of an Idle Token by calling the tokenPrice function of the token. The return value of that function is what an attacker would need to manipulate in order to get better prices for a share when buying and later selling for a profit.

In the code, the price is calculated as net asset value (NAV) divided by total supply. NAV represents the per share or per unit price of the fund at a specific date or time. Looking at the totNav calculation, one value looked potentially manipulable: the current balance of the Idle Token contract's backing assets, meaning the assets the contract holds to back its tokens. The route to changing it was the contract's internal flashloan functionality, which could temporarily empty the contract by flashloaning the maximum amount from the IdleToken.

Setup
The report contained a working proof of concept that detailed all the steps needed to reproduce the attack.
The relevant preconditions are:
- Enzyme integrates Idle Tokens through
IdlePriceFeed.sol, and share pricing flows throughcalcGav(). - The Idle Token version in use exposes an internal flashloan function. The initial Idle Token integration was with v4, which had no flashloan logic. Flashloan logic was added in v5, which unintentionally introduced the bug into Enzyme Finance.
- The attacker has a contract funded with WETH and can swap it for USDC within the same transaction.
Finding it
The researcher, setuid0 of SSLab at Georgia Tech, reported a critical vulnerability on 17 November in the way Enzyme Finance calculated the prices of Idle tokens when buying shares. The core observation is that IdlePriceFeed derives the unit price of an Idle Token from tokenPrice, which is computed as NAV divided by total supply. The NAV side depends on the current balance of the Idle Token contract's backing assets, and that balance can be moved within a single transaction using the Idle Token contract's own flashloan functionality.
A flashloan from IdleTokenGovernance.sol affects the totalSupply of the Idle tokens used in the price calculation. Price calculations were based on totalNav / totalSupply of the tokens. Because the attacker can drain the contract's backing assets temporarily, the GAV computed during the flashloan is wrong, and shares can be bought at a discount.
The report notes that this is not a common flashloan-enabled AMM price manipulation: the flashloans and the price feeds are all inside the IdleTokenGovernance contract. The attacker exploits the logic of Idle tokens without a traditional AMM oracle manipulation.
The report was escalated within five minutes, which the write-up attributes to the working proof of concept, and was confirmed by the Enzyme team early the next day. Enzyme issued a payout of $90,000 to setuid0 the same week.
Exploitation
The attack is described as a sequence of steps executed around a single flashloan.
Step 1: Fund the malicious contract with WETH
The attacker contract is funded with WETH so that it can later be swapped for USDC to pay for the flashloan.
Step 2: Flashloan IdleUSDCYield tokens
The attacker takes a flashloan of IdleUSDCYield tokens. This affects GAV calculations because it greatly impacts the contract balance of IdleUSDCYield tokens.
Step 3: Swap WETH to USDC during the flashloan
While the flashloan is outstanding, the attacker swaps WETH to USDC. This USDC is what will later be used to buy shares, since the underlying asset is used for buying shares.
Step 4: Call buyShares during the flashloan
Still inside the flashloan, the attacker calls buyShares. Because GAV calculations are affected, the shares are effectively bought at a discount.
Step 5: Repay the flashloan
The flashloan is repaid before the transaction ends.
Step 6: Call redeemShares after repayment
Once the flashloan is repaid, the attacker calls redeemShares to sell all the bought shares of the Idle Fund for a profit.
Step 7: Keep the profit
The difference between the discounted purchase price and the redemption value is the attacker's profit.
Root cause
The mistake is in the price source. IdlePriceFeed trusts tokenPrice on the Idle Token, and tokenPrice is derived from NAV divided by total supply, where NAV depends on the contract's current backing-asset balance. That balance is not a stable input: the Idle Token contract's own flashloan functionality lets a caller temporarily empty the contract, so the balance, and therefore the price, can be moved within one transaction.
The integration was originally written against Idle Token v4, which had no flashloan logic. Flashloan logic arrived in v5, and the integration was not revisited when that happened.
Impact
An attacker could buy fund shares at a discount during a flashloan and redeem them afterwards for a profit. Not much was at risk, around $400k according to the write-up. Enzyme nonetheless issued a generous payout to incentivise whitehats to find similar vulnerabilities in future.
Fix
Enzyme Finance delisted IDLE tokens and will have a larger discussion with its council and auditors about Idle tokens and other future integrations with upgradable protocols. IDLE additionally removed the flashloan feature to protect other potential integrators that may have been affected by the same issue.
Variants to test
- Derivative price feeds that read a live contract balance. For any
IDerivativePriceFeedimplementation, check whether the price depends on a balance that a caller can change inside the same transaction. A positive result is a price that moves when you deposit, withdraw or borrow against the derivative within one transaction. - Integrations written against an older version of an upgradable dependency. Compare the version the integration was written for with the deployed version and look for newly added functions such as flashloans, hooks or callbacks. A positive result is a new entry point that changes a value the integration's price feed reads.
- Share pricing that calls into the derivative during
buySharesandredeemShares. TracecalcGav()and confirm whether the value it returns can differ between the buy and the redeem in the same transaction. A positive result is a buy at one GAV and a redeem at a higher GAV after the temporary state change is undone. - Protocol-internal flashloans rather than AMM pools. Look for lending or yield contracts that expose their own flashloan function and whose internal accounting feeds a price. A positive result is a price that can be pushed by draining the contract's backing assets and restored by repaying before the transaction ends.
Glossary
- Blockchain: a shared, tamper-resistant record of transactions kept by many computers at once.
- Ethereum: a public blockchain that can run small programs called smart contracts.
- Smart contract: a program that lives on a blockchain and runs automatically when called.
- DeFi (decentralised finance): financial services built on blockchains instead of run by banks.
- Protocol: a set of smart contracts that together provide a service.
- Fund: a pool of money managed under rules set by an owner, in which investors hold shares.
- Share: a receipt recording an investor's portion of a fund.
- Vault: a contract that holds a fund's assets.
- Underlying asset: the base asset a fund or derivative is built on, such as USDC.
- Derivative asset: a token whose value is derived from another asset, such as idleUSDCYield from USDC.
- Denomination asset: the asset in which a fund's share price and performance are measured.
- Time-lock: a waiting period before a user can perform another share action.
- Price oracle: a tool that tells a program what an asset is worth.
- Onchain oracle: an oracle that is itself a smart contract, often reading prices from an AMM pool.
- Offchain oracle: an oracle fed by data reported from outside the blockchain, such as Chainlink.
- AMM (automated market maker): a decentralised exchange where prices come from the ratio of assets in a pool.
- Spot price: the price of an asset right now.
- Stablecoin: a token designed to stay close to one US dollar, such as DAI, USDC or USDT.
- WETH: ETH packaged as a token so contracts can handle it.
- Flashloan: a loan with no collateral that must be repaid within the same transaction.
- Collateral: an asset pledged so a lender can keep it if a loan is not repaid.
- Arbitrage: profiting from a small price difference for the same asset on two markets.
- Transaction: one indivisible bundle of blockchain actions; either all happen or none do.
- GAV (gross asset value): the total value of everything a fund holds.
- NAV (net asset value): the per share or per unit value of a fund at a given time.
- Total supply: the number of tokens or shares in existence.
- Mint: create new shares or tokens.
- Redeem: exchange shares back for the underlying assets.
- Price feed: the component that supplies a price to a protocol.
- Whitehat: a security researcher who finds and reports vulnerabilities to help fix them.
- Proof of concept (PoC): a working demonstration that an attack is possible.
- Escalation: raising a reported bug to the project's team for confirmation and action.
- Bug bounty: a programme that pays researchers for reporting vulnerabilities.
- Payout: the reward paid for a valid report.
- Upgradable protocol: a protocol whose contracts can be changed to new versions after deployment.
- Delist: remove an asset from a protocol's supported list.
- Integrator: a project that builds on top of another protocol's contracts.