At around 8 AM UTC on July 14, ApeRocket’s MATIC-DAI vault on Polygon was exploited and drained $1M (521 ETH) out of the SPACE token LP on Polygon.
Check out the Transaction Details on PolygonScan.
- Borrowed 24M DAI and 54M MATIC of flash loans from Aave.
- Created 25M DAIMATIC LP.
- Deposited 10M LP to the DAI-MATIC LP vault. Got the majority share (99%) of the vault.
- Deposited 15M LP from the MiniApeV2 contract of ApeSwap to the DAI-MATIC LP vault of ApeRocket (see detailed analysis below).
- Called withdrawAll() on the vault.
- With the rather large amount of LP token added (deposited from ApeSwap’s MC) by the hacker at step 3, it returned a large amount of profit. As a result, the system minted 2.5M pSAPCE as a reward to the hacker.
- Swapped the rewarded pSPACE token to ETH, repaid the flash loan. Taken out 521 ETH (in 2 transactions).
The Root Cause
The deposit() function of the MiniApeV2 of ApeSwap Polygon (a fork of SushiSwap’s MiniChefV2) allows deposits to any address, which is not possible for a regular MasterChef v1 (and the smart contract code is build with the assumption of underlying MC contract to be it), makes it possible to increase the profit amount for everyone in the vault.
With the hacker takes the majority share of the vault, almost all of the profit will still get returned to the hacker.
When the minted SPACE token worth more than the 30% performance fee, it constitutes a valid economic attack.
WatchPug is a smart contract security team with the goal of elevating the security, privacy, and usability of the current DeFi ecosystem. For the need for smart contract auditing, please contact us at Twitter or Telegram.