DeFi:解决 EIP-4626 中的滑点问题

去中心化金融社区2022-11-24 tarihinde yayınlandı2022-11-24 tarihinde güncellendi

Özet

EIP-4626提供了一种将代币投资到投资池(通常称为金库)的标准方法。

简介

EIP-4626提供了一种将代币投资到投资池(通常称为金库)的标准方法。当我们存入自己的资产(ERC-20 代币)时,我们会收到一个份额代币,代表我们在金库里的资产。金库将把汇集的资产投资到一个或多个基础平台,为持有者产生收益。

EIP-4626标准的一个结果是,存款和铸币函数没有提供指定回报的最小份额或资产金额的方法。这通常用于防止高滑点或三明治攻击。mStable 如何通过其 Meta Vaults 解决这个问题——在保持符合标准的同时减轻高滑点攻击?本文描述了这些挑战,并解释了他们的方法是如何工作的。

EIP-4626和mStable金库存款

mStable EIP-4626的首个金库将投资于基于Curve 3Pool的Convex池。从EIP-4626的角度来看,金库的资产是Curve 3Pool的流动性提供者代币(3Crv)。存款函数是EIP-4626规范的一部分,它指定要存入多少资产以及将接收金库份额的帐户。存款函数返回给接收方会铸造多少金库份额。

例如,存入3Crv Convex mUSD金库将从调用方转移3Crv,并将vcx3CRV-mUSD金库份额转移到接收方。

EIP-4626标准的强大之处在于,在投资池中有一种通用的投资方法,但对资产可以投资到底层平台的内容和时间没有限制。对于mStable的3Crv Convx mUSD 金库来说, 3Crv被添加到Curve mUSD Metapool中,然后产生的流动性提供者代币(musd3Crv)被存入Convex mUSD池中,该池会投资于Curve mUSD gauge并获得更高的回报。

这个过程中的一个技术挑战是如何防止三明治攻击。

什么是三明治攻击?如何预防它们?

当我们向Curve Metapool(或任何其他池)添加流动性时,我们指定自己想存入的资产数量和流动性提供者(LP)代币的最小数量。对于mUSD Metapool,金额是一个包含两项的数组。第一个是mUSD的量,第二个是3Crv的量。3Crv Convex金库只存3Crv,因此金额数组的第一项将为零。

开发金库时的一个技术挑战是我们如何设置预期流动性提供者代币的最小数量。

仅仅将min_mint_amount设置为零是不够的,因为它会让存款交易受到三明治攻击。但在我们深入了解三明治攻击是如何工作之前,我们需要更多地了解Curve Metapool定价是如何工作的。由于金库只添加两个池代币(mUSD和3Crv)中的一个,因此它接收到的Metapool流动性提供者(LP)代币的数量将取决于Metapool中mUSD和3Crv的余额。池中的 3Crv 越多,当仅将 3Crv 添加到 Metapool 时,返回的 LP 代币就越少。

例如,如果Curve的mUSD Metapool添加了 200 万个 mUSD,600 万个 3Crv 和 100k 个 3Crv,则将收到 100,068 个 LP 代币 (musd3Crv)。如果 Metapool 有 600 万个 mUSD,添加了 200 万个 3Crv 和 100k 个 3Crv,将收到 100,892 个 LP 代币 (musd3Crv)。

那么三明治攻击是如何实现的呢?

攻击者在将交易包含到区块之前,就会监控Mempool中可能被利用的交易。为了利用交易,他们贿赂区块生产者,将他们的交易包含在可利用的交易之前和之后。也就是说,他们将易受攻击的交易与自己的交易夹在一起。如果有一笔交易将 3Crv 添加到最低 LP 金额为零的 mUSD Metapool,则攻击者的第一笔交易将是减少 Metapool 中的 mUSD 数量。这意味着在易受攻击的添加流动性交易中收到的 Metapool LP 代币数量远低于应有的数量。在第三个交易中,攻击者返还在第一个交易中删除的mUSD,并将收益装入囊中。

