Back to Blog

当“安全转账”变得不安全:QBridge安全事件的教训

Code Auditing
January 28, 2022
3 min read

1月28日,QBridge遭到攻击,约8000万美元的资产被盗。经过分析,我们发现代码的根本原因是safeTransfer(和safeTransferFrom)函数的实现。

根本原因

首先,该项目没有使用流行的OpenZeppelin SafeERC20库进行代币转移。取而代之的是,他们实现了一个名为SafeToken的库。

其次,该实现没有检查目标是否为有效合约(或者是否为零地址)。

第三,**EVM的低级调用在目标合约为零时不会返回false。**这与开发者的常识相悖。

当然,此次事件还有其他原因,例如,零地址被加入白名单。然而,如果代码能够正确处理这种情况,那么它就不会存在漏洞。

顺便说一句:其他项目也使用了类似的.代码,它们可能也容易受到类似问题的影响。

实验

为了确认VM在目标合约为零时不返回false的第三个原因,我们开发了一个测试合约,如下所示。

TestSafeTransfer.test()的执行不会回滚。

教训和如何规避风险

我们建议:

  • 使用流行的库,而不是自己重新发明轮子,除非有非常非常充分的理由。
  • 在资产转移前后检查余额,以确保转移资产的数量符合预期。这也可以避免通缩和通胀代币的问题。

关于BlockSec

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

迄今为止,公司已为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