Slow Mist: SushiSwap was attacked for the second time

Background

What is SushiMaker

What is constant product

In other words, each exchange actually follows this formula, and the K value remains unchanged before and after the transaction. During the exchange process, since the K value remains unchanged, the formula will look like this

Where X represents the token to be sold and Y represents the token to be purchased, so the number of tokens that can be exchanged each time will look like this

It can be seen from the formula that the upper limit of the exchange amount of output token Y depends on the number of Y tokens, and has nothing to do with the number of X tokens. On the other hand, if the number of X tokens to be sold is large, But the number of Y tokens is very small, so a large number of X tokens can only be exchanged for a small amount of Y tokens, and this exchange price will deviate a lot from the normal transaction price. This is the so-called slippage. The key to this attack.

Attack analysis

The logic of the bridgeFor function is as follows:

According to the logic of bridgeFor, we can find that if the bridge of a specific currency has not been manually set, the default bridge is WETH, that is, if the bridge is not set, the default is to convert the handling fee to WETH. The DIGG coin just didn’t set the corresponding bridge through setBridge.

But there is another problem here, that is, during the swap process, if the transaction pair does not exist, the exchange process will fail. In this attack, the DIGG-WETH transaction pair did not exist at the beginning, so the attacker created a DIGG-WETH transaction pair in advance, and then added a small amount of liquidity. If a commission exchange occurs at this time, according to the feature of constant product mentioned above, because DIGG-WETH has very little liquidity, that is, the upper limit of WETH in DIGG-WETH is very small, while the number of commissions to be converted in SushiMaker is relatively small. Larger, such exchange will cause huge slippage. The exchange process will increase the price of WETH to DIGG in the DIGG-WETH trading pair, and all DIGG fee income of DIGG-WETH will be transferred to the DIGG-WETH transaction. By observing the liquidity situation of the DIGG-WETH trading pair, when the liquidity is maximum, there is only less than 2800 US dollars of liquidity. This result can also be mutually verified with the derivation of the formula.

After the attacker completes the fee conversion at SushiMaker, the price of WETH to DIGG in the DIGG-WETH transaction pair has been increased, resulting in a small amount of WETH that can be exchanged for a large amount of DIGG, and the amount of this DIGG is exactly the DIGG-WBTC transaction Most of the fee income.

Sum up

Related reference links are as follows:

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

Attacker arbitrage trading:

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

DIGG-WETH liquidity details:

https://www.sushiswap.fi/pair/0xf41e354eb138b328d56957b36b7f814826708724

Detailed explanation of Sushi’s first attack:

https://mp.weixin.qq.com/s/-Vp9bPSqxE0yw2hk_yogFw

About us

Focuses on Blockchain Ecosystem Security, has served Huobi/OKEx/Binance/imToken, nearly a thousand commercial customers in total.

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