Back to Blog

#7: ParaSpace事件:争分夺秒阻止行业最关键的攻击

February 17, 2024
6 min read

背景

2023年3月17日,NFT借贷平台Paraspace(现已更名为Parallel Finance)因其价格预言机中的一个漏洞遭受了重大攻击。Paraspace允许用户质押NFT和ERC-20代币作为抵押品来借入ERC-20代币,从而在不出售NFT的情况下获得收益。

点击此处阅读推文
点击此处阅读推文

ParaSpace的一个关键功能是ApeStaking,它可以自动复投APE奖励。质押APE的用户会收到cAPE代币,这是APE的cToken表示,可以作为抵押品借入USDC和WETH等资产。存入cAPE代币会获得pcAPE份额,其抵押品价值通过将pcAPE数量乘以其rebasinIndex计算得出。

rebasinIndex从总汇聚的APE余额和总份额中得出,如下面的代码片段所示:

function _scaledBalanceOf(address user, uint256 rebasingIndex)
    internal
    view
    returns (uint256)
{
    return super.scaledBalanceOf(user).rayMul(rebasingIndex);
}

function lastRebasingIndex() internal view override returns (uint256) {
  return ICApe(_underlyingAsset).getPooledApeByShares(WadRayMath.RAY);
}

function getPooledApeByShares(uint256 sharesAmount)
    public
    view
    returns (uint256)
{
    uint256 totalShares = _getTotalShares();
    if (totalShares == 0) {
        return 0;
    } else {
        return
            sharesAmount.mul(_getTotalPooledApeBalance()).div(totalShares);
    }
}

function _getTotalPooledApeBalance()
    internal
    view
    override
    returns (uint256)
{
    (uint256 stakedAmount, ) = apeStaking.addressPosition(address(this));
    uint256 rewardAmount = apeStaking.pendingRewards(
        APE_COIN_POOL_ID,
        address(this),
        0
    );
    return stakedAmount + rewardAmount + bufferBalance;
}

_getTotalPooledApeBalance()函数将APE代币的质押量、待处理奖励以及ApeCoinStaking合约中的缓冲余额相加。

漏洞分析

该漏洞在于操纵rebasingIndex,从而人为地夸大了cAPE代币的抵押品价值。具体来说,ApeCoinStaking合约中的depositApeCoin()函数会增加某个头寸的stakedAmount。攻击者可以通过将APE代币存入cAPE头寸来利用这一点,从而夸大_getTotalPooledApeBalance()的输出,进而夸大rebasingIndex

function depositApeCoin(uint256 _amount, address _recipient) public {
    if (_amount < MIN_DEPOSIT) revert DepositMoreThanOneAPE();
    updatePool(APECOIN_POOL_ID);

    Position storage position = addressPosition[_recipient];
    _deposit(APECOIN_POOL_ID, position, _amount);

    apeCoin.transferFrom(msg.sender, address(this), _amount);

    emit Deposit(msg.sender, _amount, _recipient);
}

function _deposit(uint256 _poolId, Position storage _position, uint256 _amount) private {
  Pool storage pool = pools[_poolId];
  _position.stakedAmount += _amount;
  pool.stakedAmount += _amount.toUint96();
  _position.rewardsDebt += (_amount * pool.accumulatedRewardsPerShare).toInt256();
}

这种设计缺陷允许攻击者通过将cAPE作为接收者,调用depositApeCoin()存入APE代币,从而夸大抵押品价值。

攻击分析

攻击者通过五步闪电贷攻击利用了这一漏洞:

  1. 通过多个合约进行了一笔约47,352 wstETH的闪电贷,并提供了约46,018 wstETH以借入cAPE。
  2. 存入了约12,880,000 cAPE代币作为抵押品。
  3. 使用约1,205 wstETH交易了约492,124 APE代币,并将1,839,999 cAPE提取为APE代币。
  4. 通过调用ApeCoinStaking.depositApeCoin()向cAPE头寸存入了2,332,214 APE代币,将协议的stakedAmount从851,662增加到3,183,876(增加了373%)。
  5. 利用夸大的抵押品借入了大量的USDC和WETH等资产以获取利润。

通过闪电贷操纵pcAPE价格,利用了预言机计算中使用的现货价格。

开始使用Phalcon Security

检测所有威胁,预警重要事项,并阻止攻击。

立即免费试用

总结

ParaSpace事件凸显了DeFi协议中预言机操纵和闪电贷攻击的风险。它强调了对健壮、抗操纵的价格预言机以及超越发布前审计的持续安全监控的迫切需求。

BlockSec的Phalcon Security系统通过自动阻止攻击并保护用户资产,展示了主动威胁检测和预防的价值。该事件提醒DeFi协议必须实施全面的安全措施,包括智能合约审计、基础设施审计和实时监控。

如需了解更多DeFi安全事件和最佳实践,请浏览我们的安全事件库,并考虑我们的智能合约审计基础设施审计服务。

探索MetaSleuth调查

追踪资金流并为调查构建证据

立即免费试用

阅读本系列的更多文章:

Web3最佳安全审计师

在上线前验证设计、代码和业务逻辑

Sign up for the latest updates
Newsletter - April 2026
Security Insights

Newsletter - April 2026

In April 2026, the DeFi ecosystem experienced three major security incidents. KelpDAO lost ~$290M due to an insecure 1-of-1 DVN bridge configuration exploited via RPC infrastructure compromise, Drift Protocol suffered ~$285M from a multisig governance takeover leveraging Solana's durable nonce mechanism, and Rhea Finance incurred ~$18.4M following a business logic flaw in its margin-trading module that allowed circular swap path manipulatio

~$7.04M Lost: GiddyDefi, Volo Vault & More | BlockSec Weekly
Security Insights

~$7.04M Lost: GiddyDefi, Volo Vault & More | BlockSec Weekly

This BlockSec weekly security report covers eight attack incidents detected between April 20 and April 26, 2026, across Ethereum, Avalanche, Sui, Base, HyperLiquid, and MegaETH, with total estimated losses of approximately $7.04M. The highlighted incident is the $1.3M GiddyDefi exploit, where the attacker did not break any cryptography or use a flash loan but simply replayed an existing on-chain EIP-712 signature with the unsigned `aggregator` and `fromToken` fields swapped out for a malicious contract, demonstrating how partial signature coverage turns any historical signature into a generic permit. Other incidents include a $3.5M Volo Vault operator key compromise on Sui, a $1.5M Purrlend privileged-role takeover, a $413K SingularityFinance oracle misconfiguration, a $142.7K Scallop cross-pool index injection, a $72.35K Kipseli Router decimal mismatch, a $50.7K REVLoans (Juicebox) accounting pollution, and a $64K Custom Rebalancer arbitrary-call exploit.

Weekly Web3 Security Incident Roundup | Apr 13 – Apr 19, 2026
Security Insights

Weekly Web3 Security Incident Roundup | Apr 13 – Apr 19, 2026

This BlockSec weekly security report covers four attack incidents detected between April 13 and April 19, 2026, across multiple chains such as Ethereum, Unichain, Arbitrum, and NEAR, with total estimated losses of approximately $310M. The highlighted incident is the $290M KelpDAO rsETH bridge exploit, where an attacker poisoned the RPC infrastructure of the sole LayerZero DVN to fabricate a cross-chain message, triggering a cascading WETH freeze across five chains and an Arbitrum Security Council forced state transition that raises questions about the actual trust boundaries of decentralized systems. Other incidents include a $242K MMR proof forgery on Hyperbridge, a $1.5M signed integer abuse on Dango, and an $18.4M circular swap path exploit on Rhea Finance's Burrowland protocol.