Back to Blog

Wenn „SafeMint“ unsicher wird: Lehren aus dem HypeBears-Sicherheitsvorfall

Code Auditing
February 3, 2022
2 min read

Am Morgen des 3. Februar (Zeitzone +8) meldete unser System eine Angriffstransaktion 0xfa97c3476aa8aeac662dae0cc3f0d3da48472ff4e7c55d0e305901ec37a2f704 auf den HypeBears NFT-Vertrag. Nach der Untersuchung stellten wir fest, dass es sich um einen Re-entrancy-Angriff handelte, der durch die _safeMint-Funktion von ERC721 verursacht wurde.

Die Hauptursache

Das Projekt hat eine Begrenzung für die Anzahl der NFTs, die ein Konto prägen kann. Grundsätzlich gibt es eine Map addressMinted, die protokolliert, ob ein Konto NFTs geprägt hat.

Beim Prägen von NFTs verwendet der Code die _safeMint-Funktion der OZ-Referenzimplementierung. Diese Funktion ist "sicher", da sie prüft, ob der Empfänger ERC721-Token empfangen kann. Dies kann den Fall verhindern, dass ein NFT an einen Vertrag geprägt wird, der keine ERC721-Token verarbeiten kann. Laut der Dokumentation:

Wenn to sich auf einen Smart Contract bezieht, muss dieser IERC721Receiver.onERC721Received implementieren, der bei einer sicheren Übertragung aufgerufen wird. Der folgende Code zeigt die OZ-Implementierung der _safeMint-Funktion.

Dieser externe Funktionsaufruf schafft jedoch eine Sicherheitslücke. Insbesondere kann der Angreifer innerhalb des onERC721Received-Callback einen Reentrant-Aufruf durchführen. Zum Beispiel kann der Angreifer im anfälligen HypeBears-Vertrag die mintNFT-Funktion im onERC721Received-Callback erneut aufrufen (da addressMinted noch nicht aktualisiert wurde).

Der Angriff

Der folgende Screenshot zeigt die Angriffstransaktion.

Lektionen

Das von SafeMint ausgehende Risiko wurde von Sicherheitsexperten diskutiert link1 link2. Dennoch sind anfälliger Code und Angriffe in freier Wildbahn immer noch zu beobachten. Wie in der safeTransfer im QBridge-Sicherheitsvorfall gezeigt, garantiert die Verwendung einer sicheren Funktion keinen sicheren Vertrag 😃.

Sign up for the latest updates
~$4.72M Lost: TAC, Transit Finance & More | BlockSec Weekly
Security Insights

~$4.72M Lost: TAC, Transit Finance & More | BlockSec Weekly

This BlockSec weekly security report covers 3 notable attack incidents identified between May 11 and May 17, 2026, across TRON, TON, and Ethereum, with total estimated losses of approximately $4.72M. Three incidents are analyzed in detail: the highlighted $1.88M Transit Finance exploit on TRON, where a deprecated swap bridge contract with lingering token approvals was exploited through arbitrary calldata forwarding; the $2.8M TAC TON-to-EVM bridge exploit caused by missing canonical wallet verification in the jetton deposit flow; and the $46.75K Boost Hook exploit on Ethereum, where spot price manipulation on a Uniswap V4 hook-based perpetual protocol forced the protocol to buy tokens at inflated prices using its own reserves.

~$15.9M Lost: Trusted Volumes, Wasabi & More | BlockSec Weekly
Security Insights

~$15.9M Lost: Trusted Volumes, Wasabi & More | BlockSec Weekly

This BlockSec bi-weekly security report covers 11 notable attack incidents identified between April 27 and May 10, 2026, across Sui, Ethereum, BNB Chain, Base, Blast, and Berachain, with total estimated losses of approximately $15.9M. Three incidents are analyzed in detail: the highlighted $1.14M Aftermath Finance exploit on Sui, where a signed/unsigned semantic mismatch in the builder-fee validation allowed an attacker to inject a negative fee that was converted into positive collateral during settlement; the $5.87M Trusted Volumes RFQ authorization mismatch on Ethereum; and the $5.7M Wasabi Protocol infrastructure-to-contract-control compromise across multiple EVM chains.

Newsletter - April 2026
Security Insights

Newsletter - April 2026

In April 2026, the DeFi ecosystem experienced three major security incidents. KelpDAO lost ~$290M due to an insecure 1-of-1 DVN bridge configuration exploited via RPC infrastructure compromise, Drift Protocol suffered ~$285M from a multisig governance takeover leveraging Solana's durable nonce mechanism, and Rhea Finance incurred ~$18.4M following a business logic flaw in its margin-trading module that allowed circular swap path manipulatio

Best Security Auditor for Web3

Validate design, code, and business logic before launch. Aligned with the highest industry security standards.

BlockSec Audit