Back to Blog

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

Code Auditing
December 15, 2022

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
Drift Protocol Incident: Multisig Governance Compromise via Durable Nonce Exploitation
Security Insights

Drift Protocol Incident: Multisig Governance Compromise via Durable Nonce Exploitation

On April 1, 2026 (UTC), Drift Protocol on Solana suffered a $285.3M loss after an attacker exploited Solana's durable nonce mechanism to delay the execution of phished multisig approvals, ultimately transferring administrative control of the protocol's 2-of-5 Squads governance with zero timelock. With full admin privileges, the attacker created a malicious collateral market (CVT), inflated its oracle price, relaxed withdrawal protections, and drained USDC, JLP, SOL, cbBTC, and other assets through 31 rapid withdrawals in approximately 12 minutes. This incident highlights how durable nonce-based delayed execution can decouple signer intent from on-chain execution, bypassing the temporal assumptions that multisig security implicitly relies on.

Weekly Web3 Security Incident Roundup | Mar 23 – Mar 29, 2026
Security Insights

Weekly Web3 Security Incident Roundup | Mar 23 – Mar 29, 2026

This BlockSec weekly security report covers eight DeFi attack incidents detected between March 23 and March 29, 2026, across Ethereum and BNB Chain, with total estimated losses of approximately $1.53M. Incidents include a $679K flawed burn mechanism exploit on the BCE token, a $512K spot-price manipulation attack on Cyrus Finance's PancakeSwap V3 liquidity withdrawal, a $133.5K flash-loan-driven referral reward manipulation on a TUR staking contract, and multiple integer overflow, reentrancy, and accounting error vulnerabilities in DeFi protocols. The report provides detailed vulnerability analysis and attack transaction breakdowns for each incident.

Newsletter -  March 2026
Security Insights

Newsletter - March 2026

In March 2026, the DeFi ecosystem experienced three major security incidents. Resolv Protocol lost ~$80M due to compromised privileged infrastructure keys, BitcoinReserveOffering suffered ~$2.7M from a double-minting logic flaw, and Venus Protocol incurred ~$2.15M following a donation attack combined with market manipulation.

Best Security Auditor for Web3

Validate design, code, and business logic before launch. Aligned with the highest industry security standards.

BlockSec Audit