损失超过 4000 万美元,GMX 攻击原理分析

链捕手Published on 2025-07-10Last updated on 2025-07-10

作者:BlockSec

GMX 遭遇黑客攻击,损失超过 4000 万美元。攻击者利用了一个可重入漏洞,并在合约启用杠杆功能的情况下开空头头寸,实施了攻击。

问题的根源在于 executeDecreaseOrder 函数被错误使用。该函数的第一个参数本应是外部账户(EOA),但攻击者传入了一个智能合约地址。这使得攻击者可以在赎回过程中重新进入系统,操纵内部状态,最终赎回的资产远超过其实际持有的 GLP 价值

GLP正常赎回机制

GMX 中,GLP 是流动性提供者代币,代表对金库资产(如 USDC、ETH、WBTC)的份额。当用户调用 unstakeAndRedeemGlp 时,系统使用以下公式计算应返还的资产数量:

redeem_amount = (user_GLP / total_GLP_supply) * AUM

其中 AUM(管理资产总额)的计算方式为:

AUM = 所有 token 池的总价值 + 全局空头未实现亏损 - 全局空头未实现盈利 - 已预留金额 - 预设扣减(aumDeduction)

该机制保证了 GLP 持有者按比例获得金库的实际资产份额。

杠杆开启后的问题

enableLeverage 开启后,用户可以开设杠杆仓位(多头或空头)。攻击者在赎回 GLP 前,开设了大额的 WBTC 空头头寸。

由于空头一开仓便增加了全局空头规模,价格尚未变动的情况下系统默认该空头是亏损的,而这部分未实现亏损会被计为金库的“资产”,导致 AUM 人为上升。尽管金库并未实际获得额外价值,但赎回计算会基于这个虚高的 AUM,从而使攻击者获得了远超其应得的资产。

攻击流程

攻击交易

https://app.blocksec.com/explorer/tx/arbitrum/0x03182d3f0956a91c4e4c8f225bbc7975f9434fab042228c7acdc5ec9a32626ef?line=93

 

图片
图片

写在结尾

此次攻击暴露了 GMX 在杠杆机制与可重入保护设计上的严重缺陷。核心问题在于资产赎回逻辑对 AUM 的信任过高,未对其组成部分(如未实现亏损)进行足够审慎的安全校验。同时,关键函数对调用者身份的假设(EOA vs 合约)也缺乏强制性验证。该事件再次提醒开发者,在涉及资金敏感操作时,必须确保系统状态不可被操纵,尤其是在引入复杂金融逻辑(如杠杆、衍生品)时,更需严防重入与状态污染带来的系统性风险。

 

Related Reads

Warsh's Debut: Will the FED Chair Who Knows Crypto Best Bring Surprises or Shocks to the Market?

Kevin Warsh, the new Federal Reserve Chairman, prepares for his inaugural press conference amidst a challenging macroeconomic landscape: resurgent inflation, a bond market sell-off, and political pressure from President Trump for rate cuts. Uniquely, Warsh holds indirect investments in over 20 crypto and Web3 entities (e.g., Solana, dYdX), making him the first Fed Chair with disclosed crypto exposure. His stance may combine a hawkish, inflation-focused monetary policy with a crypto-friendly regulatory philosophy that shifts from Powell’s “same risk, same rule” approach toward a framework acknowledging blockchain’s productivity value. Warsh’s leadership could impact crypto markets across three dimensions: a paradigm shift in regulation (potentially accelerating pro-innovation legislation and stable币 rules), a re-pricing of risk premiums based on clearer communication and his view of AI as a structural disinflationary force, and a long-term reallocation of global institutional capital driven by increased legitimacy. Two potential scenarios for the press conference are outlined. A “positive surprise” would involve a dovish-leaning tone on rates coupled with signals of regulatory openness, potentially boosting crypto asset valuations. Conversely, a “negative shock” would see a more hawkish-than-expected stance on inflation and rates, triggering a broad risk-asset selloff that crypto markets would not escape. While ethics rules required Warsh to divest his crypto holdings upon confirmation, his deep understanding of the technology may fundamentally lower policy uncertainty and build a more receptive long-term foundation for digital assets’ integration into the mainstream financial system.

marsbit5h ago

Warsh's Debut: Will the FED Chair Who Knows Crypto Best Bring Surprises or Shocks to the Market?

marsbit5h ago

Trading

Spot
Futures

Hot Articles

How to Buy GMX

Welcome to HTX.com! We've made purchasing GMX (GMX) simple and convenient. Follow our step-by-step guide to embark on your crypto journey.Step 1: Create Your HTX AccountUse your email or phone number to sign up for a free account on HTX. Experience a hassle-free registration journey and unlock all features.Get My AccountStep 2: Go to Buy Crypto and Choose Your Payment MethodCredit/Debit Card: Use your Visa or Mastercard to buy GMX (GMX) instantly.Balance: Use funds from your HTX account balance to trade seamlessly.Third Parties: We've added popular payment methods such as Google Pay and Apple Pay to enhance convenience.P2P: Trade directly with other users on HTX.Over-the-Counter (OTC): We offer tailor-made services and competitive exchange rates for traders.Step 3: Store Your GMX (GMX)After purchasing your GMX (GMX), store it in your HTX account. Alternatively, you can send it elsewhere via blockchain transfer or use it to trade other cryptocurrencies.Step 4: Trade GMX (GMX)Easily trade GMX (GMX) on HTX's spot market. Simply access your account, select your trading pair, execute your trades, and monitor in real-time. We offer a user-friendly experience for both beginners and seasoned traders.

2.4k Total ViewsPublished 2024.03.29Updated 2026.06.02

How to Buy GMX

Discussions

Welcome to the HTX Community. Here, you can stay informed about the latest platform developments and gain access to professional market insights. Users' opinions on the price of GMX (GMX) are presented below.

活动图片