Back to Blog

闪电贷攻击APE空投简析

Code Auditing
March 17, 2022
3 min read

Will Sheehan 所报道,APE 代币受到了 MEV 的攻击。经过分析,我们认为这是由于 APE 代币的空投过程只考虑了即时状态的漏洞,攻击者可以操纵该状态。

具体来说,攻击者可以借入可以兑换成 NFT 的 BYAC 代币,然后使用这些 NFT 来申领空投。之后,攻击者通过 BYAC NFT 来铸造 BYAC 代币,以偿还闪电贷。然而,攻击者在此过程中获得了空投的 APE 代币。我们认为这类似于基于闪电贷的价格操纵攻击,即合约只考虑资产的即时价格(可以被操纵)。

接下来,我们将使用 攻击交易 来说明这一过程。

第一步:准备用于闪电贷费用的 NFT

攻击者将 1060 个 NFT 转入了攻击合约 0x7797。请注意,此 NFT 并非通过闪电贷借入,而是以 106 ETH 买入。

第二步:通过闪电贷借入 BYAC 代币

第三步:使用 NFT 申领 APE 代币

请注意,在此过程中,攻击者拥有六个 NFT。一个是其购买的 1060 个,另外五个是通过(第二步)借入的 BYAC 代币兑换而来的。总共获得了 60,564 个 APE 代币。

第四步:铸造 NFT 以获取 BYAC 代币

攻击者铸造了六个 NFT 以获取 BYAC 代币。请注意,攻击者还铸造了其自己的 NFT(1060 个)来支付闪电贷的费用。由于偿还闪电贷后仍有剩余的 BYAC 代币(因为他铸造了自己的 BYAC NFT 1060 个),攻击者将剩余的 BYAC 代币兑换了大约 14 ETH。

利润

总计,攻击者获得了 60,564 个 APE 代币,其价值约为 500 万美元(撰写本博客时)。成本是一个 NFT(106 ETH - 14 ETH),约为 270K 美元。

教训

我们认为这里的问题是,APE 代币的空投仅考虑了 NFT 是否被持有的即时状态。这很不安全,因为攻击者可以使用闪电贷操纵即时状态。如果闪电贷的成本小于空投代币的价值,那么就会出现如图所示的攻击机会。

致谢

感谢 Will Sheehan 报告了此次交易。

关于 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/

官方推特账号:https://twitter.com/BlockSecTeam

Sign up for the latest updates
~$4.72M Lost: TAC, Transit Finance & More | BlockSec Weekly
Security Insights

~$4.72M Lost: TAC, Transit Finance & More | BlockSec Weekly

This BlockSec weekly security report covers 3 notable attack incidents identified between May 11 and May 17, 2026, across TRON, TON, and Ethereum, with total estimated losses of approximately $4.72M. Three incidents are analyzed in detail: the highlighted $1.88M Transit Finance exploit on TRON, where a deprecated swap bridge contract with lingering token approvals was exploited through arbitrary calldata forwarding; the $2.8M TAC TON-to-EVM bridge exploit caused by missing canonical wallet verification in the jetton deposit flow; and the $46.75K Boost Hook exploit on Ethereum, where spot price manipulation on a Uniswap V4 hook-based perpetual protocol forced the protocol to buy tokens at inflated prices using its own reserves.

~$15.9M Lost: Trusted Volumes, Wasabi & More | BlockSec Weekly
Security Insights

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

Best Security Auditor for Web3

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

BlockSec Audit