例子

使用Curve的mUSD Metapool,池中有6,000,000 mUSD和3Crv, 11,917,295个LP代币(musd3Crv)和1.018095美元的虚拟价格。

攻击者通过使用 6,500,000 (54.5%) 池流动性提供者 (musd3Crv) 代币从池中提取 5,973,425 的mUSD,使用他们池中的大部分流动性提供者代币 (musd3Crv) 来平衡池。使用remove_liquidity_one_coin函数进行单边提款,池中剩下 0.43% mUSD 和 99.56% 3Crv。虚拟价格上涨了近1%,至1.019105,因为大量不平衡的提现为池收取了费用。

受害者使用add_liquidity函数将100,000个3Crv添加到不平衡的池中,且没有最小流动性提供者数量。如果池是平衡的,受害者得到81978个LP代币而不是100371个。这意味着受害者得到的LP代币比他们应该得到的少18,393个(18%)。以美元计算,受害者得到的美元价值减少了18,643(18%)。

对于第三个也是最后一个交易,攻击者使用add_liquidity将他们从第一个交易中提取的5,973,425个mUSD添加回池中,以接收6,503,610个LP代币(musd3Crv)。比第一次交易多取了3610美元。池的虚拟价格将增加1%至1.019216,因为这是另一个不平衡的交易。以美元计算,攻击者的LP价值从6,500,000 * 1.018095 = 6,617,617美元上升到6,503,610 * 1.019216 = 6,628,583美元,增加了10,966美元(1.65%)。

如果受害者损失了18643美元价值,而攻击者只获得了10966美元价值,那么缺失的7677美元价值在哪里?

使池失衡的0.04%费用由流动性提供者和Curve投票托管的CRV (veCRV)持有者平均分摊。攻击者未持有的 5,417,295 LP 代币的价值从 5,515,323 美元增加到 5,520,794 美元。这比池费用的 50% 增加了 5,471 美元。增加的美元价值归于托管 CRV (veCRV) 持有人。

Curve的保护

为了防止三明治攻击,在向Curve Metapool添加流动性时,需要指定一个合理的最小LP代币数量。通常,DeFi 协议会在交易中传入相当数量的金额。Curve池中的add_liquidity函数就是min_mint_amount的一个很好的例子。但是对于标准的EIP-4626存款函数,没有定义参数来指定最小金额,因此我们无法传入相当数量的链下计算的Metapool LP代币。

Curve池有一个calc_token_amount函数,它可以计算池代币存款收到的 LP 代币数量。但这不能用来防止三明治攻击。如果已经运行了一个交易来平衡池,那么calc_token_amount函数将只返回当前不公平的LP代币数量。

因此问题仍然存在,EIP-4626函数没有办法传递最小量。打破标准来添加这一点是不可取的,使用预言机也是次优的。我们需要链上方法。

mStable的方法

mStable的金库获得一个公平的Metapool LP代币价格的方法是使用Curve Metapool和Curve 3Pool的虚拟价格。get_virtual_price函数以美元为单位返回池的流动性提供者代币的价格。它通过计算池的不变式来实现这一点,该不变式是池中代币的美元价值除以代币的总供应量。由于池中代币的余额不影响池的不变值或总美元价值,虚拟价格不会受到三明治攻击。

对于存入mStable金库的存款,我们需要在Curve的3Pool LP代币(3Crv)中对Metapool LP代币进行定价,因为这是我们在金库中使用的资产。为此,我们得到3Pool虚拟价格,并将其除以Metapool LP代币价格。

一旦我们有了一个合理的价格,我们就可以通过目前配置为 1% 的滑点系数来降低它。这个调整后的公平价格用于计算在向池中添加3Crv流动性时可以接收的Curve Metapool LP代币(musd3Crv)的最小数量。

