Back to Blog

ミラープロトコルがどのように悪用されたか

Code Auditing
May 31, 2022
4 min read

Mirror Protocolが@FatManによって不正利用されたと報告されました。このブログには、その件に関する優れたレポートがあります。](https://www.theblock.co/post/149342/a-90-million-defi-exploit-on-terra-went-unnoticed-for-seven-months) この短い記事では、攻撃トランザクションを使用して、どのようにしてこれが起こったのかを詳しく説明します。

免責事項:この記事は、公開されているトランザクションと、Mirrorプロトコルおよび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が追加されているため、コントラクトはまず0.001208 mETH(現在のETH価格に基づく)をミントし、次にmETH-USTペアでスワップして販売します。

ステップ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_amount4 USTCではなく、約100,004 USTCになります。

ステップ2.5: 最後に、increase_short_tokenが呼び出され、sLPトークンが記録されます。

これにより、攻撃者は直接ロックコントラクトに100,000 USTCを送信し、担保として10 USTCを送信してポジションを開きました。ポジションのロックされた金額は約100,004 USTCであり、一定期間後にアンロックできます。攻撃者は、1,000から100,000 USTCを送信して、このような多くのポジションを開きました。

1.2. 攻撃

Mirror Protocolは、ポジションIDの重複をチェックしません。この場合、攻撃者は1つのポジションのロックされた金額を繰り返しアンロックするために、多くの重複したポジションIDを供給できます。

トランザクションは、攻撃トランザクションです。例えば、ポジションID 43186の場合、攻撃者は437回重複させました。

元のコントラクトコードは重複をチェックしないため、約43.7M437 * 0.1M)USTCがアンロックされました(この単一の関数呼び出しで)。

他のポジションも同様のメカニズムでアンロックされていることに注意してください。

2. バグ修正

この脆弱性は、このコミットで修正されました。

具体的には、unlockable_positionsはアンロックされるポジションIDを含むベクトルです。元のコードでは、unlockable_positionsに重複したIDがないかどうかのチェックがありませんでした。パッチが適用されたコードでは、ポジションIDの重複チェックが追加されています。

3. 結論

@FatManや他のコミュニティメンバーが指摘したように、このバグは数ヶ月前から存在しており、実際に悪用されていました。すでに悪用されている脆弱性を静かにパッチすることは、優れたセキュリティプラクティスではないと考えています。さらに、注目度の高い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