Back to Blog

Mirror Protocol 如何被利用

Code Auditing
May 31, 2022
4 min read

@FatMan报道,Mirror Protocol 遭受了黑客攻击。这篇博客对此有很好的报道。在这篇短文中,我们将使用攻击交易来详细说明这是如何发生的。

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

1. 攻击

1.1. 准备

该交易用于准备攻击。

步骤 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,合约将首先根据当前 ETH 价格铸造 0.001208 mETH,然后通过在 mETH-UST Pair 中进行兑换来出售。

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

步骤 2.4: 接着将调用 lock_position_funds_hook。在此函数中,通过查询 current_balance 并将 current_balance 与 locked_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 来解锁一个仓位中的锁定金额。

该交易是攻击交易。 例如,对于仓位 ID 43186,攻击者重复了 437 次。

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

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

2. Bug 修复

该漏洞已在此提交中修复。

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

3. 结论

正如 @FatMan 和其他社区成员指出的那样,此 bug 已存在数月并在野外被利用。我们认为,对已被利用的漏洞进行悄无声息的修复并不是一种好的安全实践。此外,我们也认为高知名度的 DeFi 项目应该部署一些守门员,主动监控其应用程序的状态,并在出现异常情况时发出警报。

Sign up for the latest updates
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.

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.

Best Security Auditor for Web3

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

BlockSec Audit