Harvest Finance Hack Analysis & POC

got hacked for around due to a flashloan attack which manipulated the price in the Curve pool to retrieve more tokens than originally deposited amount in pool. This attack was also possible on other f-pools using the same set of steps described below. But the attacker chose not to continue. If the attack had continued, the attacker would have walked away with worth of assets.

is a type of yield farming protocol the same as (Yearn Finance). It gathers yields from various lending protocols and optimizes for the maximum gain to return to depositors. The attacker performed an arbitrage attack by using a large flash loan.

THE EXPLOIT

Detailed Transaction Trace

https://ethtx.info/mainnet/0x9d093325272701d63fdafb0af2d89c7e23eaf18be1a51c580d9bce89987a2dc1/

We will be focusing on this specific transaction to understand the hack.

https://etherscan.io/tx/0x9d093325272701d63fdafb0af2d89c7e23eaf18be1a51c580d9bce89987a2dc1

  1. The attacker deploys a contract & pre-funds it with &
  2. The attacker took flashloan of from the Uniswap v2 pair.
  3. The attacker then swaps for . Now the contract has .
  4. A total of are then deposited to the pool to get tokens.
  5. The attacker then swaps back for .
  6. The attacker withdraws the deposited to claim which is more than what was originally deposited i.e . Gaining profit of approximately
  7. The attacker repeatedly called steps 3–6 4 times to gain profit.

TRY IT YOURSELF!

We have put together a GitHub repository to reproduce the attack. Here is the Github repo:

--

--

We exist to build trust in the web3 ecosystem by cultivating veterans that are experts in security, testing and audits. Visit the website: https://blockapex.io

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
BlockApex

We exist to build trust in the web3 ecosystem by cultivating veterans that are experts in security, testing and audits. Visit the website: https://blockapex.io