Back to Blog

少存多得:yCREDIT 攻击详情

Code Auditing
January 3, 2021

2021年1月2日(北京时间上午07:25),我们的监控系统ThunderForecast报告了一系列针对yCREDIT智能合约的可疑交易。随后,我们使用我们研究团队开发的EthScope系统分析了这些交易,并确认所有报告的交易均为恶意交易。在本篇博文中,我们将详细说明攻击细节。

细节

此次攻击源于铸造的代币数量与预期数量不符。因此,攻击者可以以较低的价格获得更多的yCREDIT代币,然后将这些代币出售以获利。

易受攻击的函数位于StableYieldCredit 合约_deposit 函数中。

接下来,我们将使用一个攻击交易来演示整个过程。

攻击者首先向WBTC-yCREDIT 对池转入了1e-8 WBTC331.335 yCredit代币。然后,攻击者向StableYieldCredit合约存入了0.5 WBTC以发动攻击。

具体来说,_value 是基于价格预言机提供商ChainLink(第480行,_value1466786010075)根据token(0x2260fac5e5542a773aa44fbcfedf7c193bc2c599 - WBTC)的amount(0.5)计算得出的。其目的是计算存入的WBTC以美元计的价值。然后,合约将(_value - fee)数量的yCREDIT代币转给存入WBTC的人(即攻击者)。这是因为yCREDIT的价值等于一美元(正如系统所设计的)。一切正常,除了攻击者会损失少量的fee

此外,合约会将存入的WBTC添加到WBTC-yCREDIT 对池中。这是因为如果存入的WBTC被锁定在合约中,它将失去流动性。因此,它首先计算将放入池中的代币对(WBTC到yCREDIT)的价值。这个价值是使用_addLiquidity函数计算的。基本上,它是根据池中现有的储备计算的。由于池中只有1e-8 WBTC331.335 yCREDIT代币,计算出的amountA44amountB1466786010075)。这意味着攻击者仅花费了44e-8 WBTC(第485行),并获得了14667.86010075 - fee = 14594.52080025个yCREDIT代币(第493行)。同时,池中剩余少量的WBTC(1e-8 + 44e-8)和(331.335 + 14667.86010075)yCREDIT代币。

为了获利,攻击者只需在交易所交易获得的14594.52080025个yCREDIT代币即可。有趣的是,在此交易中获取利润的过程比必要情况复杂得多。我们也观察到了其他交易中一种巧妙的攻击策略。

此次攻击涉及一系列交易,包括(但不限于)以下交易。

更新

2020/01/03:有一个新智能合约修复了该漏洞。

时间线

  • 2021/01/01 23:25 UTC,攻击被我们的系统捕获
  • 2021/01/02 16:20 UTC,本篇博文发布
Sign up for the latest updates
Tether Freezes $6.76M USDT Linked to Iran's IRGC & Houthi Forces: Why On-Chain Compliance is Now a Geopolitical Battlefield
Security Insights

Tether Freezes $6.76M USDT Linked to Iran's IRGC & Houthi Forces: Why On-Chain Compliance is Now a Geopolitical Battlefield

Looking ahead, targeted freezing events like this $6.76M USDT action will only become more common. On-chain data analysis is improving. Stablecoin issuers are also working closely with regulators. As a result, hidden illicit financial networks will be exposed.

Weekly Web3 Security Incident Roundup | Mar 2 – Mar 8, 2026
Security Insights

Weekly Web3 Security Incident Roundup | Mar 2 – Mar 8, 2026

During the week of March 2 to March 8, 2026, seven blockchain security incidents were reported with total losses of ~$3.25M. The incidents occurred across Base, BNB Chain, and Ethereum, exposing critical vulnerabilities in smart contract business logic, token deflationary mechanics, and asset price manipulation. The primary causes included a double-minting logic flaw during full token deposits that allowed an attacker to exponentially inflate their balances through repeated burn-and-mint cycles, a price manipulation vulnerability in an AMM-based lending market where artificially inflated vault shares created divergent price anchors to incorrectly force healthy positions into liquidation, and a flawed access control implementation relying on trivially spoofed contract interfaces that enabled attackers to bypass authorization to batch-mint and dump arbitrary tokens.

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

Weekly Web3 Security Incident Roundup | Feb 23 – Mar 1, 2026

During the week of February 23 to March 1, 2026, seven blockchain security incidents were reported with total losses of ~$13M. The incidents affected multiple protocols, exposing critical weaknesses in oracle design/configuration, cryptographic verification, and core business logic. The primary drivers included oracle manipulation/misconfiguration that led to the largest loss at YieldBloxDAO (~$10M), a crypto-proof verification flaw that enabled the FOOMCASH (~$2.26M) exploit, and additional token design and logic errors impacting Ploutos, LAXO, STO, HedgePay, and an unknown contract, underscoring the need for rigorous audits and continuous monitoring across all protocol layers.