Platypus Stablecoin USP Hack Analysis — Withdraw funds without paying the debt

Shashank
SolidityScan
Published in
3 min readFeb 17, 2023

--

Overview:

On February 16th, 2023, a hack on the platypus stablecoin DeFi platform lets an attacker withdraw funds without paying back the loans they had previously taken out. During the smart contract hack analysis, it was discovered that the emergency Withdraw feature did not verify that the user had paid back the loan before enabling them to transfer funds directly from the pool, resulting in a loss of approximately $9.05M.

Smart Contract Hack Overview:

Attacker’s transaction

Decoding the Smart Contract Vulnerability:

  • The attacker began by obtaining a flash loan from AAVE for 44M USDC to deposit to Platypus Finance Pool and minted ~44M LP-USDC equivalent.
  • The attacker then borrowed 42 million USP tokens from the Platypus Treasury and placed 44 million LP-USDC tokens into the MasterPlatypusV4 contract.
  • The attacker calls the emergencyWithdraw() function of the MasterPlatypusV4 contract where the contract gets broken, the function first checks if a user isSolvent. Since the user.amount was not set to zero, the platypus finance contract treated the user as solvent and permitted emergency withdrawal.
  • To further exploit the loophole attacker withdrew 44M USDC from the Platypus Finance pool and swapped USP to USDT, BUSD, DAI, and USDC.e to gain profits, and the flash loan was repaid at last.

Mitigation and Best Practices:

  • To prevent reentrancy attacks, consider moving the lpToken.transfer() call to the end of the function after all other state changes have been made. Alternatively, consider using the `OpenZeppelin ReentrancyGuard library`, which provides more robust protection against reentrancy attacks.
  • Add a check to ensure that the user.amount is greater than or equal to the amount being withdrawn before transferring the tokens to the user.
  • Update the users balance so that it can’t be treated as a solvent to the platypus finance contract.
  • To prevent such vulnerabilities, the best Smart Contract auditors must examine the Smart Contracts for logical issues. We at CredShields provide smart contract security and end-to-end security of web applications and externally exposed networks. Schedule a call at https://credshields.com/
  • Scan your Solidity contracts against the latest common security vulnerabilities with 130+ detection at SolidityScan including access control vulnerabilities.
SolidityScan — Smart Contract Vulnerability Scanner

Conclusion:

SolidityScan is an advanced smart-contract scanning tool that discovers vulnerabilities and reduces risks in code. Request a security audit with us, and we will help you secure your smart contracts. Signup for a free trial at https://solidityscan.com/signup

Follow us on our Social Media for Web3 security-related updates.
SolidityScan — LinkedIn | Twitter | Telegram | Discord

--

--