On-chain liquidity manipulation

TL;DR

Seeing hackers exploited liquidity of ETH, BTC by manipulating liquidity of altcoins, we realized that we can replay this trick on Impermax Finance abandoned pool for learning and fun. However, it's harder to make collateral on Impermax than on other platforms and $IMX as a multi-chain token imposes risk of cross-chain arbitrage bots. However, our ignorance of a detail of Twap interval made us lose massive profits.

History

Liquidity manipulation has been leaving shadow on ethereum darkforest, which usually exploit lending protocol by flash loan. In many cases, hackers would play pump and dump game on some alt coins which have low liquidity. And take advantage of oracle, borrowing tokens with higher liquidity by using alt coin as collateral. This kind attack never ends, naming a few: Mango Markets, Venus Protocol, Cream Finance(multiple times). [1]

The core of price manipulation is Oracle, and SBF stressed the significance of it in Mango crisis. [2] According to $MNGO price on its own platform, hackers succeeded in draining the whole platform in 5min, which means the oracle of Mango Market is too sensitive and vulnerable to short-term volatility. However, most Cexs and dApps employed TWAP, EWMA and IMF Factors to prevent chaos caused by short-term liquidity manipulation.

Our Plan

Inspired by these ever-existing crises and combined with past experience during Ve War(Solidly by AC), me and my partner decided to replay this trick on $IMX of Impermax Finance. [3] I have to clarify there is an Intrinsic difference between our plan and past hack behavior that $IMX had been abandoned due to private key leak. Thus, it no longer has anything to do with Impermax Finance or its users, so whatever we did is free of legal risk. [4]

Due to the borrowing mechanism of Impermax Finance, it's much harder to manipulate the price of $IMX compared to Mango attack. Firstly, $IMX is a multi-chain token and yes, we can pump it on a single chain and drain another high liquidity token in pool, but some cross-chained bots would bridge $IMX from other chains with a cheaper price, dumping on our pump liquidity. So, we have to keep $IMX in a much higher price in all 6 chains(Ethereum, Polygon, Arbitrum, Avalanche, Moonriver and Fantom). Moreover, to borrow a token in Impermax Finance, we have to provide liquidity on dex and mint collateral with LP tokens instead of depositing single token as collateral. [5] Therefore, the higher we pull the price, the more profits we can grab, but of course this means bigger risks. The last problem is the old holder dump. Although $IMX is forgotten by most users, some holders still probably notice the instant pump and dump on our liquidity. We can only choose Saturday to implement our plan when most traders might enjoy their lives off-chain. Apart from that, we just pray for luck.

The key step is to let the oracle send pumped price to the pool of IMX/ETH, and we made an overconfident mistake on UniswapV2 TWAP mechanism. [6] Considering most protocols took 30min as interval, we assumed Impermax Finance was no exception. It turned out to be 60min interval. After 30min of pumping, we were unable to borrow $ETH from the lending pool. It was a torturous phase, since we have to take any potential risk of old holder dumping. If we don't, then the previous 30min pump is nonsense. Murphy's Law says "if it can go wrong, it will.” The dumps we had been worried about still happened during the second 30min. Dozens of dollars $IMX was not a big deal before the pump, but now they are worth hundreds of dollars and we have to take all of them. So in the end, all the profits made from liquidity manipulation go back to dumpers.

On-Chain Info

  • 0x8a8f37ec4545b102d1766c608ceeda06a35296a67b7d020d92a368c5e5ada14f: At Oct-29-2022 06:38:35 PM +UTC, we started to pull the price with multiple transactions,making price raise from 0.0012 to 0.035.

  • 0xe3aeaebce992a1ad5a48b9441ad4293c002ff749ebe40a29a9b6bbf1ed93a095: At Oct-29-2022 07:09:35 AM +UTC, we successfully borrowed eth out of the lending pool, but this amount is much less than we expected, which means UniswapV2 Oracle didn't feed the latest price to the pool. Then we were aware that IMX/ETH takes 60min as Twap interval.

  • 0xc2c96e86835288be9150d791ee40747b4049513f75bd54a08c66c069df28cc2c: At Oct-29-2022 07:40:47 AM +UTC, IMX/ETH got the price updated and we drained the remaining eth.

  • 0x783955d0ea656e5c13f596a8b4943f9a658474af00be5fc5462369e14c7eebda, 0x4b8c6fe566d474de28b187ebd2c41f4fa53df866a0f42410f31f29e4c35484ba: Between Oct-29-2022 06:52:40 and 07:43:06 AM +UTC, Polygon and Avalanche whales dumped their bags to our liquidity and we were trying to drain the pool from Arbitrum at that time.

  • 0xde358d5eff7eea7a26b94dd687533422f4ebde02b48a8b016608c2cbcd3373af: At Oct-29-2022 08:35:59 PM +UTC, after draining all eth from multiple chains, we dumped $IMX collected from pumping. The game ended.

Summary

Many protocols are vulnerable to liquidity manipulation, and it's hard to locate the problem until the exploit actually happens. The most efficient way is probably using Twap with longer interval, which is also the lesson we learnt from the implementation. I wouldn't say our whole play is a failure although we didn't get the profits we expected. Draining IMX/ETH abandoned pools from multi-chains by liquidity manipulation is really an alpha move. Still, we need to pay more attention to protocol Twap rules and on-chain holder info in the future.

Reference

[1] REKT leaderboard, https://rekt.news/leaderboard/.

[2] SBF tweets, https://twitter.com/SBF_FTX/status/1580170215304089600.

[3] Andre Cronje medium, https://andrecronje.medium.com/solidly-feature-updates-and-launch- date-97be7e50e282.

[4] Impermax Finance statement, https://www.impermax.finance/post/imx-incident-post-mortem-and-recovery-plan.

[5] Impermax Finance lending mechanism, https://docs.impermax.finance/protocol/lending-pools-and-collateral.

[6] UniswapV2 Oracle explanation, https://docs.uniswap.org/protocol/V2/concepts/core-concepts/oracles.