Skip to content
Business logic Audit finding Intermediate

First depositor inflation attack in PendlePowerFarmToken

The first depositor of a PendlePowerFarmToken can inflate the share price by donating a large amount of underlying assets, causing a subsequent depositor to receive far fewer shares than expected and lose a significant portion of their deposit when withdrawing.

SBSecurity Follow with 0xCiphky

Originally disclosed on Code4rena

Submitted by SBSecurity, also found by 0xCiphky

In certain scenarios, shares of a subsequent depositor can be heavily reduced, losing a large amount of his deposited funds, the attacker can increase the right side of the previewMintShares by adding rewards for compounding.

That way victim can lose 6e17 of his assets for a deposit of 1e18.

Proof of Concept

Let’s see how a first user, can grief a subsequent deposit and reduce his shares from the desired 1:1 ratio to 1:0000000000000005.

First, he needs to choose PowerFarmToken with no previous deposits.

  1. He calls depositExactAmount with 2 wei which will also call syncSupply → _updateRewards which is a key moment of the attack. This will make it possible PowerFarmController::exchangeRewardsForCompoundingWithIncentive to be called when performing the donation.
  2. With 2 wei user will mint 2 shares, so totalSupply = 3 and underlyingLpAssetsCurrent = 3.
  3. Then, the victim comes and tries to deposit 1e18 of assets, but is front ran by the first user calling PowerFarmController::exchangeRewardsForCompoundingWithIncentive → addCompoundRewards with 999999999999999996 that will increase the totalLpAssetsToDistribute, which is added to underlyingLpAssetsCurrent in the _syncSupply function, called from the modifier before the main functions.

The attacker does not lose his deposit of 1e18 because it is converted to rewardTokens and sent to him, basically making the inflation free.

PendlePowerFarmController.sol#L53-L111

function exchangeRewardsForCompoundingWithIncentive(
      address _pendleMarket,
      address _rewardToken,
      uint256 _rewardAmount
  ) external syncSupply(_pendleMarket) returns (uint256) {
      CompoundStruct memory childInfo = pendleChildCompoundInfo[_pendleMarket];

      uint256 index = _findIndex(childInfo.rewardTokens, _rewardToken);

      if (childInfo.reservedForCompound[index] < _rewardAmount) {
          revert NotEnoughCompound();
      }

      uint256 sendingAmount = _getAmountToSend(_pendleMarket, _getTokensInETH(_rewardToken, _rewardAmount));

      childInfo.reservedForCompound[index] -= _rewardAmount;
      pendleChildCompoundInfo[_pendleMarket] = childInfo;

      _safeTransferFrom(_pendleMarket, msg.sender, address(this), sendingAmount);

      IPendlePowerFarmToken(pendleChildAddress[_pendleMarket]).addCompoundRewards(sendingAmount);//@audit inflate

      _safeTransfer(childInfo.rewardTokens[index], msg.sender, _rewardAmount);//@audit receive back + incentive

      emit ExchangeRewardsForCompounding(_pendleMarket, _rewardToken, _rewardAmount, sendingAmount);

      return sendingAmount;
  }

After that, totalSupply = 3, underlyingLpAssetsCurrent = 1e18 - 1. The victim transaction is then executed:

PendlePowerFarmToken.sol#L452-L463

function previewMintShares(uint256 _underlyingAssetAmount, uint256 _underlyingLpAssetsCurrent)
        public
        view
        returns (uint256)
    {
        return _underlyingAssetAmount * totalSupply() / _underlyingLpAssetsCurrent;
        // 1e18 * 3 / 1e18 - 1 = 2
    }

Both attacker and victim have 1 share, because of the fee that is taken in the deposit function.

After victim deposit: totalSupply: 5, underlyingLpAssetsCurrent = 2e18 - 1. Then, the victim tries to withdraw all his shares - 1 (1 was taken as a fee on deposit).

PendlePowerFarmToken.sol#L465-L476

function previewAmountWithdrawShares(uint256 _shares, uint256 _underlyingLpAssetsCurrent)
        public
        view
        returns (uint256)
    {
        return _shares * _underlyingLpAssetsCurrent / totalSupply();
	        //1 * (2e18 - 1) / 5 = 399999999999999999 (0.3e18)
    }

User has lost 1e18 - 0.3e18 = 0.6e18 tokens.

Recommended Mitigation Steps

Since there will be many PowerFarmTokens deployed, there is no way for team to perform the first deposit for all of them. Possible mitigation will be to have minimum deposit amount for the first depositor in the PendlePowerToken, which will increase the cost of the attack exponentially. There will not be enough reward tokens making the exchangeRewardsForCompoundingWithIncentive revert, due to insufficient amount. Or, could mint proper amount of tokens in the initialize function.

vm06007 (Wise Lending) commented:

Since there will be many PowerFarmTokens deployed, there is no way for team to perform the first deposit for all of them.

I think this assumption is wrong here, team deploys each token and farm by admin - one by one, and each time a new token/farm is created, team can perform first deposit or necessary step. It is not a public function to create these that team cannot handle something like that or to say “there is no way to perform the first deposit for all of them”. That’s just blown off and far fetched.

vm06007 (Wise Lending) commented:

Mitigated here.

Additional notes: before any farm is publicly available, admin creating farms can ensure no further supplier to the farm would experience any loss due to described far-fetched scenario in this “finding”.


The original report as published on Code4rena, by SBSecurity. 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 calculation uses the current total assets without protecting against a first depositor inflating the share price via a large donation.

Impact

The victim could lose a large portion of their deposit (e.g., 0.6e18 out of 1e18) due to the share inflation attack.

What the attacker needed

Attacker has reward tokens to donate; Victim deposits after attacker's donation; No prior deposits in the farm token

The fix

The team mitigated the issue by ensuring the admin performs the first deposit or necessary step before the farm is publicly available.

How it was found

  1. Attacker calls depositExactAmount with 2 wei to mint 2 shares, making totalSupply = 3 and underlyingLpAssetsCurrent = 3.
  2. Attacker calls exchangeRewardsForCompoundingWithIncentive with a large amount to addCompoundRewards, increasing underlyingLpAssetsCurrent to 1e18 - 1.
  3. Victim deposits 1e18 assets, but due to the inflated underlyingLpAssetsCurrent, receives only 2 shares (after fee).
  4. Victim withdraws all shares, receiving only about 0.3e18 assets, losing 0.6e18.

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 you deposit money into a shared pool, you get shares representing your portion. If someone else manipulates the pool's total value before you deposit, your shares can be worth much less. Here, the first depositor inflated the pool's value so the next person's deposit bought very few shares, causing a loss.

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 SBSecurity

View all

8 more disclosed reports, best first.

More from Wise Lending

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.