存款的全部流程如下:

结论

虽然标准在标准化和获得采用方面起着巨大的作用,但像这样的问题提醒我们,在DeFi方面没有轻松的胜利。我们需要认识到现有标准的局限性,并为它们寻找最佳的解决方案。

Trend Kriptolar

İlgili Okumalar

Idle Macs Can Also Make Money? An Overview of Eigen Labs' Decentralized AI Inference Network Darkbloom

AI inference is becoming a crucial layer of internet infrastructure, yet it remains largely dependent on costly, capacity-limited centralized systems with potential security risks. Meanwhile, millions of powerful computers sit idle globally. Eigen Labs' Darkbloom network aims to utilize this idle capacity by enabling distributed AI inference on Mac computers, specifically those with Apple Silicon chips. Darkbloom's architecture consists of three components: users who send inference requests, a coordinator (operated by Eigen Labs) that routes these requests, and providers (Mac owners) whose machines run the models and return outputs without being able to see the request content. The system prioritizes privacy through a hardened provider process, software integrity checks, and hardware-supported attestation based on Apple's security architecture to ensure verifiable privacy. Economically, Darkbloom differs from traditional models. It leverages existing hardware, with marginal costs primarily driven by electricity, allowing it to offer pricing roughly 50% lower than major API aggregators. Providers keep 100% of the inference revenue, and the project does not rely on token subsidies; earnings come solely from real AI inference demand. However, early-stage earnings are modest, with top providers currently earning under $6 per day, influenced by factors like hardware specs, uptime, and network demand. The network currently supports models like Google's Gemma 4 and OpenAI's GPT-OSS via OpenRouter. To participate as a provider, users need an Apple Silicon Mac running macOS 14 or later, must install the Darkbloom provider software, and keep the machine online with a stable internet connection.

marsbit9 dk önce

Idle Macs Can Also Make Money? An Overview of Eigen Labs' Decentralized AI Inference Network Darkbloom

marsbit9 dk önce

Which Crypto Sectors Have Been "Eaten" by AI Agents?

The article examines which crypto sectors have been increasingly dominated by AI Agents and which remain human-centric. In certain high-speed, efficiency-driven areas, AI Agents have taken clear control. This includes derivatives/perpetuals trading, where bots outperform humans significantly (e.g., a contest showed 0% of AI Agents were liquidated vs. 43% of humans), arbitrage/MEV extraction, and yield optimization (with ~68% of new DeFi protocols in Q1 2026 featuring autonomous AI Agents). Spot trading and portfolio optimization are also seeing heavy Agent adoption. However, the shift is not universal. In "battleground" sectors, both Agents and humans coexist. In prediction markets, Agents dominate short-term arbitrage, but humans still outperform in long-term, nuanced judgment calls. In DeFi lending, while liquidation is automated, core deposit/borrow decisions remain largely human-driven. Sectors still firmly led by human activity include stablecoin payments and card-based spending (driven by real-world economic activity and remittances) and wallets, which serve as the crucial human-verification and approval layer. The rise of Agents increases the need for robust human-Agent verification layers. Projects like World/AgentKit, t54, Self Protocol, and Kite AI are building infrastructure to create trust, security, and accountability by binding Agents to verified human identities. In conclusion, while AI Agents have decisively "eaten" speed and optimization-focused crypto sectors, human judgment, trust, and real-world context remain dominant in areas that create broad economic value, such as payments and identity. The future likely involves a symbiotic relationship where Agents require human verification and oversight to operate effectively.

Foresight News15 dk önce

Which Crypto Sectors Have Been "Eaten" by AI Agents?

Foresight News15 dk önce

After Rising 11 Times in a Year, Micron's Earnings Report Becomes a Stress Test for the AI Memory Market

