Back to Blog

安全检查:EVM兼容链是否可靠?

Code Auditing
January 4, 2024
6 min read

2023年11月,BlockSec首席执行官周亚进教授应邀参加了由DRK Lab主办的首届Web3学者峰会。在会议上,周教授分享了BlockSec在EVM(以太坊虚拟机)漏洞检测方面的工作和成果。他还介绍了BlockSec专为确保EVM兼容链安全性而设计的自动化差分模糊测试工具。本文总结了演讲的内容。

引言

根据Defillama的数据统计,目前共有238条L1和L2公链,其中144条兼容EVM。然而,问题随之而来:这些兼容EVM的链在实现过程中是否存在安全问题?经过我们的研究,答案是肯定的。为了应对这一担忧,BlockSec推出了一款自动化的差分模糊安全测试工具。让我们一起踏上探索这些EVM兼容链背后真相的旅程。

虚拟机中的漏洞

图1:以太坊虚拟机(EVM)工作流程图
图1:以太坊虚拟机(EVM)工作流程图

以以太坊虚拟机(EVM)为例,它采用基于堆栈的架构,包括虚拟机ROM、程序计数器、堆栈、内存和世界状态(持久性)。

虚拟机充当解释和执行智能合约编译后的二进制代码的引擎。虚拟机是许多区块链平台的核心组件,其中以太坊虚拟机(EVM)尤为值得注意。因此,虚拟机在执行智能合约、处理交易和确保区块链的完整性方面起着关键作用。

我们知道,EVM本身也是由程序员编写的软件程序。然而,我们如何确保EVM没有问题呢?毕竟,任何由人类编写的代码都可能存在bug。

一旦EVM中出现bug,将对区块链上的生态系统产生灾难性后果。事实上,EVM在过去已经遇到过许多严重的漏洞。

例如,2020年,由于预编译合约(即 CVE-2020-26241)[1] 导致了一个漏洞事件。Geth(位于0x00...04)协议中的dataCopy预编译合约在调用时执行了浅拷贝,当复制大量数据时,只复制了指针而不是完整的数据。这使得恶意智能合约可以修改不应被修改的数据,导致不同版本的虚拟机执行相同智能合约时出现数据不一致。另一个例子发生在2021年,当时某些EVM兼容链没有与以太坊同步升级。在旧版本的Geth中,存在一个漏洞(CVE-2021-39137)[2],预编译合约调用的输入和输出数据的内存区域发生重叠。攻击者利用了这个漏洞,导致了链分叉。

BlockSec的应对措施

如何及时发现EVM中的漏洞?挑战在哪里?

  1. 首先,由于虚拟机设计的复杂性,很难找到能够完全理解其运行逻辑的工具。每个专业领域都需要专门知识,许多开发人员可能无法投入足够的精力来理解其运行逻辑并采取有效的预防措施。

  2. 此外,许多L1/L2新公链会定制EVM虚拟机,这可能会引入新的安全问题。

显然,仅仅依靠人工审计来发现EVM虚拟机上的这些问题是困难的。

适应并做出相应的回应!针对这些挑战,BlockSec开发了一个自动化系统来直接应对这些问题!

差分模糊测试

在BlockSec,我们的专家团队采用了一种巧妙的方法,称为差分模糊测试。通过在不同版本的虚拟机上执行相同的测试用例并比较输出结果,我们可以发现潜在的漏洞和不一致之处。这种方法使我们能够有效地识别传统测试方法可能忽略的细微差异,从而提高系统的整体安全性。

图2:差分模糊测试工作流程
图2:差分模糊测试工作流程

基本工作原理:

为了进行差分模糊测试,我们需要准备相同的输入作为测试用例。然后将这些测试用例输入差分模糊测试引擎。通过比较在不同版本虚拟机上执行相同测试用例的输出,我们可以发现潜在问题。

具体实施步骤:

差分模糊测试的测试用例需要包含两部分:交易元数据和预状态。但我们如何生成这些交易呢?我们有两种方法来应对这一挑战。

  1. 重用历史交易:我们可以检索区块链上发生的历史交易,并在差分模糊测试引擎中将它们运行在不同版本的虚拟机上。然而,仅依赖这种方法存在局限性。历史交易往往过于“正常”,而安全测试需要发现角落情况——异常场景。这就是为什么我们提出了第二种方法。
  2. 覆盖率引导模糊测试:我们从头开始生成不常见的字节码和历史上未见的交易,然后对交易和智能合约代码进行变异,并将它们输入虚拟机。我们从多个维度确保测试用例的有效性和全面性。

一旦这些交易被生成,它们就会被输入差分模糊测试引擎,然后对结果进行比较。

结果比较不仅仅是简单的数字比较,还会全面考虑虚拟机中持久性和非持久性存储的数据一致性。本文将不再深入阐述。

案例研究

图3:Aurora VM中预编译合约*ModExp*问题的示例
图3:Aurora VM中预编译合约ModExp问题的示例

我想分享一个我们通过差分模糊测试在Aurora VM中发现的虚拟机漏洞案例。具体来说,它与ModExp预编译智能合约的一个问题有关。

在计算一个数x的y次幂的模幂时,我们知道这个运算需要计算资源。在正确的实现中,gas计算会考虑到迭代次数,因为模幂运算涉及多次迭代。然而,在一种特定情况下,gas计算会遇到问题:当指数y等于0时,表示一个零阶幂运算。在这种情况下,迭代次数为零,导致gas值极小。但实际上,计算仍然需要资源。

结论

目前,BlockSec推出的差分模糊测试工具支持在包括rbpfubpfAurora-engineneon-evmMoonbeamrevmEvmOSfevmPolygon-zkevm在内的各种区块链虚拟机环境中执行,并且正在持续扩展。

通过该工具,我们发现了14个新漏洞,申请了2个CVE:CVE-2021–46102CVE-2022–23066,并获得了超过130万美元的漏洞赏金。

目前,BlockSec提供的全面EVM链安全解决方案(审计服务+差分模糊测试工具)已被EOS和FileCoin认可并采用,并将为其生态系统的安全和健康发展做出贡献。

参考

[1] 0x4预编译中的浅拷贝可能导致EVM内存损坏

[2] 通过datacopy进行RETURNDATA损坏

关于BlockSec

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

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

✉️商务咨询:[email protected]

BlockSec的Twitter账号:https://twitter.com/BlockSecTeam

Phalcon的Twitter账号:https://twitter.com/Phalcon_xyz

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