Toutes les vulnérabilités
CRITICALWeb3exploited in the wild

WEB3-GRIM-2021

Web3 · Fantom · Grim Finance

Résumé

On 18 December 2021 Grim Finance, a yield-optimizer vault protocol on Fantom, lost approximately $30 million. The vulnerable depositFor() function in the GrimBoostVault contract let the caller pass an arbitrary token address, pulled it via safeTransferFrom(), and computed the deposited amount as the balanceOf difference before and after the transfer to mint vault shares. The function had no reentrancy guard and did not whitelist the token, so the attacker supplied a malicious contract whose safeTransferFrom handed control flow back mid-execution, functionally an ERC-777-style pre-transfer hook. The attacker re-entered depositFor() five times before any frame finalized its share accounting; because each nested frame observed overlapping cumulative balance snapshots, the outer call was credited roughly five times the collateral actually deposited, over-minting shares against a flash-loaned position that was then redeemed to drain the vaults. This was an arbitrary-token-callback cross-function reentrancy.

Comment l’éviter dans votre code

  • Whitelist allowed deposit tokens; never let callers pass an arbitrary token or pool address into deposit logic
  • Guard depositFor and all share-minting entrypoints with a nonReentrant mutex
  • Avoid balanceOf before/after diff accounting when the token contract is untrusted or attacker-supplied
  • Mint shares and finalize accounting before returning, following checks-effects-interactions
  • Assume any external transferFrom/safeTransferFrom can call back into your contract

Références

Vulnérabilités liées

Tout Web3 →