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
Building a Secure Stablecoin Payment Network: BlockSec Partners with Morph
Partnership

Building a Secure Stablecoin Payment Network: BlockSec Partners with Morph

BlockSec has partnered with Morph as an official audit partner for the $150M Morph Payment Accelerator. By offering exclusive discounts on smart contract audits and penetration testing, BlockSec provides institutional-grade security to payment builders, ensuring a safe and resilient foundation for the future of global stablecoin payments.

Weekly Web3 Security Incident Roundup | Mar 9 – Mar 15, 2026
Security Insights

Weekly Web3 Security Incident Roundup | Mar 9 – Mar 15, 2026

This BlockSec weekly security report covers eight DeFi attack incidents detected between March 9 and March 15, 2026, across Ethereum and BNB Chain, with total estimated losses of approximately $1.66M. Incidents include a $1.01M AAVE incorrect liquidation caused by oracle misconfiguration, a $242K exploit on the deflationary token MT due to flawed trading restrictions, a $149K exploit on the burn-to-earn protocol DBXen from `_msgSender()` and `msg.sender` inconsistency, and a $131K attack on AM Token exploiting a flawed delayed-burn mechanism. The report provides detailed vulnerability analysis and attack transaction breakdowns for each incident.

Venus Thena (THE) Incident: What Broke and What Was Missed

Venus Thena (THE) Incident: What Broke and What Was Missed

On March 15, 2026, an attacker bypassed the THE (Thena) supply cap on Venus Protocol (BNB Chain) through a donation attack, inflating a collateral position to 3.67x the intended limit and borrowing ~$14.9M in assets. Both sides lost money on-chain: Venus was left with ~$2.15M in bad debt after 254 liquidation bots competed across 8,048 transactions, while the attacker retained only ~$5.2M against a $9.92M investment. This deep dive examines what broke across three lines of defense (exposure limits, collateral valuation, and liquidation) and the monitoring gaps that left months of on-chain warning signals unacted upon.

Best Security Auditor for Web3

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

BlockSec Audit