Back to Blog

重访虫洞攻击

Code Auditing
March 22, 2022
5 min read

1. 背景

虫洞(Wormhole),也称为爱因斯坦-罗森桥,是一种连接时空中不同点的推测性结构。在区块链领域,Wormhole 被用作不同链(例如 SolanaEthereum)之间的桥梁。用户可以通过 Wormhole 将代币化资产跨链转移。

2022 年 2 月 2 日,Wormhole 遭到黑客攻击,攻击者成功铸造了价值 3.2 亿美元的 120,000 枚 Wrapped Ether,这是 DeFi 历史上仅次于 Poly Network 的第二大损失。

2. Wormhole 的工作原理

Wormhole 的工作原理是通过监控每条链上发出的消息。监控到的消息将被转发到目标链,以便构建跨链通信协议。

直观的问题是如何保证被监控的消息是可信的。为了解决这个问题,Wormhole 引入了 19 个额外的节点,称为守护者(guardians)。当前的守护者集合可以在 Wormhole Explorer 中查看。每个守护者都可以独立验证监控到的消息并对其进行签名。

在 Wormhole 中,消息以 VAA 格式组织。VAA 由两部分组成。一部分是头部,用于收集守护者的签名。另一部分是主体,包含目标链信息、消息载荷等。

一旦守护者的签名达到共识阈值,VAA 就可以被发布到链上。

总之,守护者负责转移消息的完整性。

3. 代币桥

在介绍了消息如何在不同链之间转移之后,就不难理解 Wormhole 中的主要应用——代币桥是如何工作的了。

要将代币从链 A 转移到链 B,Wormhole 会在链 A 上锁定代币,然后在链 B 上铸造。这是高层次的想法。实际上,这可以分为三个步骤。首先,链 A 上的代币被锁定。其次,关于链 A 上的代币应转移到链 B 的消息被广播。第三,链 B 接收到消息,相应的代币被铸造。一切完成。

4. Solana 指令

在 Solana 中,一个 交易 由多个指令组成。每个指令包含一个程序 ID、账户和数据。程序 ID 代表将处理该指令的程序(智能合约)。程序将解释数据并操作提供的账户。

5. Wormhole 攻击

简而言之,攻击者在 Solana 上铸造了 120,000 枚 ETH,而无需在以太坊上锁定任何资产。交易 在此

因此,问题在于攻击者是如何能够在 Solana 上铸造这 120,000 枚 ETH 的。我们来详细说明一下步骤。为了铸造代币,调用了 complete_wrapped 指令。此指令接收多个地址,其中第三个是存储签名消息的地址。在铸造 120,000 枚 ETH 之前,链 B(即 Solana)应接收到签名消息(即 VAA),表明 120,000 枚 ETH 已在链 A(即以太坊)上被锁定。

要发布消息,会调用在 post_vaa.rs 中定义的 post_vaa。因此,将创建一个账户来存储消息。但是,post_vaa 不会检查守护者的签名。相反,在 verify_signatures.rs 中定义的 verify_signatures 会验证签名。

提供给 verify_signatures第四个账户是系统指令账户。现在让我们来探讨 verify_signatures 的工作原理。

第 103 行,调用 load_instruction_at 函数来加载之前执行的指令 secp_ixsecp_ix 将调用 Secp256k1 签名验证函数。因此,verify_signatures 通过检查之前执行的指令 secp_ix 来验证签名。现在,你明白一切了吗?load_instruction_at 函数不会检查从哪里加载指令!!!你需要从 Sysvar:Instructions 加载指令。

然而,攻击交易的第四个账户是 2tHS1cXX2h1KBEaadprqELJ6sV9wLoaSdX68FqsrrZRd,而不是 Sysvar:Instructions。在这种情况下,攻击者成功绕过了签名验证过程。Wormhole 认为验证已通过,消息已发布到链上,导致在没有锁定任何资产的情况下铸造了 120,000 枚 ETH!

让我们来看一个合法的验证 指令。此交易包含两个指令。第一个调用 Secp256k1 验证函数,第二个调用 verify_signatures 指令。请注意,这里的第四个账户是 Sysvar:Instructions。

在铸造了 120,000 枚 ETH 后,攻击者能够将其提取回以太坊,并兑换成其他代币以获利。

6. 补丁

仓库所述,自 1.8.0 版本以来,load_instruction_at 不安全,并且不会检查 Sysvar 账户地址。相反,推荐使用 load_instruction_at_checked

7. 我们的思考

  • 开发人员应该非常熟悉他们使用的外部函数。
  • 密切关注所用库的任何重要更改。如果库发生更改,使用该库的代码可能需要更改。
  • 库维护者应该意识到特定更改带来的潜在风险,并及时通知整个社区。仅仅添加注释可能无效且不足够。
  • 如果库和代码的版本发生变化,您的合约代码需要进行审计。

关于 BlockSec

BlockSec 是一家开创性的区块链安全公司,由一群全球杰出的安全专家于 2021 年创立。公司致力于增强新兴 Web3 世界的安全性和可用性,以促进其大规模采用。为此,BlockSec 提供智能合约和 EVM 链 安全审计服务,用于主动开发和阻止威胁的 Phalcon 平台,用于资金追踪和调查的 MetaSleuth 平台,以及用于 Web3 构建者高效冲浪加密世界的 MetaSuites 扩展。

迄今为止,公司已为 MetaMask、Uniswap Foundation、Compound、Forta 和 PancakeSwap 等 300 多家知名客户提供服务,并在两轮融资中从 Matrix Partners、Vitalbridge Capital 和 Fenbushi Capital 等领先投资者那里获得了数千万美元的投资。

官方网站:https://blocksec.com/

官方 Twitter 账号:https://twitter.com/BlockSecTeam

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