Skip to content
Business logic Audit finding Intermediate

PrizeVault.maxDeposit() doesn’t take into account produced fees

The vault's maxDeposit() function did not subtract accrued yield fees from the TWAB supply limit, so a user could deposit up to the full limit and leave no room to mint fee shares. The yield fee recipient then could not claim earned fees because the share mint would overflow.

pa6kuda Follow with 0xhunter20 and Afriauditor

Originally disclosed on Code4rena

Submitted by pa6kuda, also found by 0xhunter20 and Afriauditor

https://github.com/code-423n4/2024-03-pooltogether/blob/480d58b9e8611c13587f28811864aea138a0021a/pt-v5-vault/src/PrizeVault.sol#L368-L392 https://github.com/code-423n4/2024-03-pooltogether/blob/480d58b9e8611c13587f28811864aea138a0021a/pt-v5-vault/src/PrizeVault.sol#L685 https://github.com/code-423n4/2024-03-pooltogether/blob/480d58b9e8611c13587f28811864aea138a0021a/pt-v5-vault/src/PrizeVault.sol#L619

Summary

Currently, PrizeVault.maxDeposit() calculates the maximum possible amount of deposit without taking into account produced fees. That means if there is already maxed deposited amount of asset that is calculated by the current implementation in PrizeVault.maxDeposit(), yieldFeeRecipient can’t withdraw shares with PrizeVault.claimYieldFeeShares() because in that case _mint() will revert because of overflow. A lot of low-price tokens can exceed the limit of type(uint96).max with ease. For example, to make a deposit with maxDeposit() value with LADYS token it’s needed only $13568 (as of 08-03-2024).

Impact

If a user makes a maximum allowed deposit that is calculated by the current implementation of PrizeVault.maxDeposit(), yieldFeeRecipient can’t withdraw fees if they are available.

Proof of Concept

Add this test to PrizeVault.t.sol and run with:

    forge test --match-contract PrizeVaultTest --match-test testMaxDeposit_CalculatesWithoutTakingIntoAccountGeneratedFees
    function _deposit(address account, uint256 amount) private {
        underlyingAsset.mint(account, amount);
        vm.startPrank(account);
        underlyingAsset.approve(address(vault), amount);
        vault.deposit(amount, account);
        vm.stopPrank();
    }

    function testMaxDeposit_CalculatesWithoutTakingIntoAccountGeneratedFees() public {
        vault.setYieldFeePercentage(1e8); // 10%
        vault.setYieldFeeRecipient(bob);

        // alice make initial deposit
        _deposit(alice, 1e18);

        // mint yield to the vault and liquidate
        underlyingAsset.mint(address(vault), 1e18);
        vault.setLiquidationPair(address(this));
        uint256 maxLiquidation = vault.liquidatableBalanceOf(address(underlyingAsset));
        uint256 amountOut = maxLiquidation / 2;
        uint256 yieldFee = (1e18 - vault.yieldBuffer()) / (2 * 10); // 10% yield fee + 90% amountOut = 100%

        // bob transfers tokens out and increase fee
        vault.transferTokensOut(address(0), bob, address(underlyingAsset), amountOut);

        // alice make deposit with maximum available value for deposit
        uint256 maxDeposit = vault.maxDeposit(address(this));
        _deposit(alice, maxDeposit);

        // then bob want to withdraw earned fee but he can't do that
        vm.prank(bob);
        vm.expectRevert();
        vault.claimYieldFeeShares(yieldFee);
    }

Recommended Mitigation Steps

Add function to withdraw fees in asset or change function PrizeVault.maxDeposit() to calculate max deposit with taking into account produced fees:

    function maxDeposit(address) public view returns (uint256) {
        uint256 _totalSupply = totalSupply();
        uint256 totalDebt_ = _totalDebt(_totalSupply);
        if (totalAssets() < totalDebt_) return 0;

        // the vault will never mint more than 1 share per asset, so no need to convert supply limit to assets
        uint256 twabSupplyLimit_ = _twabSupplyLimit(_totalSupply);
        uint256 _maxDeposit;
        uint256 _latentBalance = _asset.balanceOf(address(this));
        uint256 _maxYieldVaultDeposit = yieldVault.maxDeposit(address(this));
        if (_latentBalance >= _maxYieldVaultDeposit) {
            return 0;
        } else {
            unchecked {
                _maxDeposit = _maxYieldVaultDeposit - _latentBalance;
            }
-           return twabSupplyLimit_ < _maxDeposit ? twabSupplyLimit_ : _maxDeposit;
+           return twabSupplyLimit_ < _maxDeposit ? twabSupplyLimit_ - yieldFeeBalance : _maxDeposit - yieldFeeBalance;
        }
    }

Assessed type

Math

trmid (PoolTogether) confirmed and commented:

The TWAB max supply limit is a known issue with the prize vault and the deployer is expected to evaluate the possibility of the limit being exceeded before deploying a new prize vault. This issue has demonstrated that any yield fees accrued in this state may end up locked in the prize vault until enough withdrawals occur to free up the TWAB supply limit. This is undesirable behaviour, since all funds that have entered the prize vault through deposits or yield should be able to be taken out in these unexpected circumstances.

Mitigation here.


The original report as published on Code4rena, by pa6kuda. 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 maxDeposit() calculation compared the TWAB supply limit against the deposit amount without reserving space for the yieldFeeBalance that still needs to be minted as shares.

Impact

If a user deposits the maximum allowed amount, the yield fee recipient cannot claim available fees until enough withdrawals free up the supply limit, so fees may be locked in the vault.

What the attacker needed

Yield fees have accrued in the vault; a deposit reaches the max limit

The fix

The maxDeposit() calculation was changed to subtract the yield fee balance from the returned limit, and a mitigation was linked by the project.

How it was found

  1. Set the yield fee percentage and fee recipient on the vault.
  2. Make an initial deposit as one user.
  3. Mint yield into the vault and liquidate part of it so a fee accrues.
  4. Make a deposit equal to the current maxDeposit() value.
  5. Attempt to claim the accrued fee shares as the fee recipient and observe the revert.

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.

A vault lets people deposit tokens and earn yield, and a small cut of that yield goes to a fee recipient as shares. The vault caps how many shares can exist, but the deposit limit ignored the shares already owed as fees, so a large deposit could fill the cap completely. After that, the fee recipient's shares could not be created, leaving their fees stuck.

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