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
The Decentralization Dilemma: Cascading Risk and Emergency Power in the KelpDAO Crisis
Security Insights

The Decentralization Dilemma: Cascading Risk and Emergency Power in the KelpDAO Crisis

This BlockSec deep-dive analyzes the KelpDAO $290M rsETH cross-chain bridge exploit (April 18, 2026), attributed to the Lazarus Group, tracing a causal chain across three layers: how a single-point DVN dependency enabled the attack, how DeFi composability cascaded the damage through Aave V3 lending markets to freeze WETH liquidity exceeding $6.7B across Ethereum, Arbitrum, Base, Mantle, and Linea, and how the crisis forced decentralized governance to exercise centralized emergency powers. The article examines three parameters that shaped the cascade's severity (LTV, pool depth, and cross-chain deployment count) and provides an exclusive technical breakdown of Arbitrum Security Council's forced state transition, an atomic contract upgrade that moved 30,766 ETH without the holder's signature.

Weekly Web3 Security Incident Roundup | Apr 13 – Apr 19, 2026
Security Insights

Weekly Web3 Security Incident Roundup | Apr 13 – Apr 19, 2026

This BlockSec weekly security report covers four attack incidents detected between April 13 and April 19, 2026, across multiple chains such as Ethereum, Unichain, Arbitrum, and NEAR, with total estimated losses of approximately $310M. The highlighted incident is the $290M KelpDAO rsETH bridge exploit, where an attacker poisoned the RPC infrastructure of the sole LayerZero DVN to fabricate a cross-chain message, triggering a cascading WETH freeze across five chains and an Arbitrum Security Council forced state transition that raises questions about the actual trust boundaries of decentralized systems. Other incidents include a $242K MMR proof forgery on Hyperbridge, a $1.5M signed integer abuse on Dango, and an $18.4M circular swap path exploit on Rhea Finance's Burrowland protocol.

Weekly Web3 Security Incident Roundup | Apr 6 – Apr 12, 2026
Security Insights

Weekly Web3 Security Incident Roundup | Apr 6 – Apr 12, 2026

This BlockSec weekly security report covers four DeFi attack incidents detected between April 6 and April 12, 2026, across Linea, BNB Chain, Arbitrum, Optimism, Avalanche, and Base, with total estimated losses of approximately $928.6K. Notable incidents include a $517K approval-related exploit where a user mistakenly approved a permissionless SquidMulticall contract enabling arbitrary external calls, a $193K business logic flaw in the HB token's reward-settlement logic that allowed direct AMM reserve manipulation, a $165.6K exploit in Denaria's perpetual DEX caused by a rounding asymmetry compounded with an unsafe cast, and a $53K access control issue in XBITVault caused by an initialization-dependent check that failed open. The report provides detailed vulnerability analysis and attack transaction breakdowns for each incident.

Best Security Auditor for Web3

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

BlockSec Audit