Mosca Hack Analysis

On January 8, 2025, the Mosca contract on BSC was hacked because of a flaw when updating user’s balance, resulting in a loss of approximately $19,485.

Overview

Analysis

When users join(), they are added to a rewardQueue. From now, they will gain rewards whenever other users buy() or swap() tokens.

Thanks for reading Verichains! Subscribe for free to receive new posts and support my work.

When users decide to leave, exitProgram() is invoked. It loops through rewardQueue, when the user is match, it calls withdrawAll() to transfer all pending rewards to user.

In withdrawAll(), the total reward of user is calculated as:
balance = user.balance + user.balanceUSDT + user.balanceUSDC
However, in exitProgram(), only user.balance is set to 0, user.balanceUSDT and user.balanceUSDC still hold values after user exit. The hacked exploited this vulnerability in the hack.

The hacker first join() the protocol and successfully deposits some assets (step 4). Then, they leverage a pool to perform a flash loan (step 15) and create a ‘fake’ buy() operation (step 23) to gain rewards for themselves. Finally, they repeatedly invoke join() and exitProgram() to drain USDC from the contract.

Conclusion

The developers violated the Checks-Effects-Interactions pattern and deployed the Mosca contract only a few days before the hack, which may indicate they are under high time-pressure and the product is lack of testing. To prevent such issues, we strongly recommend implementing robust audit processes from the initial stages of development and throughout the entire lifespan of the project. Regular security audits, code reviews, and vulnerability assessments should be standard practice to identify and address potential risks before they are exploited.

Thanks for reading Verichains! Subscribe for free to receive new posts and support my work.

Source
Disclaimer: The content above is only the author's opinion which does not represent any position of Followin, and is not intended as, and shall not be understood or construed as, investment advice from Followin.
Like
Add to Favorites
Comments