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
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