**Micron's Upcoming Earnings: A Crucial Test for the AI Memory Rally** Investors in AI memory stocks face a critical moment on June 24th, when Micron Technology reports quarterly earnings. The stock, having surged approximately 11-fold from $103 to $1,134 over the past year, carries immense market expectations. Wall Street consensus forecasts a staggering ~932% year-over-year jump in EPS to around $19.72 and ~270% revenue growth to ~$345 billion, largely driven by sold-out HBM (High Bandwidth Memory) capacity through 2026. Analysts have aggressively revised estimates upward over the last 90 days, with EPS expectations rising 68%. This creates a high bar: even strong results risk a sell-off if they fail to meet these elevated projections. Notably, price forecasts from institutions like Citi (predicting ~200% DRAM price increases in 2026) are already among the most bullish on Wall Street, not conservative. The key metric to watch is gross margin, guided to a record ~81%. Such peak profitability raises questions about sustainability in the historically cyclical memory sector. While management has signaled continued strength, the stock's direction post-earnings will likely hinge more on forward guidance for the next quarter and details on HBM capacity expansion for 2027, rather than the already-anticipated stellar past results. The report represents a major pressure test for the high-flying AI memory trade.

marsbit20 dk önce

After Rising 11 Times in a Year, Micron's Earnings Report Becomes a Stress Test for the AI Memory Market

marsbit20 dk önce

İşlemler

Spot
Futures

Popüler Makaleler

CRV Nasıl Satın Alınır

HTX.com’a hoş geldiniz! Curve DAO Token (CRV) satın alma işlemlerini basit ve kullanışlı bir hâle getirdik. Adım adım açıkladığımız rehberimizi takip ederek kripto yolculuğunuza başlayın. 1. Adım: HTX Hesabınızı OluşturunHTX'te ücretsiz bir hesap açmak için e-posta adresinizi veya telefon numaranızı kullanın. Sorunsuzca kaydolun ve tüm özelliklerin kilidini açın. Hesabımı Aç2. Adım: Kripto Satın Al Bölümüne Gidin ve Ödeme Yönteminizi SeçinKredi/Banka Kartı: Visa veya Mastercard'ınızı kullanarak anında Curve DAO Token (CRV) satın alın.Bakiye: Sorunsuz bir şekilde işlem yapmak için HTX hesap bakiyenizdeki fonları kullanın.Üçüncü Taraflar: Kullanımı kolaylaştırmak için Google Pay ve Apple Pay gibi popüler ödeme yöntemlerini ekledik.P2P: HTX'teki diğer kullanıcılarla doğrudan işlem yapın.Borsa Dışı (OTC): Yatırımcılar için kişiye özel hizmetler ve rekabetçi döviz kurları sunuyoruz.3. Adım: Curve DAO Token (CRV) Varlıklarınızı SaklayınCurve DAO Token (CRV) satın aldıktan sonra HTX hesabınızda saklayın. Alternatif olarak, blok zinciri transferi yoluyla başka bir yere gönderebilir veya diğer kripto para birimlerini takas etmek için kullanabilirsiniz.4. Adım: Curve DAO Token (CRV) Varlıklarınızla İşlem YapınHTX'in spot piyasasında Curve DAO Token (CRV) ile kolayca işlemler yapın.Hesabınıza erişin, işlem çiftinizi seçin, işlemlerinizi gerçekleştirin ve gerçek zamanlı olarak izleyin. Hem yeni başlayanlar hem de deneyimli yatırımcılar için kullanıcı dostu bir deneyim sunuyoruz.

440 Toplam GörüntülenmeYayınlanma 2024.12.11Güncellenme 2026.06.02

CRV Nasıl Satın Alınır

Tartışmalar

HTX Topluluğuna hoş geldiniz. Burada, en son platform gelişmeleri hakkında bilgi sahibi olabilir ve profesyonel piyasa görüşlerine erişebilirsiniz. Kullanıcıların CRV (CRV) fiyatı hakkındaki görüşleri aşağıda sunulmaktadır.

活动图片