Toutes les vulnérabilités
CRITICALWeb3exploited in the wild

WEB3-DFORCE-2020

Web3 · Ethereum · dForce Lendf.me

Résumé

On 19 April 2020 the dForce Lendf.me lending market on Ethereum lost roughly $25 million across more than ten supported assets. Lendf.me was a fork of Compound v1's MoneyMarket contract and accepted imBTC, an ERC-777 token whose ERC-20 transferFrom path silently fires the sender's tokensToSend hook (registered via the ERC-1820 registry) before balances settle. The supply() function cached the caller's current collateral into a local variable, then called doTransferIn() which invoked imBTC.transferFrom() before writing the updated balance to storage, violating checks-effects-interactions. The transfer fired the attacker's tokensToSend hook, which cross-function re-entered withdraw() to pull imBTC back out and correctly decrement stored collateral; control then returned to supply(), which overwrote storage with the stale cached value and erased the withdrawal. Each loop minted phantom collateral that was used to borrow and drain every pool, an ERC-777 cross-function reentrancy.

Comment l’éviter dans votre code

  • Apply checks-effects-interactions: write updated balances to storage before any token transfer or external call
  • Guard supply/withdraw and all state-changing entrypoints with a nonReentrant mutex covering cross-function paths
  • Never cache balances in locals across an external call; re-read storage after the call returns
  • Treat ERC-777/ERC-677/ERC-1363 transfer hooks (tokensToSend, tokensReceived) as untrusted reentry points
  • Whitelist supported collateral tokens and reject assets with callback-bearing transfer semantics

Références

Vulnérabilités liées

Tout Web3 →