Skip to content
Business logic Audit finding Intermediate

A malicious early user/attacker can manipulate the vault’s pricePerShare to take an unfair share of future users’ deposits

The vault's share price calculation can be manipulated by an early depositor who deposits a tiny amount and then inflates the price per share, causing later depositors to receive far fewer shares and lose funds. The attacker can also redeem tokens for free due to precision loss.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug, also found by 0xDjango, berndartmueller, CertoraInc, gzeon, kebabsec, leastwood, Tadashi, and unforgiven

This is a well-known attack vector for new contracts that utilize pricePerShare for accounting.

AaveV3YieldSource.sol#L352-L374

  /**
   * @notice Calculates the number of shares that should be minted or burnt when a user deposit or withdraw.
   * @param _tokens Amount of asset tokens
   * @return Number of shares.
   */
  function _tokenToShares(uint256 _tokens) internal view returns (uint256) {
    uint256 _supply = totalSupply();

    // shares = (tokens * totalShares) / yieldSourceATokenTotalSupply
    return _supply == 0 ? _tokens : _tokens.mul(_supply).div(aToken.balanceOf(address(this)));
  }

  /**
   * @notice Calculates the number of asset tokens a user has in the yield source.
   * @param _shares Amount of shares
   * @return Number of asset tokens.
   */
  function _sharesToToken(uint256 _shares) internal view returns (uint256) {
    uint256 _supply = totalSupply();

    // tokens = (shares * yieldSourceATokenTotalSupply) / totalShares
    return _supply == 0 ? _shares : _shares.mul(aToken.balanceOf(address(this))).div(_supply);
  }

A malicious early user can supplyTokenTo() with 1 wei of _underlyingAssetAddress token as the first depositor of the AaveV3YieldSource.sol, and get 1 wei of shares token.

Then the attacker can send 10000e18 - 1 of aToken and inflate the price per share from 1.0000 to an extreme value of 1.0000e22 ( from (1 + 10000e18 - 1) / 1) .

As a result, the future user who deposits 19999e18 will only receive 1 wei (from 19999e18 * 1 / 10000e18) of shares token.

They will immediately lose 9999e18 or half of their deposits if they redeemToken() right after the supplyTokenTo().

AaveV3YieldSource.sol#L251-L256

  function redeemToken(uint256 _redeemAmount) external override nonReentrant returns (uint256) {
    address _underlyingAssetAddress = _tokenAddress();
    IERC20 _assetToken = IERC20(_underlyingAssetAddress);

    uint256 _shares = _tokenToShares(_redeemAmount);
    _burn(msg.sender, _shares);
    ...

Furthermore, after the PPS has been inflated to an extremely high value (10000e18), the attacker can also redeem tokens up to 9999e18 for free, (burn 0 shares) due to the precision loss.

Recommended Mitigation Steps

Consider requiring a minimal amount of share tokens to be minted for the first minter, and send a port of the initial mints as a reserve to the DAO address so that the pricePerShare can be more resistant to manipulation.

Also, consder adding require(_shares > 0, "AaveV3YS/shares-gt-zero"); before _burn(msg.sender, _shares);.

PierrickGT (PoolTogether) confirmed and commented:

PR: https://github.com/pooltogether/aave-v3-yield-source/pull/15


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

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

Likely the share price calculation uses the vault's token balance directly, allowing an attacker to inflate it by transferring tokens without minting shares, combined with rounding down to zero shares for small deposits.

Impact

Future depositors could lose up to half of their deposits, and the attacker can redeem tokens for free, but the text does not state whether this was actually exploited.

What the attacker needed

Attacker is first depositor; attacker can transfer aTokens directly

The fix

The fix should require a minimum number of shares to be minted for the first depositor and add a check that shares are greater than zero before burning.

How it was found

  1. Attacker deposits 1 wei of the underlying token as the first depositor, receiving 1 wei of shares.
  2. Attacker transfers a large amount of aTokens directly to the vault, inflating the price per share.
  3. A future user deposits a large amount, but receives only 1 wei of shares due to rounding.
  4. The user loses half of their deposit if they redeem immediately.
  5. Attacker can also redeem up to a large amount for free due to precision loss.

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.

This is a smart contract vault where users deposit tokens and get shares in return. The number of shares you get depends on the total value of the vault divided by the total shares. An attacker can be the first to deposit a tiny amount, then send a large amount of tokens directly to the vault to make each share very expensive. When a normal user deposits later, they get very few shares and lose most of their money if they withdraw immediately.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by WatchPug

View all

197 more disclosed reports, best first.

More from PoolTogether

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.