Back to Blog

Mirror Protocol是如何被利用的

Code Auditing
May 31, 2022

@FatMan 报道,Mirror Protocol 遭到攻击。[该博客对此有很好的报道。](https://www.theblock.co/post/149342/a-90-million-defi-exploit-on-terra-went-unnoticed-for-seven-months) 在这篇短文中,我们将使用攻击交易来详细说明发生的情况。

免责声明:本文基于公开交易以及我们对 Mirror Protocol 和 Terra 生态系统的理解。如有任何不准确之处,请告知我们。欢迎对本博客发表任何评论。

1 攻击

1.1 准备

[此交易](https://finder.terra.money/classic/tx/29C9CFBBC9562100A5DB19D705E440CE24768D3BDE399507FA1C2EC2424413C4) 用于准备攻击。

步骤 1: 在此交易中,攻击者首先向锁定合约发送了 100,000 USTC。这并非开仓的必要条件,但对攻击至关重要。

步骤 2: 之后,攻击者通过存入 10 USTC 作为抵押品并指定抵押率 collateral_ratio 为 2.5 来开仓。

指定 short_params 是为了让铸造合约出售铸造的 mAssets(即 mETH),并将获得的 USTC 添加到头寸的锁定金额中。

步骤 2.1: 让我们分步进行交易。首先,将调用 open_position 函数来打开一个 ID 为 43186 的空头头寸。

步骤 2.2: 由于添加了可选的 short_params,合约将首先铸造 0.001208 mETH(基于当前 ETH 价格),然后通过在 mETH-UST Pair 中进行兑换来出售。

步骤 2.3: 0.001208 mETH 将被兑换成 4.06582 USTC,兑换后的 USTC 将在扣除相关费用(例如税费)后发送到锁定合约。这是因为开仓的头寸需要经过一定时间才能解锁。

步骤 2.4: 随后将调用 lock_position_funds_hook。在此函数中,将通过查询 current_balance 并将 current_balancelocked_funds 进行比较来计算 position_locked_amount

然而,正如我们在步骤 1 中所见,100,000 USTC 已直接转入锁定合约,因此 locked_amount 将约为 100,004 USTC,而不是 4 USTC。

步骤 2.5: 最后,将调用 increase_short_token 来记录 sLP 代币。

至此,攻击者通过直接发送 100,000 USTC 到锁定合约并以 10 USTC 作为抵押品来开仓。该头寸的锁定金额约为 100,004 USTC,并且可以在一段时间后解锁。攻击者通过发送 1,000100,000 USTC 来开设了许多此类头寸。

1.2. 攻击

Mirror Protocol 不检查头寸 ID 的重复性。在这种情况下,攻击者可以反复输入许多重复的头寸 ID 来解锁一个头寸中的锁定金额。

[此交易](https://finder.terra.money/classic/tx/08DD2B70F6C2335D966342C20C1E495FD7A8872310B80BAF3450B942F79EBC1F) 是攻击交易。例如,对于头寸 ID 43186,攻击者将其复制了 437 次。

由于原始合约代码不检查重复性,因此(在此单次函数调用中)约有 43.7M437 * 0.1M)USTC 被解锁。

请注意,其他头寸也通过相同的机制被解锁。

2. Bug 修复

该漏洞已在此 [commit](https://github.com/Mirror-Protocol/mirror-contracts/commit/56cc6946b9457293ede6aa0feb296ee1d16f6974) 中修复。

具体来说,unlockable_positions 是一个包含待解锁头寸 ID 的向量。在原始代码中,没有检查 unlockable_positions 是否包含重复的 ID。修补后的代码添加了对头寸 ID 重复性的检查。

3. 结论

正如 @FatMan 和其他社区成员所指出的,这个 bug 已经存在了好几个月,并且已经被利用。我们认为,对于一个已被利用的漏洞进行静默修复不是一个好的安全实践。此外,我们也认为高知名度的 DeFi 项目应该部署一些守门人来主动监控其应用程序的状态,并在发生异常情况时发出警报。

Sign up for the latest updates
Tracing $1.6B in TRON USDT: Inside the VerilyHK Ponzi Infrastructure
Case Studies

Tracing $1.6B in TRON USDT: Inside the VerilyHK Ponzi Infrastructure

An on-chain investigation into VerilyHK, a fraudulent platform that moved $1.6B in TRON USDT through a multi-layered fund-routing infrastructure of rotating wallets, paired payout channels, and exchange exit funnels, with traced connections to the FinCEN-sanctioned Huione Group.

Weekly Web3 Security Incident Roundup | Mar 30 – Apr 5, 2026
Security Insights

Weekly Web3 Security Incident Roundup | Mar 30 – Apr 5, 2026

This BlockSec weekly security report covers nine DeFi attack incidents detected between March 30 and April 5, 2026, across Solana, BNB Chain, Arbitrum, and Polygon, with total estimated losses of approximately $287M. The week was dominated by the $285.3M Drift Protocol exploit on Solana, where attackers combined multisig signer social engineering with Solana's durable nonce mechanism to bypass a zero-timelock 2-of-5 Security Council, alongside notable incidents including a $950K flash loan TWAP manipulation against the LML staking protocol, a $359K Silo Finance vault inflation via an external `wstUSR` market donation exploiting a depegged-asset oracle and `totalAssets()` accounting flaw, and an EIP-7702 delegated-code access control failure. The report provides detailed vulnerability analysis and attack transaction breakdowns for each incident, covering flawed business logic, access control, price manipulation, phishing, and misconfiguration attack types.

Drift Protocol Incident: Multisig Governance Compromise via Durable Nonce Exploitation
Security Insights

Drift Protocol Incident: Multisig Governance Compromise via Durable Nonce Exploitation

On April 1, 2026 (UTC), Drift Protocol on Solana suffered a $285.3M loss after an attacker exploited Solana's durable nonce mechanism to delay the execution of phished multisig approvals, ultimately transferring administrative control of the protocol's 2-of-5 Squads governance with zero timelock. With full admin privileges, the attacker created a malicious collateral market (CVT), inflated its oracle price, relaxed withdrawal protections, and drained USDC, JLP, SOL, cbBTC, and other assets through 31 rapid withdrawals in approximately 12 minutes. This incident highlights how durable nonce-based delayed execution can decouple signer intent from on-chain execution, bypassing the temporal assumptions that multisig security implicitly relies on.

Best Security Auditor for Web3

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

BlockSec Audit