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
~$15.9M Lost: Trusted Volumes & More | BlockSec Weekly
Security Insights

~$15.9M Lost: Trusted Volumes & 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

~$7.04M Lost: GiddyDefi, Volo Vault & More | BlockSec Weekly
Security Insights

~$7.04M Lost: GiddyDefi, Volo Vault & More | BlockSec Weekly

This BlockSec weekly security report covers eight attack incidents detected between April 20 and April 26, 2026, across Ethereum, Avalanche, Sui, Base, HyperLiquid, and MegaETH, with total estimated losses of approximately $7.04M. The highlighted incident is the $1.3M GiddyDefi exploit, where the attacker did not break any cryptography or use a flash loan but simply replayed an existing on-chain EIP-712 signature with the unsigned `aggregator` and `fromToken` fields swapped out for a malicious contract, demonstrating how partial signature coverage turns any historical signature into a generic permit. Other incidents include a $3.5M Volo Vault operator key compromise on Sui, a $1.5M Purrlend privileged-role takeover, a $413K SingularityFinance oracle misconfiguration, a $142.7K Scallop cross-pool index injection, a $72.35K Kipseli Router decimal mismatch, a $50.7K REVLoans (Juicebox) accounting pollution, and a $64K Custom Rebalancer arbitrary-call exploit.

Best Security Auditor for Web3

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

BlockSec Audit