Skip to content
Business logic Audit finding Intermediate

Any fee claim lesser than the total yieldFeeBalance as unit of shares is lost and locked in the PrizeVault contract

The claimYieldFeeShares function subtracts the entire cached yieldFeeBalance from the stored balance instead of only the claimed amount, so any partial claim wipes out the remaining unclaimed fees. An attacker (or the fee recipient themselves) could claim a tiny amount and cause the rest of the accrued fees to be permanently locked in the contract.

DarkTower Follow with 0xJoyBoy03, smbv-1923 and 46 others

Originally disclosed on Code4rena

Submitted by DarkTower, also found by 0xJoyBoy03, smbv-1923, d3e4, 0xlemon, trachev, aua_oo7, Afriauditor, Aymen0909, FastChecker, Dots, AgileJune, leegh, Tripathi, turvy_fuzz, GoSlang, McToady, zhaojie, radin100, yotov721, y4y, 0xkeesmark, 0xRiO, gesha17, iberry, 0xmystery, sammy, Fitro, Greed, 0xJaeger, wangxx2026, dd0x7e8, yvuchev, Abdessamed, Daniel526, kR1s, n1punp, AcT3R, SoosheeTheWise, valentin_s2304, btk, pa6kuda, Al-Qa-qa, asui, dvrkzy, crypticdefense, marqymarq10, DanielTan_MetaTrust, and Krace

Any fee claim by the fee recipient lesser than the accrued internal accounting of the yieldFeeBalance is lost and locked in the PrizeVault contract with no way to pull out the funds.

Proof of Concept

The claimYieldFeeShares allows the yieldFeeRecipient fee recipient to claim fees in yields from the PrizeVault contract. The claimer can claim up to the yieldFeeBalance internal accounting and no more. The issue with this function is it presents a vulnerable area of loss with the _shares argument in the sense that if the accrued yield fee shares is 1000 shares and the claimer claims only 10, 200 or even any amount less than 1000, they forfeit whatever is left of the yieldFeeBalance (e.g if you claimed 200 and hence, got minted 200 shares, you lose the remainder 800 because it wipes the yieldFeeBalance 1000 balance; whereas, they only minted 200 shares).

Let’s see a code breakdown of the vulnerable claimYieldFeeShares function:

function claimYieldFeeShares(uint256 _shares) external onlyYieldFeeRecipient {
        if (_shares == 0) revert MintZeroShares();

        uint256 _yieldFeeBalance = yieldFeeBalance;
        if (_shares > _yieldFeeBalance) revert SharesExceedsYieldFeeBalance(_shares, _yieldFeeBalance);

        yieldFeeBalance -= _yieldFeeBalance; // @audit issue stems and realized next line of code

        _mint(msg.sender, _shares); // @audit the point where the claimant gets to lose

        emit ClaimYieldFeeShares(msg.sender, _shares);
    }

This line of the function caches the total yield fee balance accrued in the contract and hence, the fee recipient is entitled to (e.g 100).

uint256 _yieldFeeBalance = yieldFeeBalance;

This next line of code enforces a comparison check making sure the claimer cannot grief other depositors in the vault because the claimant could, for example, try to claim and mint 150 shares; whereas, they are only entitled to 100.

if (_shares > _yieldFeeBalance) revert SharesExceedsYieldFeeBalance(_shares, _yieldFeeBalance);

This line of code subtracts the cached total yield fee balance from the state yield fee balance (e.g 100 - 100). So if say Bob, the claimant, tried to only mint 50 shares at this point in time with the _shares argument, the code wipes the entire balance of 100.

yieldFeeBalance -= _yieldFeeBalance;

And this line of code then mints the specified _shares amount (e.g 50 shares) to Bob:

_mint(msg.sender, _shares);

So what essentially happens is:

  • Total accrued fee is 100.
  • Bob claims 50 shares of the 100.
  • Bob gets minted 50 shares.
  • Bob loses the rest 50 shares.

Here’s a POC for this issue. Place the testUnclaimedFeesLostPOC function inside the PrizeVault.t.sol file and run the test.

