Fei Protocol Incident Analysis

Incident Summary

Context

  • FEI protocol is an algorithmic stable coin project for decentralized finance. Fei Protocol aims to help other DAOs achieve deep liquidity in lending and exchange markets by deploying PCV and offering Liquidity-as-a-Service (LaaS)
  • Rari Fuse Pool is a DeFi protocol that facilitates lending, borrowing and creating isolated lending markets with unlimited flexibility.

Exploit Transactions

Attack Flow

  1. Attacker flashloaned 150,000,000 USDC and 50,000 WETH
  2. Deposited 150,000,000 USDC as collateral into the fUSDC-127 contract, which is a vulnerable fork version of the compound protocol.
  3. With deposited collateral, the attacker borrowed 1,977 ETH via the “borrow()” function.
  4. However, the “borrow()” function does not follow the check-effect-interaction pattern. Specifically, it transfers ETH to the attacker’s contract before updating the attacker’s actual borrow records.
  5. Therefore, with the attacker’s borrow record not updated, the attacker made a reentrant call to “exitmarket()” in the fallback function, which allows the attacker to withdraw all his collateral (150M USDC)
  6. The attacker repeated steps 1~5 on multiple other tokens.
  7. Finally, the attacker repaid the flashloan and transferred the rest to their address as profit, and routed some of the funds onward to Tornado Cash.

Vulnerability

Profit and assets tracing

Can the issue be found in the audit?

  1. A low-level call is invoked to transfer ETH.
  2. The code in the “borrow” logic violates the check-effect-interaction pattern.

Conclusion

  1. Strictly follow the check-effect-interaction pattern.
  2. Re-entrancy protection modifier should cover all corresponding functions.
  3. Introduce a third-party audit service to review the codebase.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store