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
~$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