On July 18, 2023, Beijing time, Ocean BNO suffered a flash loan attack, and the attacker has made a profit of about 500,000 US dollars.
SharkTeam conducted a technical analysis of this incident for the first time, and summarized the security precautions, hoping that follow-up projects can learn from it and jointly build a security defense line for the blockchain industry.
Attacker address:
0xa6566574edc60d7b2adbacedb71d5142cf2677fb
Attack contract:
0xd138b9a58d3e5f4be1cd5ec90b66310e241c13cd
Attacked contract:
0xdCA503449899d5649D32175a255A8835A03E4006
Attack transactions:
0x33fed54de490797b99b2fc7a159e43af57e9e6bdefc2c2d052dc814cfe0096b9
Attack process:
(1) The attacker (0xa6566574) borrowed 286,449 BNOs through pancakeSwap flash loan.
(2) Then call the stakeNft function of the attacked contract (0xdCA50344) to pledge two nft.
(3) Then call the pledge function of the attacked contract (0xdCA50344) to pledge 277856 BNO coins.
(4) Call the emergencyWithdraw function of the attacked contract (0xdCA50344) to extract all BNO
(5) Then call the unstakeNft function of the attacked contract (0xdCA50344), retrieve the two pledged nft and receive additional BNO tokens.
(6) Repeat the above process to continuously obtain additional BNO tokens
(7) After repaying the flash loan, exchange all BNO tokens for 50.5W BUSD and leave the market with a profit.
The root cause of this attack is: there is a problem with the reward calculation mechanism and the interaction logic of the emergency withdrawal function in the attacked contract (0xdCA50344), which causes the user to get an additional reward token after withdrawing the principal.
The contract provides the emergencyWithdraw function for emergency withdrawal of tokens, and clears the attacker’s allstake total mortgage and rewardDebt total debt, but does not clear the attacker’s nftAddition variable, and the nftAddition variable is also calculated through the allstake variable.
In the unstakeNft function, the user’s current reward will still be calculated, and if the nftAddition variable is not reset to zero, the pendingFit function will still return an additional BNO reward value, causing the attacker to obtain additional BNO tokens.
In response to this attack, we should follow the following precautions during the development process:
(1) When calculating rewards, verify whether the user has withdrawn the principal.
(2) Before the project goes online, it is necessary to seek technical assistance from a third-party professional audit team.