市场风险之外:SushiSwap 的 KashiPairMediumRiskV1 合约中发现了一个逻辑漏洞

市场风险之外:SushiSwap 的 KashiPairMediumRiskV1 合约中发现了一个逻辑漏洞

2022年11月8日,我们发现一些攻击成功地从基于Sushi官方KashiPairMediumRiskV1合约(或其分支合约)构建的资金池中耗尽了资产。经过调查,我们发现根本原因是由于一个逻辑漏洞导致了代币价格的错误计算。

我们立即联系了Sushi的安全团队,他们证实了我们的发现。令人欣慰的是,他们正在采取措施保护一些有价值但易受攻击的资金池免受攻击。此外,他们还提供了补偿被利用而损失资金的用户的程序。因此,我们现在认为披露该漏洞和攻击的细节是安全的。在本报告中,我们将提供详细的分析。

漏洞分析

通过分析KashiPairMediumRiskV1合约的源代码,我们得出结论,该bug存在于borrow函数中,该函数在solvent修饰符中使用过时的exchangeRate来验证借款份额。具体来说,验证将基于_isSolvent函数中exchangeRate的当前值进行。

而在liquidate函数中,updateExchangeRate函数在最开始就被调用。因此,验证和计算将基于更新后的值进行。

显然,这个bug可能被利用来导致(巨大的)价格差异。

攻击分析

我们观察到两次攻击:

  1. 0xcf8f242ea83100b6d43e659f7f53a698d304fc6ac2ca6fe79e3e07ee05fefe58:受害者使用了KashiPairMediumRiskV1合约,损失约9,466 USDC。
  2. 0x3d163bfbec5686d428a6d43e45e2626a220cc4fcfac7620c620b82c1f2537c78:受害者是一个使用了CauldronMediumRiskV1(KashiPairMediumRiskV1的分支)的策略合约,损失约110,911 MIM。

请注意,第一次攻击交易是由一个机器人发起的,该机器人抢先了原始攻击交易:0x7a845d8d2af7919f5b9e22dd5571305cb5347d17986a8402715c1463d515fc18,而原始攻击者地址是0xb7ea0f0f8c6df7a61bf024db21bbe85ac5688005

这里我们以第一次攻击交易为例,该交易包括以下步骤:

  1. Balancer借入40,900 BADGER和121,904 USDC的闪电贷。
  2. BentoBox存入40,900 BADGER和113,599 USDC。
  3. 调用kmBADGER/USDC-LINK的addCollateral函数,存入40,900,000,000,000,000,000,000份BADGER份额。
  4. 调用kmBADGER/USDC-LINK的addAsset函数,存入112,529,000,000份USDC份额。
  5. 调用borrow函数,借入120,755,095,093份USDC份额。
  6. 调用UpdateExchangeRate函数。
  7. 调用liquidate函数进行自我清算。
  8. BentoBox提取40,899 BADGER和123,006 USDC。
  9. 偿还闪电贷,获得约9466 USDC的利润。

请注意,第6步不是必需的,因为borrow函数会调用UpdateExchangeRate函数。

关键步骤如下:

不难看出,borrow函数中使用的exchangeRate值与liquidate函数中使用的值存在偏差:

  • borrow函数中:250,997,938,545,109,237,740,214,705,193
  • liquidate函数中:328,266,883,541,864,569,505,752,156,794

影响

有几十个资金池(在以太坊和BSC上)可能受到此bug的影响。一种临时缓解此问题的方法是通过偶尔(或定期)调用UpdateExchangeRate函数来减少或消除偏差。这种方法已经被许多受影响的项目采用,并且可以在链上观察到相应的交易。

经验教训

让一个DeFi项目安全并非易事。除了代码审计,我们认为社区应该采取积极主动的方法来监控项目状态,并在攻击发生之前就阻止攻击

关于BlockSec

BlockSec是一家开创性的区块链安全公司,由一群杰出的全球安全专家于2021年创立。公司致力于提升新兴Web3世界的安全性和可用性,以促进其大规模采用。为此,BlockSec提供智能合约和EVM链安全审计服务,Phalcon平台用于安全开发和主动阻止威胁,MetaSleuth平台用于资金追踪和调查,以及MetaDock扩展,帮助Web3开发者在加密世界中高效冲浪。

迄今为止,公司已服务超过300家尊贵客户,如MetaMask、Uniswap Foundation、Compound、Forta和PancakeSwap,并在两轮融资中从Matrix Partners、Vitalbridge Capital和Fenbushi Capital等知名投资者那里获得了数千万美元的资金。

官方网站:https://blocksec.com/

官方Twitter账号:https://twitter.com/BlockSecTeam

Sign up for the latest updates
Weekly Web3 Security Incident Roundup | Feb 9 – Feb 15, 2026

Weekly Web3 Security Incident Roundup | Feb 9 – Feb 15, 2026

During the week of February 9 to February 15, 2026, three blockchain security incidents were reported with total losses of ~$657K. All incidents occurred on the BNB Smart Chain and involved flawed business logic in DeFi token contracts. The primary causes included an unchecked balance withdrawal from an intermediary contract that allowed donation-based inflation of a liquidity addition targeted by a sandwich attack, a post-swap deflationary clawback that returned sold tokens to the caller while draining pool reserves to create a repeatable price-manipulation primitive, and a token transfer override that burned tokens directly from a Uniswap V2 pair's balance and force-synced reserves within the same transaction to artificially inflate the token price.

Top 10 "Awesome" Security Incidents in 2025

Top 10 "Awesome" Security Incidents in 2025

To help the community learn from what happened, BlockSec selected ten incidents that stood out most this year. These cases were chosen not only for the scale of loss, but also for the distinct techniques involved, the unexpected twists in execution, and the new or underexplored attack surfaces they revealed.

#10 Panoptic Incident: XOR Linearity Breaks the Position Fingerprint Scheme

#10 Panoptic Incident: XOR Linearity Breaks the Position Fingerprint Scheme

On August 29, 2025, Panoptic disclosed a Cantina bounty finding and confirmed that, with support from Cantina and Seal911, it executed a rescue operation on August 25 to secure roughly $400K in funds. The issue stemmed from a flaw in Panoptic’s position fingerprint calculation algorithm, which could have enabled incorrect position identification and downstream fund risk.