Slow Fog: Attackers Exploit LP Value Error and Fee Capture Quantity Error to Profit in AutoShark

According to Slow Fog Zone news, AutoShark Finance, a DeFi project on the Coin Security Smartchain (BSC), was hacked, causing a flash crash in token prices. Slow Fog security team followed up the analysis at the first time for your reference.
Due to the mechanism of AutoShark strategy pool, the attacker needs to deposit a certain amount of LP tokens into the strategy pool in advance to prepare for the subsequent attack, so the whole attack is actually divided into 2 steps.
The steps of the attack are as follows.
1. the attacker borrows a large amount of WBNB from the WBNB/BUSD pair of Pancake.
2. half of the total WBNB borrowed in step 1 is exchanged for a large amount of SHARK through Panther’s SHARK/WBNB pair, while the number of WBNB in the pool increases.
3. injecting WBNB and SHARK from steps 1 and 2 into SharkMinter in preparation for subsequent attacks.
4. call the getReward function in the WBNB/SHARK strategy pool of the AutoShark project, which will award SHARK tokens to the user as contribution value by taking a portion of the fees from the user’s profitable funds, which will be operated in the SharkMinter contract.
5. the SharkMinter contract, after receiving the LP handling fee from the user, will split the LP into the corresponding WBNB and SHARK and re-add them to the WBNB/SHARK pool of Panther.
Since the attacker in step 3 has already credited the corresponding tokens into the SharkMinter contract, when the SharkMinter contract adds liquidity after removing liquidity, it uses the WBNB and SHARK balance of the SharkMinter contract itself to add liquidity, which includes the WBNB and SHARK balance credited by the attacker in step 3. This balance includes the balance that the attacker credited to SharkMinter in step 3, resulting in the final contract getting the wrong balance for adding liquidity, i.e., the SharkMinter contract mistakenly believes that the attacker has credited a large amount of fees to the contract.
7. after the SharkMinter contract gets the amount of fees, it calculates the value of the fees through the tvlInWBNB function, and then mint SHARK tokens to the user based on the value of the fees. However, when calculating the value of LP, the real-time number of WBNBs in the Panther WBNB/SHARK pool is divided by the total number of LPs to calculate how many WBNBs can be exchanged for LPs, but since the number of WBNBs in the Panther pool is already very large in step 2, the calculated value of LPs is very high.
8. with the wrong value of LP and the wrong number of fees obtained, the SharkMinter contract ends up calculating a very large value when calculating the attacker’s contribution, resulting in the SharkMinter contract minting a large number of SHARK tokens to the attacker.
9. the attacker subsequently sells the SHARK tokens in exchange for WBNB to repay the lightning loan. and then leaves with a profit.

Previous:

Next: