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

去中心化金融社区Publicado em 2022-11-24Última atualização em 2022-11-24

Resumo

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方面没有轻松的胜利。我们需要认识到现有标准的局限性,并为它们寻找最佳的解决方案。

Criptomoedas em alta

Leituras Relacionadas

AC Exits Sonic Board, 'DeFi Godfather' Pulls Off Another Strategic Retreat

Andre Cronje, known as the "DeFi Godfather," and two other founding directors have stepped down from the Sonic Labs board. The S token, once valued at $1.03, has plummeted 97% to $0.028, and the chain's TVL has evaporated 98% from its peak. In his exit statement, Cronje clarified he was a technical architect, not a founder, and distanced himself from token economics and migration decisions behind the token's crash. Cronje revealed his focus for the past 18 months has been his new project, Flying Tulip. This project raised $200 million privately last year at a $10 billion valuation. Its token design includes a perpetual put option (ftPUT NFT) for early investors, allowing them to redeem their initial investment at any time—a protection not extended to public market buyers. This pattern mirrors Cronje's past exits from projects like Yearn Finance and Fantom, where he departed near peak hype, leaving later holders to bear significant losses. Sonic itself has seen a complete management overhaul in recent months. The article frames this as a microcosm of the broader crypto bear market, where Layer-1 chains are bleeding value. It highlights a harsh reality: a project's valuation is often tied to a founder's reputation rather than fundamentals. Ironically, Flying Tulip is set to launch first on the Sonic chain Cronje just left, underscoring a disconnect between the person and the platform.

marsbitHá 18m

AC Exits Sonic Board, 'DeFi Godfather' Pulls Off Another Strategic Retreat

marsbitHá 18m

Dialogue with KK, Founder of Hash Global: Do VCs Still Invest in Blockchain Games Now? What Kind of Projects Can Still Get Funding?

**Title: Dialogue with KK, Founder of Hash Global: Do VCs Still Invest in Blockchain Games? What Kind of Projects Can Still Get Funding?** **Summary:** KK, partner at Hash Global, discussed the evolving landscape of Web3 investment and blockchain games in a recent interview. He noted that the industry has moved past its initial hype phase into a more sober "second half," where VCs now prioritize core questions: Is the game actually fun? Does it have real users? Can it generate revenue? Key insights include: * **Web3 Investment Evolution:** The sector is increasingly adopting traditional investment logic, focusing on business models, value capture, and tangible worth over pure narrative. * **Blockchain Game Fundamentals:** The paramount criterion for any game is being genuinely fun and engaging. Web3 elements (like asset issuance and value distribution) should enhance an already solid product, not be a substitute for poor gameplay. Play-to-Earn is seen as a potential final stage, not a starting point. * **Current Investment Thesis:** Hash Global remains active in gaming, favoring projects with low barriers to entry, strong social/competitive elements, and the ability to generate real revenue (e.g., through ads, skins) like traditional Web2 games before scaling. Essential criteria are: 1) A fun core loop understandable without Web3 knowledge, 2) Web3 mechanisms that genuinely improve asset distribution and community participation, and 3) A capable, long-term-focused team with proven product-building experience. * **Team Focus:** The firm concentrates on investing in Chinese teams, leveraging cultural familiarity and judgment. * **Web3 Application Outlook:** Large-scale adoption may be accelerated by AI in areas with significant pain points in distribution (e.g., creator economy) or in "Non-Financial RWA" sectors like entertainment/culture. * **BNB Ecosystem:** Hash Global is bullish on BNB, viewing its ecosystem as significantly undervalued, with real users and global capital access. * **Investor Advice:** In the current bear market, KK expresses respect for new institutional investors entering Web3, as it indicates deep research rather than hype-chasing. A key lesson is managing pace—maintaining optimism tempered with realism to ensure longevity.

marsbitHá 50m

Dialogue with KK, Founder of Hash Global: Do VCs Still Invest in Blockchain Games Now? What Kind of Projects Can Still Get Funding?

marsbitHá 50m

A New Player Enters at Third Place, Rothera Disrupts the Prediction Market Landscape

"Rothera Skyrockets to Third in Prediction Market Rankings, Disrupting Industry Landscape" Rothera, Robinhood's newly launched prediction market platform, has rapidly climbed to become the third-largest player in the sector by trading volume, trailing only giants Kalshi and Polymarket. Its growth is attributed not to attracting new users, but to migrating existing Robinhood user orders away from partner Kalshi. Previously, Robinhood served as a major distribution channel for Kalshi, accounting for an estimated 25%-35% of its volume. With the launch of Rothera, Robinhood now internally executes events like World Cup contracts, capturing revenue that was previously shared with Kalshi. Data shows Rothera's weekly trading volume surged from $21.9 million to $559 million within weeks, reaching nearly one-fifth of Polymarket's volume. Analysts estimate Robinhood's prediction market business could generate around $10 billion in annual revenue at this pace, potentially surpassing its historical crypto revenue peak. In response, Kalshi is reportedly exploring new distribution channels by engaging with investment banks for a potential IPO, requiring them to integrate their systems with Kalshi to access institutional clients. This shift highlights a new competitive focus in prediction markets: controlling user access and distribution channels rather than just product offerings.

marsbitHá 59m

A New Player Enters at Third Place, Rothera Disrupts the Prediction Market Landscape

marsbitHá 59m

Trading

Spot
Futuros

Artigos em Destaque

Como comprar CRV

Bem-vindo à HTX.com!Tornámos a compra de Curve DAO Token (CRV) simples e conveniente.Segue o nosso guia passo a passo para iniciar a tua jornada no mundo das criptos.Passo 1: cria a tua conta HTXUtiliza o teu e-mail ou número de telefone para te inscreveres numa conta gratuita na HTX.Desfruta de um processo de inscrição sem complicações e desbloqueia todas as funcionalidades.Obter a minha contaPasso 2: vai para Comprar Cripto e escolhe o teu método de pagamentoCartão de crédito/débito: usa o teu visa ou mastercard para comprar Curve DAO Token (CRV) instantaneamente.Saldo: usa os fundos da tua conta HTX para transacionar sem problemas.Terceiros: adicionamos métodos de pagamento populares, como Google Pay e Apple Pay, para aumentar a conveniência.P2P: transaciona diretamente com outros utilizadores na HTX.Mercado de balcão (OTC): oferecemos serviços personalizados e taxas de câmbio competitivas para os traders.Passo 3: armazena teu Curve DAO Token (CRV)Depois de comprar o teu Curve DAO Token (CRV), armazena-o na tua conta HTX.Alternativamente, podes enviá-lo para outro lugar através de transferência blockchain ou usá-lo para transacionar outras criptomoedas.Passo 4: transaciona Curve DAO Token (CRV)Transaciona facilmente Curve DAO Token (CRV) no mercado à vista da HTX.Acede simplesmente à tua conta, seleciona o teu par de trading, executa as tuas transações e monitoriza em tempo real.Oferecemos uma experiência de fácil utilização tanto para principiantes como para traders experientes.

467 Visualizações TotaisPublicado em {updateTime}Atualizado em 2026.06.02

Como comprar CRV

Discussões

Bem-vindo à Comunidade HTX. Aqui, pode manter-se informado sobre os mais recentes desenvolvimentos da plataforma e obter acesso a análises profissionais de mercado. As opiniões dos utilizadores sobre o preço de CRV (CRV) são apresentadas abaixo.

活动图片