Skip to content
Smart contracts Audit finding Intermediate

The state variable `BondToken.globalPool` is updated incorrectly via `Pool.startAuction()`

The BondToken's globalPool state variable is updated incorrectly when an auction starts, using an outdated sharesPerToken value. This leads to incorrect calculations of coupon tokens that bondholders can claim.

0xmystery Follow with MysteryAuditor, Pablo and 5 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-12-plaza-finance-judging/issues/972

Found by

0xmystery, MysteryAuditor, Pablo, X0sauce, bretzel, mxteem, silver_eth, wellbyt3

Summary

When an auction starts, the globalPool state variable of BondToken is updated incorrectly. This leads to the wrong calculation of coupon tokens that bondholders can claim.

Root Cause

In the startAuction() function of Pool.sol, the state variable in bondToken is updated by calling bondToken.increaseIndexedAssetPeriod(sharesPerToken).

Solidity
  function startAuction() external whenNotPaused() {
  
    ...

    // Calculate the coupon amount to distribute
    uint256 couponAmountToDistribute = (normalizedTotalSupply * normalizedShares)
        .toBaseUnit(maxDecimals * 2 - IERC20(couponToken).safeDecimals());

    auctions[currentPeriod] = Utils.deploy(
      address(new Auction()),
      abi.encodeWithSelector(
        Auction.initialize.selector,
        address(couponToken),
        address(reserveToken),
        couponAmountToDistribute,
        block.timestamp + auctionPeriod,
        1000,
        address(this),
        poolSaleLimit
      )
    );

    // Increase the bond token period
    bondToken.increaseIndexedAssetPeriod(sharesPerToken);

    // Update last distribution time
    lastDistribution = block.timestamp;
  }

In the increaseIndexedAssetPeriod() function of BondToken.sol, it updates the globalPool state variable by pushing a new PoolAmount struct to globalPool.previousPoolAmounts, setting sharesPerToken as globalPool.sharesPerToken. Then it updates globalPool.sharesPerToken with the new sharesPerToken.

This logic is correct only if sharesPerToken has not changed. However, the setSharesPerToken() function in Pool.sol allows for changes to sharesPerToken, and globalPool.sharesPerToken can only be updated when starting an auction.

If an auction starts with a new sharesPerToken, the function uses the previous value (globalPool.sharesPerToken), which is outdated. This leads to incorrect calculations of coupon tokens that bondholders can claim.

Solidity
  function increaseIndexedAssetPeriod(uint256 sharesPerToken) public onlyRole(DISTRIBUTOR_ROLE) whenNotPaused() {
    globalPool.previousPoolAmounts.push(
      PoolAmount({
        period: globalPool.currentPeriod,
        amount: totalSupply(),
        sharesPerToken: globalPool.sharesPerToken
      })
    );
    globalPool.currentPeriod++;
    globalPool.sharesPerToken = sharesPerToken;

    emit IncreasedAssetPeriod(globalPool.currentPeriod, sharesPerToken);
  }
Solidity
  function setSharesPerToken(uint256 _sharesPerToken) external NotInAuction onlyRole(poolFactory.GOV_ROLE()) {
    sharesPerToken = _sharesPerToken;

    emit SharesPerTokenChanged(sharesPerToken);
  }

As a result, the calculation of coupon tokens that bondholders can claim will be based on incorrect values.

Solidity
  function getIndexedUserAmount(address user, uint256 balance, uint256 period) public view returns(uint256) {
    IndexedUserAssets memory userPool = userAssets[user];
    uint256 shares = userPool.indexedAmountShares;

    for (uint256 i = userPool.lastUpdatedPeriod; i < period; i++) {
      shares += (balance * globalPool.previousPoolAmounts[i].sharesPerToken).toBaseUnit(SHARES_DECIMALS);
    }

    return shares;
  }

Internal Pre-Conditions

The state variable sharesPerToken of the pool has been modified.

External Pre-Conditions

Attack Path

Impact

The calculation of coupon tokens that bondholders can claim will be incorrect, potentially leading to financial discrepancies.

Mitigation

Update the increaseIndexedAssetPeriod() function to use the current value of sharesPerToken instead of globalPool.sharesPerToken.

Diff
  function increaseIndexedAssetPeriod(uint256 sharesPerToken) public onlyRole(DISTRIBUTOR_ROLE) whenNotPaused() {
    globalPool.previousPoolAmounts.push(
      PoolAmount({
        period: globalPool.currentPeriod,
        amount: totalSupply(),
-       sharesPerToken: globalPool.sharesPerToken
+       sharesPerToken: sharesPerToken
      })
    );
    globalPool.currentPeriod++;
    globalPool.sharesPerToken = sharesPerToken;

    emit IncreasedAssetPeriod(globalPool.currentPeriod, sharesPerToken);
  }

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/Convexity-Research/plaza-evm/pull/161

The original report as published on Sherlock, by 0xmystery. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The increaseIndexedAssetPeriod function uses the outdated globalPool.sharesPerToken instead of the current sharesPerToken parameter when recording the shares per token for the period.

Impact

The calculation of coupon tokens that bondholders can claim will be incorrect, potentially leading to financial discrepancies.

What the attacker needed

SharesPerToken has been modified

The fix

The protocol team fixed this issue in the following PRs/commits: https://github.com/Convexity-Research/plaza-evm/pull/161

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When an auction starts, the system records how many coupon tokens each bondholder should get. It uses an old setting instead of the new one, so the amounts are wrong. This means bondholders might get too many or too few coupons.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by 0xmystery

View all

3 more disclosed reports, best first.

More from Plaza Finance

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.