Analysis of Attack on LibertiVault Contract on Polygon Chain

According to the Beosin EagleEye security risk monitoring, early warning and blocking platform monitoring of the blockchain security audit company Beosin,**, the LibertiVault contract on the Polygon chain was attacked, and the loss of about 123ETH and 56,234USDT worth about 290,000 US dollars, and the Ethereum chain 35ETH and 96223USDT are worth about US$160,000, totaling more than US$450,000. **Technical staff analyzed and found that this attack was caused by a reentrancy vulnerability in the LibertiVault contract.

  1. The attacker borrowed 5 million USDT using the flash loan, and called the deposit function of the LibertiVault contract to pledge. The pledge logic will use part of the pledged tokens for exchange, and then calculate the amount of minted coins. The amount of minted coins is based on the contract and the deposit The calculation is based on the ratio of the amount of tokens deposited to the balance before the contract is deposited.

  2. The exchange operation swap will call the hacker's contract. At this time, the hacker re-enters the call deposit for the first time, and re-enters this function for the second time, depositing 2.5 million USDT into the contract.

  3. After the second re-entry, the contract will mint coins for the hacker according to the ratio of 2.5 million USDT to the USDT balance of the previous contract. After the first re-entry deposit function is completed, the hacker deposits another 2.5 million USDT into it.

  4. At this point, the exchange operation in the outer deposit function is completed, and the contract will mint coins according to the ratio of 2.5 million USDT to the contract USDT balance.

  5. The problem lies in the fourth point. Logically speaking, the second calculation of the contract balance should be the previous balance plus the 2.5 million balance entered for the first time as the parameter for this calculation, but here is the In the form of reentry, the contract balance has been obtained at the very beginning, so the parameters have not changed, and the original balance is still used for calculation, resulting in minting a large number of voucher tokens for hackers.

  6. Finally, the hacker removed the tokens and returned the flash loan for profit.

View Original
This page may contain third-party content, which is provided for information purposes only (not representations/warranties) and should not be considered as an endorsement of its views by Gate, nor as financial or professional advice. See Disclaimer for details.
  • Reward
  • Comment
  • Repost
  • Share
Comment
0/400
No comments
Trade Crypto Anywhere Anytime
qrCode
Scan to download Gate App
Community
English
  • 简体中文
  • English
  • Tiếng Việt
  • 繁體中文
  • Español
  • Русский
  • Français (Afrique)
  • Português (Portugal)
  • Bahasa Indonesia
  • 日本語
  • بالعربية
  • Українська
  • Português (Brasil)