Slow fog: PancakeBunny hacked brief analysis

The DeFi revenue aggregator PancakeBunny project on the Coin Smartchain has been hit by a lightning loan attack, the results of which are shared in a newsletter.

Slow fog: PancakeBunny hacked brief analysis

According to Slow Fog intelligence, PancakeBunny, a DeFi revenue aggregator on the CoinSec smart chain, was attacked by a lightning loan, and the Slow Fog security team took the first step to analyze it and share the results in the form of a newsletter for your reference.

  1. The attacker first initiates a transaction to add liquidity to PancakeSwap using 0.5 WBNB and about 189 USDT and obtains the corresponding LP, and then pledges the LP to the VaultFlipToFlip contract of the PancakeBunny project.

After the LP is pledged, the attacker initiates another transaction in which the attacker first borrows a large amount of WBNB tokens from multiple liquidity pools in PancakeSwap and a certain amount of USDT tokens from the Fortube project’s Lightning Lending module. The borrowed USDT tokens and some WBNB tokens are then used to add liquidity to PancakeSwap’s WBNB-USDT pool, and the acquired LPs are left in the WBNB-USDT pool. 3.

Since the attacker has already pledged in the VaultFlipToFlip contract in step 1, the attacker directly calls the getReward function of the VaultFlipToFlip contract after adding liquidity to get the BUNNY token reward and retrieve the previously pledged liquidity.

When the getReward operation is performed, it calls the mintForV2 function of the BunnyMinterV2 contract to mint a BUNNY token reward for the caller.

In the mintForV2 operation, it first transfers a certain amount (performanceFee) of LP to the WBNB-USDT pool to remove liquidity, but since the attacker left a large amount of LP in the pool in step 2, the BunnyMinterV2 contract will receive a large amount of WBNB The BunnyMinterV2 contract will receive a large number of WBNB tokens and USDT tokens.

After the removal of liquidity, the zapBSC contract’s zapInToken function will be called to transfer the WBNB and USDT tokens received in step 5 to the zapBSC contract, respectively.

In the zapInToken operation, it converts the transferred USDT into WBNB in the WBNB-USDT pool of PancakeSwap, and then converts half of the contract’s WBNB into BUNNY tokens in the WBNB-BUNNY pool of PancakeSwap, and Add liquidity to the WBNB-BUNNY pool with the remaining WBNB tokens to obtain LP, and transfer this LP to the mintForV2 contract. And due to the unanticipated large amount of WBNB received in step 5 and the operation of converting WBNB to BUNNY tokens, the amount of WBNB in the WBNB-BUNNY pool will increase substantially.

After completing the zapInToken operation, the number of WBNB-BUNNY LPs currently received by the BunnyMinterV2 contract will be calculated and returned to mintForV2. The valueOfAsset function of the PriceCalculatorBSCV1 contract will then be called to The value of these LPs will be calculated in BNB (i.e., how many BNBs a single LP is worth). 9.

In the valueOfAsset calculation, it uses the number of WBNBs in the WBNB-BUNNY pool in real time multiplied by 2 and divided by the total number of WBNB-BUNNY LPs to calculate the value of a single LP (valueInBNB). However, after step 7, we can see that the unintended number of WBNBs in the WBNB-BUNNY pool has increased substantially, which results in a very high price relative to the BNB when calculating the value of a single LP.

  1. Subsequently, in mintForV2, the contract uses the LP value calculated in step 9 to calculate how many BUNNY tokens to mint for the attacker via the amountBunnyToMint function. However, the flawed price calculation results in the final LP price being inflated by the attacker’s malicious manipulation, which results in the BunnyMinterV2 contract eventually minting a large number of BUNNY tokens (about 6.97 million) for the attacker.

After getting the BUNNY tokens, the attackers sold them in batches into WBNB and USDT to return the lightning loans. After completing the entire attack, the attacker takes the money and walks away.


The key point is that the price calculation of WBNB-BUNNY LP is flawed, and the amount of BUNNY minted in the BunnyMinterV2 contract depends on this flawed LP price calculation, which eventually leads the attacker to manipulate the WBNB-BUNNY pool with lightning loans This led to the attacker manipulating the WBNB-BUNNY pool using lightning credits, thereby driving up the price of LPs and allowing the BunnyMinterV2 contract to mint a large number of BUNNY tokens for the attacker. The Slow Fog security team recommends using a trusted time-delayed feeding prophecy machine or refer to the previous Alpha Finance team when it comes to such LP price calculations.

Posted by:CoinYuppie,Reprinted with attribution to:
Coinyuppie is an open information publishing platform, all information provided is not related to the views and positions of coinyuppie, and does not constitute any investment and financial advice. Users are expected to carefully screen and prevent risks.

Like (0)
Donate Buy me a coffee Buy me a coffee
Previous 2021-05-20 13:10
Next 2021-05-20 13:14

Related articles