function testUnclaimedFeesLostPOC() public {
        vault.setYieldFeePercentage(1e8); // 10%
        vault.setYieldFeeRecipient(bob); // fee recipient bob
        assertEq(vault.totalDebt(), 0); // no deposits in vault yet

        // alice makes an initial deposit of 100 WETH
        underlyingAsset.mint(alice, 100e18);
        vm.startPrank(alice);
        underlyingAsset.approve(address(vault), 100e18);
        vault.deposit(100e18, alice);
        vm.stopPrank();

        console.log("Shares balance of Alice post mint: ", vault.balanceOf(alice));

        assertEq(vault.totalAssets(), 100e18);
        assertEq(vault.totalSupply(), 100e18);
        assertEq(vault.totalDebt(), 100e18);

        // mint yield to the vault and liquidate
        underlyingAsset.mint(address(vault), 100e18);
        vault.setLiquidationPair(address(this));
        uint256 maxLiquidation = vault.liquidatableBalanceOf(address(underlyingAsset));
        uint256 amountOut = maxLiquidation / 2;
        uint256 yieldFee = (100e18 - vault.yieldBuffer()) / (2 * 10); // 10% yield fee + 90% amountOut = 100%
        vault.transferTokensOut(address(0), bob, address(underlyingAsset), amountOut);
        console.log("Accrued yield post in the contract to be claimed by Bob: ", vault.yieldFeeBalance());
        console.log("Yield fee: ", yieldFee);
        // yield fee: 4999999999999950000
        // alice mint: 100000000000000000000

        assertEq(vault.totalAssets(), 100e18 + 100e18 - amountOut); // existing balance + yield - amountOut
        assertEq(vault.totalSupply(), 100e18); // no change in supply since liquidation was for assets
        assertEq(vault.totalDebt(), 100e18 + yieldFee); // debt increased since we reserved shares for the yield fee

        vm.startPrank(bob);
        vault.claimYieldFeeShares(1e17);

        console.log("Accrued yield got reset to 0: ", vault.yieldFeeBalance());
        console.log("But the shares minted to Bob (yield fee recipient) should be 4.9e18 but he only has 1e17 and the rest is lost: ", vault.balanceOf(bob));

        // shares bob: 100000000000000000
        assertEq(vault.totalDebt(), vault.totalSupply());
        assertEq(vault.yieldFeeBalance(), 0);
        vm.stopPrank();
    }
Test logs and results:
Logs:
  Shares balance of Alice post mint:  100000000000000000000
  Accrued yield in the contract to be claimed by Bob:  4999999999999950000
  Yield fee:  4999999999999950000
  Accrued yield got reset to 0:  0
  But the shares minted to Bob (yield fee recipient) should be 4.9e18 but he only has 1e17 and the rest is lost:  100000000000000000

Tools Used

Foundry

Recommended Mitigation Steps

Adjust the claimYieldFeeShares to only deduct the amount claimed/minted:

function claimYieldFeeShares(uint256 _shares) external onlyYieldFeeRecipient {
  if (_shares == 0) revert MintZeroShares();

-  uint256 _yieldFeeBalance = yieldFeeBalance;
-  if (_shares > _yieldFeeBalance) revert SharesExceedsYieldFeeBalance(_shares, _yieldFeeBalance);
+  if (_shares > yieldFeeBalance) revert SharesExceedsYieldFeeBalance(_shares, yieldFeeBalance);

-  yieldFeeBalance -= _yieldFeeBalance;
+  yieldFeeBalance -= _shares;

  _mint(msg.sender, _shares);

  emit ClaimYieldFeeShares(msg.sender, _shares);
}

trmid (PoolTogether) confirmed and commented:

Mitigated here.


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

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

PoolTogether is a prize savings protocol. The target here is the PrizeVault contract, which holds depositor assets, mints shares against deposits, and accrues a yield fee that a designated fee recipient can later claim. The fee is tracked internally in a state variable called yieldFeeBalance, denominated in shares, and the recipient pulls it out through claimYieldFeeShares(uint256 _shares).

The function is meant to let the fee recipient mint up to the accrued yieldFeeBalance as shares. The report shows that the accounting inside that function does not match the amount actually minted, so any claim smaller than the full accrued balance destroys the remainder.

Setup

The proof of concept is a Foundry test placed inside the existing PrizeVault.t.sol file. The test uses the vault's own test harness: an underlyingAsset (WETH in the test), two actors, alice as depositor and bob as fee recipient, and the test contract itself acting as the liquidation pair. The tool used is Foundry.

