Pickle Finance Exploited For $20M In Most Complex Ever Code Execution

In the latest DeFi hack, stablecoin stabilizing protocol Pickle Finance was exploited on 21-11-2020 06:37 PM (UTC) for nearly $20M. It is notable because analysts are terming it as the most complex DeFi exploit ever, as pDAI jar was hacked with skill-full mastery. The system was gamed using multiple flaws, including Jar swap and Jar convert logic in an extremely sophisticated code execution.

Following the attack, users were advised to withdraw funds from Pickle Jars and wait for the next updates. The team has now confirmed that the attack has been reverse engineered and relevant system modules have been patched to defend against this attack vector, in the future.

Banteg Reveals Details Of The Attack

Yearn.Finance developer Banteg was one of the white hat hackers assisting the team with the investigation and fixed. He has since then posted a detailed explanation of the attack. It is every evident that the hacker (s) had a deep understanding of the smart contract logic and execution. The following information was taken from the Github entry.

  1. Deploy two Evil Jars
  2. Get the amount available to withdraw from StrategyCmpdDaiV2
  3. Invoke ControllerV4.swapExactJarForJar() passing the Evil Jars and the amount retrieved in the previous step.
  4. ControllerV4.swapExactJarForJar() doesn’t check the Jars and calls them, withdrawing from StrategyCmpDAIV2 using StrategyCmpDAIV2.withdrawForSwap() which ultimately usesStrategyCmpDAIV2.deleverageToMin(). This transfers 19M DAI to pDAI.
  5. Call pDAI.earn() 3 times. This invokes a Compound deposit via StrategyCmpDAIV2.deposit(), leading to the contract receiving cDAI. StrategyCmpdDAIV2 now has an equivalent of 19M in cDAI.
  6. Deploy 3 more evil contracts, the first one being the equivalent of FakeUnderlying in our replicated exploit and the other two Evil Jars.
  7. Invoke ControllerV4.swapExactJarForJar() passing the Evil Jars, no amount and a CurveProxyLogic as target with a crafted data which allowed an injection to call the equivalent FakeUnderlying.
  8. ControllerV4 delegate calls CurveProxyLogic.add_liquidity() passing StrategyCmpDAIV2 and a crafted signature which leads to withdrawal of cDAI and transferring them to ControllerV4.
  9. The funds (in cDAI) are now in the Controller, it calls the EvilJar.deposit() which transfer the funds to the attacker smart contract.
  10. The attacker smart contract redeems cDAI for DAI from Compound and transfers DAI to the attacker EOA.

Implications For DeFi Protocols Design And Security

DeFi protocols are generally famous for “move fast and break things” ethos. The developer teams in this space are known to experiment with code and deploy unaudited code without much protection. Lately, this has resulted in massive fund losses, no doubt largely borne by the users. Even if the code is audited even by multiple teams, there is no guarantee that it’s 100% secure.

DeFi teams need to apply a multi-disciplinary strategy, bringing together elements of finance, game theory, tokenomics, smart contract design and logic. They also need to make certain that going forward relevant safeguards are present to enforce limits and insurance has been acquired, in order to protect against such exploits.

Pickle Finance
Pickle Finance© Cryptoticker
scroll to top