Back to Blog

当“SafeMint”不再安全:HypeBears安全事件的教训

Code Auditing
February 3, 2022
2 min read

在东八区时间 2 月 3 日上午,我们的系统报告了一笔针对 HypeBears NFT 合约的攻击交易 0xfa97c3476aa8aeac662dae0cc3f0d3da48472ff4e7c55d0e305901ec37a2f704。经过调查,我们发现这是由 ERC721 的 _safeMint 函数引起的重入攻击。

根本原因

该项目对一个账户可以铸造的 NFT 数量有限制。基本上,它有一个 addressMinted 的映射,用于记录一个账户是否已经铸造过 NFT。

在铸造 NFT 时,代码使用了 OZ 参考实现中的 _safeMint 函数。这个函数是 safe 的,因为它检查接收方是否可以接收 ERC721 代币。这可以防止 NFT 被铸造到无法处理 ERC721 代币的合约中。根据 文档:

如果 to 指的是一个智能合约,它必须实现 IERC721Receiver.onERC721Received,该函数在安全转账时被调用。以下代码显示了 OZ 对 _safeMint 函数的实现。

然而,这个外部函数调用会产生一个安全漏洞。具体来说,攻击者可以在 onERC721Received 回调中执行重入调用。例如,在 有漏洞的 HypeBears 合约 中,攻击者可以在 onERC721Received 回调中再次调用 mintNFT 函数(因为 addressMinted 尚未更新)。

攻击

下图显示了 攻击交易

教训

安全研究人员讨论过 SafeMint 带来的风险 链接1 链接2。然而,我们仍然可以看到有漏洞的代码和实际发生的攻击。正如在 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