Preconditions for the bug to matter: the vault has accrued a non-zero yieldFeeBalance, and the fee recipient calls claimYieldFeeShares with a _shares value lower than that balance.

Finding it

The researcher read claimYieldFeeShares and noticed that the function caches the whole yieldFeeBalance into a local variable, then subtracts that cached total from the state variable, while minting only the requested _shares. The check above it only prevents claiming more than the balance; nothing prevents claiming less. The result is that a partial claim wipes the full balance but mints only part of it.

The vulnerable function as quoted in the report:

Solidity
function claimYieldFeeShares(uint256 _shares) external onlyYieldFeeRecipient {
        if (_shares == 0) revert MintZeroShares();

        uint256 _yieldFeeBalance = yieldFeeBalance;
        if (_shares > _yieldFeeBalance) revert SharesExceedsYieldFeeBalance(_shares, _yieldFeeBalance);

        yieldFeeBalance -= _yieldFeeBalance; // @audit issue stems and realized next line of code

        _mint(msg.sender, _shares); // @audit the point where the claimant gets to lose

        emit ClaimYieldFeeShares(msg.sender, _shares);
    }

Line by line, as the report walks through it:

  1. uint256 _yieldFeeBalance = yieldFeeBalance; caches the total accrued fee the recipient is entitled to (the report's example is 100).
  2. if (_shares > _yieldFeeBalance) revert SharesExceedsYieldFeeBalance(_shares, _yieldFeeBalance); stops the recipient claiming more than they are owed, for example minting 150 when only 100 is accrued.
  3. yieldFeeBalance -= _yieldFeeBalance; subtracts the cached total from the state variable, so 100 minus 100 leaves zero, regardless of how much was requested.
  4. _mint(msg.sender, _shares); mints only the requested amount, for example 50.

The report's summary of the sequence: total accrued fee is 100, Bob claims 50 shares of the 100, Bob gets minted 50 shares, and Bob loses the remaining 50 shares.

Exploitation

Step 1: configure the vault and make the initial deposit

The test sets a 10% yield fee, makes Bob the fee recipient, and has Alice deposit 100 WETH. It then asserts the vault's starting state.

Solidity
function testUnclaimedFeesLostPOC() public {
        vault.setYieldFeePercentage(1e8); // 10%
        vault.setYieldFeeRecipient(bob); // fee recipient bob
        assertEq(vault.totalDebt(), 0); // no deposits in vault yet

        // alice makes an initial deposit of 100 WETH
        underlyingAsset.mint(alice, 100e18);
        vm.startPrank(alice);
        underlyingAsset.approve(address(vault), 100e18);
        vault.deposit(100e18, alice);
        vm.stopPrank();

        console.log("Shares balance of Alice post mint: ", vault.balanceOf(alice));

        assertEq(vault.totalAssets(), 100e18);
        assertEq(vault.totalSupply(), 100e18);
        assertEq(vault.totalDebt(), 100e18);

After this, Alice holds 100e18 shares, total assets, total supply and total debt are all 100e18, and no fee has accrued yet.

Step 2: generate yield and liquidate half of it

The test mints 100 WETH of yield directly into the vault, registers the test contract as the liquidation pair, and liquidates half of the liquidatable balance. It computes the expected yield fee as 10% of the liquidated amount.

Solidity
        // mint yield to the vault and liquidate
        underlyingAsset.mint(address(vault), 100e18);
        vault.setLiquidationPair(address(this));
        uint256 maxLiquidation = vault.liquidatableBalanceOf(address(underlyingAsset));
        uint256 amountOut = maxLiquidation / 2;
        uint256 yieldFee = (100e18 - vault.yieldBuffer()) / (2 * 10); // 10% yield fee + 90% amountOut = 100%
        vault.transferTokensOut(address(0), bob, address(underlyingAsset), amountOut);
        console.log("Accrued yield post in the contract to be claimed by Bob: ", vault.yieldFeeBalance());
        console.log("Yield fee: ", yieldFee);
        // yield fee: 4999999999999950000
        // alice mint: 100000000000000000000

        assertEq(vault.totalAssets(), 100e18 + 100e18 - amountOut); // existing balance + yield - amountOut
        assertEq(vault.totalSupply(), 100e18); // no change in supply since liquidation was for assets
        assertEq(vault.totalDebt(), 100e18 + yieldFee); // debt increased since we reserved shares for the yield fee

transferTokensOut is the liquidation step that realises the yield and books the fee. After it, yieldFeeBalance is 4999999999999950000, matching the computed yieldFee. Total supply is unchanged because the liquidation was for assets, and total debt has grown by the yield fee because shares were reserved for it.

Step 3: claim less than the accrued balance

Bob, as fee recipient, claims 1e17 shares, which is far below the accrued 4999999999999950000.

Solidity
        vm.startPrank(bob);
        vault.claimYieldFeeShares(1e17);

        console.log("Accrued yield got reset to 0: ", vault.yieldFeeBalance());
        console.log("But the shares minted to Bob (yield fee recipient) should be 4.9e18 but he only has 1e17 and the rest is lost: ", vault.balanceOf(bob));

        // shares bob: 100000000000000000
        assertEq(vault.totalDebt(), vault.totalSupply());
        assertEq(vault.yieldFeeBalance(), 0);
        vm.stopPrank();
    }

The test output confirms the loss:

Text
Test logs and results:
Logs:
  Shares balance of Alice post mint:  100000000000000000000
  Accrued yield in the contract to be claimed by Bob:  4999999999999950000
  Yield fee:  4999999999999950000
  Accrued yield got reset to 0:  0
  But the shares minted to Bob (yield fee recipient) should be 4.9e18 but he only has 1e17 and the rest is lost:  100000000000000000

Bob ends up with 100000000000000000 shares, yieldFeeBalance is zero, and the difference between the accrued fee and the minted amount is stranded in the vault. The final assertion shows total debt equal to total supply, so the reserved shares are gone from the accounting.

Root cause

The bug is a mismatch between the amount deducted from yieldFeeBalance and the amount minted. The function subtracts the cached total (_yieldFeeBalance) instead of the requested _shares, so the state variable is zeroed on every claim, while _mint only credits _shares. The only guard, if (_shares > _yieldFeeBalance), enforces an upper bound and does nothing about a lower one. There is no path in the contract to recover the difference, so the unclaimed portion is locked.

Impact

The fee recipient permanently loses any part of the accrued yield fee they do not claim in a single call. In the test, roughly 4.8e18 of the 4.9e18 accrued shares are lost. The report frames this as funds locked in the PrizeVault with no way to pull them out. The loss falls on the fee recipient, not on depositors, and only occurs when a claim is made for less than the full yieldFeeBalance.

Fix

The recommended mitigation is to deduct only the amount actually claimed, and to compare against the state variable directly:

Solidity
function claimYieldFeeShares(uint256 _shares) external onlyYieldFeeRecipient {
  if (_shares == 0) revert MintZeroShares();

-  uint256 _yieldFeeBalance = yieldFeeBalance;
-  if (_shares > _yieldFeeBalance) revert SharesExceedsYieldFeeBalance(_shares, _yieldFeeBalance);
+  if (_shares > yieldFeeBalance) revert SharesExceedsYieldFeeBalance(_shares, yieldFeeBalance);

-  yieldFeeBalance -= _yieldFeeBalance;
+  yieldFeeBalance -= _shares;

  _mint(msg.sender, _shares);

  emit ClaimYieldFeeShares(msg.sender, _shares);
}

With this change, a partial claim leaves the remainder in yieldFeeBalance for a later call. The PoolTogether team confirmed the issue and linked a mitigation pull request on the pt-v5-vault repository.

Variants to test

  1. Any claim or withdraw function that caches a balance into a local variable and then subtracts the cached value rather than the requested amount. A positive result is a state variable that drops to zero while the credited amount is smaller.
  2. Functions with an upper-bound check (requested > balance) but no lower-bound handling. Look for a partial call that zeroes the accounting.
  3. Reward, fee and dividend accumulators where the recipient can choose the amount to pull. Check whether the remainder survives a partial pull.
  4. Accounting that reserves shares (debt) separately from minting them. If the reservation is cleared but the mint is partial, the difference is stranded; a positive result is total debt and total supply converging after a partial claim.

Hunting notes

This class of bug hides in claim, harvest and withdraw paths where a cached total is used for the subtraction and a user-supplied amount is used for the credit. During review, compare every -= against the argument that drives the corresponding mint or transfer; if they are different variables, the remainder is suspect. The signal is a local variable named after the state variable it shadows, used in the subtraction line. The researcher demonstrated impact with a full Foundry test that prints the accrued balance, the claimed amount, the resulting balance and the reset state variable, which makes the loss explicit and reproducible. The project confirmed the issue and linked a mitigation pull request.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 13 min read.

What happened, in plain words

PoolTogether is a savings game built on a blockchain. People put money (in this case a digital token called WETH) into a shared pot called a vault, and the interest that pot earns is used to fund prizes. The vault is a piece of software called a smart contract: a program that lives on the blockchain and runs automatically, with no company in the middle. The contract in question is called PrizeVault.

When the vault earns interest, a small cut of it goes to a designated person or address called the fee recipient. That cut is called the yield fee. The contract keeps a running tally of how much fee is owed, stored in a variable (a named slot in the contract's memory) called yieldFeeBalance. The tally is counted in shares, which are the vault's internal units of ownership, a bit like the number of slices a pizza has been cut into.

To collect the fee, the fee recipient calls a function called claimYieldFeeShares and says how many shares they want. The function is supposed to hand over up to the amount owed. The bug is that the function wipes the entire tally no matter how much is actually handed over. So if the recipient is owed 100 shares and asks for only 50, they get 50 and the other 50 vanish: the tally is reset to zero and there is no way to get the rest back.

This is a high severity finding because money is permanently lost. It was reported to PoolTogether through the Code4rena audit platform, the project confirmed it, and a mitigation pull request was linked.

Background you need

A few ideas come up again and again, so here they are from scratch.

  • Smart contract: a program stored on a blockchain. Once deployed, anyone can call its functions, and it runs exactly as written. Nobody can quietly edit it afterwards.
  • Function: a named action inside a program. claimYieldFeeShares is one; calling it is like pressing a button.
  • Variable and state variable: a named storage slot. A state variable is one whose value is kept permanently in the contract, like a number written on a whiteboard that everyone can read. yieldFeeBalance is a state variable.
  • Local variable: a temporary value that exists only while one function call is running, like a scribble on a sticky note. The report's _yieldFeeBalance is a local variable.
  • Caching: copying a value into a local variable so you can use it several times without reading the state variable again. It is like copying a number off the whiteboard onto a sticky note.
  • Mint: create new shares out of thin air and credit them to someone. The vault mints shares when people deposit, and also when the fee recipient claims.
  • Shares: the vault's internal units of ownership. Depositors get shares for their money; the fee recipient gets shares for the fee.
  • Yield: the interest or profit the vault's assets earn over time.
  • Fee recipient: the address allowed to collect the yield fee.
  • Revert: cancel the whole transaction and undo everything, like a shop refusing a payment and handing your card back. A revert statement is a guard that stops bad input.
  • Assertion (assertEq): a check in a test that two values are equal. If they are not, the test fails loudly.
  • Foundry: a toolkit for writing and running tests against smart contracts. The proof of concept here is a Foundry test.
  • Proof of concept (PoC): a small, runnable demonstration that proves a bug is real.

The vulnerable function

Here is the function as quoted in the report:

Solidity
function claimYieldFeeShares(uint256 _shares) external onlyYieldFeeRecipient {
        if (_shares == 0) revert MintZeroShares();

        uint256 _yieldFeeBalance = yieldFeeBalance;
        if (_shares > _yieldFeeBalance) revert SharesExceedsYieldFeeBalance(_shares, _yieldFeeBalance);

        yieldFeeBalance -= _yieldFeeBalance; // @audit issue stems and realized next line of code

        _mint(msg.sender, _shares); // @audit the point where the claimant gets to lose

        emit ClaimYieldFeeShares(msg.sender, _shares);
    }

Line by line, in plain words:

  1. function claimYieldFeeShares(uint256 _shares) external onlyYieldFeeRecipient { declares the function. It takes one number, _shares, the amount the caller wants. external means anyone outside the contract can call it. onlyYieldFeeRecipient is a guard that only lets the designated fee recipient through, like a door that only opens for one key.
  2. if (_shares == 0) revert MintZeroShares(); refuses a request for zero shares. There is no point minting nothing.
  3. uint256 _yieldFeeBalance = yieldFeeBalance; copies the whole accrued fee into a temporary local variable. The report's example value is 100.
  4. if (_shares > _yieldFeeBalance) revert SharesExceedsYieldFeeBalance(_shares, _yieldFeeBalance); refuses a request for more than is owed. Asking for 150 when only 100 is accrued is blocked. This is an upper limit only; nothing here stops someone asking for less.
  5. yieldFeeBalance -= _yieldFeeBalance; subtracts the copied total from the stored tally. In the example, 100 minus 100 leaves zero, no matter what was requested. This is the bug.
  6. _mint(msg.sender, _shares); creates only the requested number of shares, for example 50, and gives them to the caller.
  7. emit ClaimYieldFeeShares(msg.sender, _shares); writes a public log entry recording the claim, so the outside world can see it happened.

The mismatch is between steps 5 and 6: the tally is reduced by the full amount, but only part of it is handed out. The report sums it up as: total accrued fee is 100, Bob claims 50 of the 100, Bob is minted 50 shares, and Bob loses the remaining 50.

Reproducing it

The proof of concept is a Foundry test placed inside the existing PrizeVault.t.sol test file. The test uses the vault's own test setup: a token called underlyingAsset (WETH in the test), two actors, alice as the depositor and bob as the fee recipient, and the test contract itself playing the role of the liquidation pair (the component that turns accrued yield into realised profit).

For the bug to bite, two things must be true: the vault has accrued a non-zero yieldFeeBalance, and the fee recipient claims less than that balance.

Step 1: set up the vault and make the first deposit

The test sets a 10% yield fee, makes Bob the fee recipient, and has Alice deposit 100 WETH. It then checks the vault's starting numbers.

Solidity
function testUnclaimedFeesLostPOC() public {
        vault.setYieldFeePercentage(1e8); // 10%
        vault.setYieldFeeRecipient(bob); // fee recipient bob
        assertEq(vault.totalDebt(), 0); // no deposits in vault yet

        // alice makes an initial deposit of 100 WETH
        underlyingAsset.mint(alice, 100e18);
        vm.startPrank(alice);
        underlyingAsset.approve(address(vault), 100e18);
        vault.deposit(100e18, alice);
        vm.stopPrank();

        console.log("Shares balance of Alice post mint: ", vault.balanceOf(alice));

        assertEq(vault.totalAssets(), 100e18);
        assertEq(vault.totalSupply(), 100e18);
        assertEq(vault.totalDebt(), 100e18);

What each part does:

  1. vault.setYieldFeePercentage(1e8); sets the fee to 10%. The number 1e8 is a way of writing 100,000,000, which the contract treats as 10% because it counts in very fine units.
  2. vault.setYieldFeeRecipient(bob); names Bob as the person who can collect the fee.
  3. assertEq(vault.totalDebt(), 0); checks that the vault owes nothing yet, because nobody has deposited.
  4. underlyingAsset.mint(alice, 100e18); creates 100 WETH for Alice in the test. 100e18 is 100 followed by 18 zeros, the standard way tokens with 18 decimal places are written.
  5. vm.startPrank(alice); tells Foundry to act as Alice for the following calls. It is like logging in as a particular user.
  6. underlyingAsset.approve(address(vault), 100e18); lets the vault take up to 100 WETH from Alice. This is the standard permission step before a deposit.
  7. vault.deposit(100e18, alice); moves Alice's 100 WETH into the vault and credits her with shares.
  8. vm.stopPrank(); stops acting as Alice.
  9. console.log(...) prints Alice's share balance so the test output shows it.
  10. The three assertEq lines check that total assets, total supply and total debt are all 100e18. In other words, the vault holds exactly what Alice put in, and no fee has accrued yet.

Step 2: create yield and liquidate half of it

The test now adds 100 WETH of yield directly to the vault, registers the test contract as the liquidation pair, and liquidates half of what is available. It also works out the expected fee as 10% of the liquidated amount.

Solidity
        // mint yield to the vault and liquidate
        underlyingAsset.mint(address(vault), 100e18);
        vault.setLiquidationPair(address(this));
        uint256 maxLiquidation = vault.liquidatableBalanceOf(address(underlyingAsset));
        uint256 amountOut = maxLiquidation / 2;
        uint256 yieldFee = (100e18 - vault.yieldBuffer()) / (2 * 10); // 10% yield fee + 90% amountOut = 100%
        vault.transferTokensOut(address(0), bob, address(underlyingAsset), amountOut);
        console.log("Accrued yield post in the contract to be claimed by Bob: ", vault.yieldFeeBalance());
        console.log("Yield fee: ", yieldFee);
        // yield fee: 4999999999999950000
        // alice mint: 100000000000000000000

        assertEq(vault.totalAssets(), 100e18 + 100e18 - amountOut); // existing balance + yield - amountOut
        assertEq(vault.totalSupply(), 100e18); // no change in supply since liquidation was for assets
        assertEq(vault.totalDebt(), 100e18 + yieldFee); // debt increased since we reserved shares for the yield fee

What each part does:

  1. underlyingAsset.mint(address(vault), 100e18); creates 100 WETH and puts it straight into the vault. This stands in for interest the vault has earned.
  2. vault.setLiquidationPair(address(this)); makes the test contract the liquidation pair, the component allowed to turn yield into realised profit.
  3. uint256 maxLiquidation = vault.liquidatableBalanceOf(address(underlyingAsset)); asks the vault how much can be liquidated right now.
  4. uint256 amountOut = maxLiquidation / 2; takes half of that amount.
  5. uint256 yieldFee = (100e18 - vault.yieldBuffer()) / (2 * 10); calculates the expected fee: 10% of the liquidated amount, after subtracting a small buffer the vault keeps.
  6. vault.transferTokensOut(address(0), bob, address(underlyingAsset), amountOut); performs the liquidation, sending the liquidated tokens out and booking the fee. This is the step that makes the fee real.
  7. The two console.log lines print the accrued fee and the calculated fee so they can be compared.
  8. The three assertEq lines check the vault's numbers afterwards: total assets equal the original deposit plus the yield minus what was liquidated; total supply is unchanged because the liquidation was in assets, not shares; and total debt has grown by the fee, because shares were set aside to pay it.

After this step, yieldFeeBalance is 4999999999999950000, matching the calculated yieldFee.

Step 3: claim less than what is owed

Bob, as fee recipient, now claims 1e17 shares, far below the accrued 4999999999999950000.

Solidity
        vm.startPrank(bob);
        vault.claimYieldFeeShares(1e17);

        console.log("Accrued yield got reset to 0: ", vault.yieldFeeBalance());
        console.log("But the shares minted to Bob (yield fee recipient) should be 4.9e18 but he only has 1e17 and the rest is lost: ", vault.balanceOf(bob));

        // shares bob: 100000000000000000
        assertEq(vault.totalDebt(), vault.totalSupply());
        assertEq(vault.yieldFeeBalance(), 0);
        vm.stopPrank();
    }

What each part does:

  1. vm.startPrank(bob); switches to acting as Bob.
  2. vault.claimYieldFeeShares(1e17); calls the vulnerable function, asking for 1e17 shares, which is much less than the accrued fee.
  3. The first console.log prints the remaining tally, which the test expects to be zero.
  4. The second console.log prints Bob's share balance, showing he received only 1e17 even though far more was owed.
  5. assertEq(vault.totalDebt(), vault.totalSupply()); checks that the vault's debt now equals its supply, meaning the shares reserved for the fee are gone from the accounting.
  6. assertEq(vault.yieldFeeBalance(), 0); checks that the tally has been reset to zero.
  7. vm.stopPrank(); stops acting as Bob.

The test output confirms the loss:

Text
Test logs and results:
Logs:
  Shares balance of Alice post mint:  100000000000000000000
  Accrued yield in the contract to be claimed by Bob:  4999999999999950000
  Yield fee:  4999999999999950000
  Accrued yield got reset to 0:  0
  But the shares minted to Bob (yield fee recipient) should be 4.9e18 but he only has 1e17 and the rest is lost:  100000000000000000

Bob ends up with 100000000000000000 shares, the tally is zero, and the gap between what was owed and what was minted is stuck in the vault. The final assertion shows total debt equal to total supply, so the reserved shares have disappeared from the books.

Why it happens

The root cause is a mismatch between the amount taken off the tally and the amount handed out. The function subtracts the copied total (_yieldFeeBalance) instead of the requested _shares, so the tally is zeroed on every claim, while _mint only credits _shares. The only guard, if (_shares > _yieldFeeBalance), sets an upper limit and says nothing about a lower one. Nothing in the contract can recover the difference, so the unclaimed part is locked.

What it costs

The fee recipient permanently loses any part of the accrued fee they do not claim in a single call. In the test, roughly 4.8e18 of the 4.9e18 accrued shares are lost. The report describes this as funds locked in the PrizeVault with no way to pull them out. The loss falls on the fee recipient, not on depositors, and only happens when a claim is made for less than the full yieldFeeBalance.

The fix

The recommended change is to deduct only the amount actually claimed, and to compare against the stored tally directly:

Solidity
function claimYieldFeeShares(uint256 _shares) external onlyYieldFeeRecipient {
  if (_shares == 0) revert MintZeroShares();

-  uint256 _yieldFeeBalance = yieldFeeBalance;
-  if (_shares > _yieldFeeBalance) revert SharesExceedsYieldFeeBalance(_shares, _yieldFeeBalance);
+  if (_shares > yieldFeeBalance) revert SharesExceedsYieldFeeBalance(_shares, yieldFeeBalance);

-  yieldFeeBalance -= _yieldFeeBalance;
+  yieldFeeBalance -= _shares;

  _mint(msg.sender, _shares);

  emit ClaimYieldFeeShares(msg.sender, _shares);
}

The lines marked with a minus sign are removed and the lines marked with a plus sign are added. The temporary copy of the tally is gone; the check compares the request against the stored tally directly; and the subtraction now removes exactly _shares, the amount actually minted. With this change, a partial claim leaves the remainder in yieldFeeBalance for a later call. The PoolTogether team confirmed the issue and linked a mitigation pull request on the pt-v5-vault repository.

Similar places to look

  1. Any claim or withdraw function that copies a balance into a local variable and then subtracts the copy rather than the requested amount. A positive result is a stored tally that drops to zero while the amount credited is smaller.
  2. Functions with an upper-limit check (requested > balance) but no handling of a lower amount. Look for a partial call that zeroes the accounting.
  3. Reward, fee and dividend tallies where the recipient chooses how much to pull. Check whether the remainder survives a partial pull.
  4. Accounting that reserves shares (debt) separately from minting them. If the reservation is cleared but the mint is partial, the difference is stranded; a positive result is total debt and total supply converging after a partial claim.

How to spot it during a review

This kind of bug hides in claim, harvest and withdraw paths where a copied total drives the subtraction and a user-supplied amount drives the credit. When reviewing, compare every -= against the argument that drives the matching mint or transfer; if they are different variables, the remainder is suspect. The tell is a local variable named after the state variable it shadows, used in the subtraction line. The researcher proved the impact with a full Foundry test that prints the accrued balance, the claimed amount, the resulting balance and the reset tally, which makes the loss explicit and repeatable. The project confirmed the issue and linked a mitigation pull request.

Glossary

  • Smart contract: a program stored on a blockchain that runs automatically when its functions are called.
  • Blockchain: a shared, tamper-resistant record of transactions maintained by many computers.
  • Function: a named action inside a program that can be called.
  • Variable: a named storage slot holding a value.
  • State variable: a variable whose value is stored permanently in the contract.
  • Local variable: a temporary value that exists only during one function call.
  • Caching: copying a value into a local variable so it can be reused without reading the original again.
  • Mint: create new tokens or shares and credit them to an address.
  • Share: the vault's internal unit of ownership, representing a claim on the vault's assets.
  • Yield: the interest or profit earned by the vault's assets over time.
  • Yield fee: a cut of the yield paid to a designated recipient.
  • Vault: a contract that holds assets on behalf of depositors and tracks their shares.
  • Liquidation pair: the component that turns accrued yield into realised profit.
  • Revert: cancel a transaction and undo its effects, used as a guard against bad input.
  • Assertion (assertEq): a test check that two values are equal, failing the test if they are not.
  • WETH: a token representing wrapped ether, used as the deposit asset in the test.
  • 1e18 notation: a way of writing a number followed by 18 zeros, matching tokens with 18 decimal places.
  • Total supply: the total number of shares in existence.
  • Total assets: the total value of assets held by the vault.
  • Total debt: the vault's internal record of value owed to share holders, including shares reserved for fees.
  • Pull request: a proposed change to a code repository that can be reviewed and merged.

More by DarkTower

View all

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