Toutes les vulnérabilités
CRITICALWeb3exploited in the wild

WEB3-BEC-2018

Web3 · Ethereum · Beauty Ecosystem Coin (BEC)

Résumé

On 22 April 2018 the Beauty Ecosystem Coin (BEC) ERC-20 token on Ethereum was drained by the classic batchOverflow attack, generating roughly 10^58 BEC and collapsing the token's value. The vulnerable batchTransfer(_receivers, _value) computed amount = cnt * _value in unchecked Solidity 0.4.x arithmetic, where cnt was the receiver count. The attacker passed two receivers with _value = 0x8000...0000 (2^255), so amount = 2 * 2^255 overflowed uint256 back to zero. That zero total passed the require(_value > 0 && balances[msg.sender] >= amount) balance check, yet the loop still credited each of the two receivers 2^255 tokens. This is a textbook unchecked integer (multiplication) overflow, assigned CVE-2018-10299, and it triggered the discovery of the same batchOverflow pattern in dozens of other ERC-20 contracts.

Comment l’éviter dans votre code

  • Use Solidity >=0.8 checked arithmetic or OpenZeppelin SafeMath for every multiply/add on token amounts and supplies
  • Never validate a balance against a product computed in unchecked arithmetic; compute and check each per-receiver debit
  • Reject zero or absurdly large transfer values; bound _value and the total against totalSupply before crediting anyone
  • Fuzz-test batch functions with boundary inputs (2^255, MAX_UINT/cnt) to catch overflow that bypasses require guards

Références

Vulnérabilités liées

Tout Web3 →