Back to Blog

「セーフミント」が危険に:HypeBearsセキュリティインシデントから学ぶ教訓

Code Auditing
February 3, 2022
2 min read

2月3日午前(+8時差)、当社のシステムは、HypeBears NFTコントラクトに対する攻撃トランザクション 0xfa97c3476aa8aeac662dae0cc3f0d3da48472ff4e7c55d0e305901ec37a2f704 を報告しました。調査の結果、ERC721の_safeMint関数によって引き起こされたリエントランシー攻撃であることが判明しました。

原因

このプロジェクトでは、アカウントがミントできるNFTに制限があります。基本的に、アカウントがNFTをミントしたかどうかを記録するaddressMintedというマップがあります。

NFTをミントする際、コードはOZリファレンス実装の_safeMint関数を使用しています。この関数は、受信者がERC721トークンを受け取れるかどうかをチェックするため「安全」です。これにより、ERC721トークンを処理できないコントラクトにNFTがミントされるケースを防ぐことができます。 ドキュメントによると:

to がスマートコントラクトを参照する場合、IERC721Receiver.onERC721Received を実装する必要があり、これはセーフ転送時に呼び出されます。以下のコードは、_safeMint関数のOZ実装を示しています。

しかし、この外部関数呼び出しはセキュリティ上の抜け穴を生み出します。具体的には、攻撃者はonERC721Receivedコールバック内で再入可能呼び出しを実行できます。例えば、脆弱なHypeBearsコントラクトでは、攻撃者はonERC721ReceivedコールバックでmintNFT関数を再度呼び出すことができます(addressMintedがまだ更新されていないため)。

攻撃

以下のスクリーンショットは、攻撃トランザクションを示しています。

学び

SafeMintによるリスクは、セキュリティ研究者によって議論されてきました。link1 link2。しかし、脆弱なコードと実際の攻撃を依然として目にします。QBridgeセキュリティインシデントsafeTransferで示されているように、「安全な」関数を使用しても「安全な」コントラクトが保証されるわけではありません😃。

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