Skip to content
Business logic Audit finding Advanced

theft of funds for new depositers if sUSP can not absorb entire losses

The requestRedeem function records a user's full USP burn amount as their withdrawal entitlement without checking whether the system has enough collateral to cover it. When a yield source loss exceeds what sUSP can absorb, the remaining bad debt is unfairly borne by new depositors who join in a later epoch.

Atharv Follow with Kalyan-Singh and vivekd

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-04-pareto-contest-judging/issues/305

Found by

Atharv, Kalyan-Singh, vivekd

Summary

If in an epoch a loss large enough happens which cannot be offset by sUSP, the paretoQueue instead of socializing loss between the investors till that epoch, unfairly puts all of the remaining bad debt on newer depositors due to faulty requestRedeem implementation.

Root Cause

requestRedeem function in ParetoDollarQueue.sol directly stores ParetoUSP burn amount in userWithdrawalsEpochs mapping & epochPending mapping without even checking whether system has enough totalCollateralScaled to meet the burn amount. Which is possible if a 4626 vault had -ve apy or a CV borrower fails to return full collateral.

Internal Pre-conditions

  • The contract has deposited funds into a yield source (e.g., an ERC4626 vault).

External Pre-conditions

  • The yield source (vault or credit vault) must experience a loss, either through negative APY, default, or other means.
  • The losses must be greater than what sUSP can absorb.

Attack Path

  1. Users A & B deposit collateral, assume total of 15k $ ( 10 + 5)
  2. These funds are deposited to a vault or CV
  3. User B also deposits 1k of his USP in sUSP. So currently totalAssets staked are only 1k
  4. The yield source incurs a loss of 10% amounting to 1500 $
  5. owner offsets 1k by burning all assets in sUSP. Now 500 $ is left which is our bad debt.
  6. both users (A & B) call paretoDollar.requestRedeem() with their entire balance, making the following stateChanges userWithdrawalsEpoch[userA][1] = 10k userWithdrawalsEpoch[userB][1] = 4k totReservedWithdrawal = 14k epochPending[1] = 14k
  7. Manager moves the epoch ahead,epoch is now =2 & calls redeemFunds() , at the same time ( in the same epoch i.e 2) a User C deposits 2k into the system
Solidity
	  .....
    balPre = _yieldSource.token.balanceOf(address(this));
    _externalCall(source, _methods[i], _args[i]);
    redeemed = _yieldSource.token.balanceOf(address(this)) - balPre;
      ....
    if (_epoch != epochNumber) {
      if (totRedeemedScaled >= _epochPending) {
        if (_epochPending > 0) {
          epochPending[_epoch] = 0;
        }
      } else {
        epochPending[_epoch] -= totRedeemedScaled;
      }
    }
      
  1. In redeemFunds() the above code is executed, in our case balPre =2000 $ (from user C deposits)
  2. externalCall happens & totRedeemedScaled = 13500 $ ( 10% loss)
  3. so the code inside else is executed & now epochPending[1] = 14k-13500 = 500
  4. Now all shares for this vault are burned & every epoch related function or withdrawal function will revert as epochPending[1] !=0
  5. Now manager calls depositFunds with 0 as amount to move the epoch forward such that userA & B can claim their requests, this call succeeds as , totalUnlentbalance( 13500 + 2k) > totReservedWithdrawals ( 14k) + epochPending[2] ( 0 ). This calls sets epochPending[1] =0 , allowing manager to call stopEpoch.
Solidity
    if (getUnlentBalanceScaled() < totReservedWithdrawals - epochPending[_currEpoch]) {
      revert InsufficientBalance();
    }
    epochPending[_currEpoch - 1] = 0;
  1. Now userA & user B can withdraw their funds by calling claimRedeemRequest which takes amount directly from userWithdrawalsEpoch mapping. Returning User A's entire 10k $ & user B's 4k $, now only 1500 $ are left in queue, meaning 500$ loss was bore by user C, who was not even a LP when the loss occured.

Impact

  • Loss of funds for newer users.
  • Breaking of core functionality. ( when there is no new user C in 2nd epoch all the epoch related function will revert as depositFunds will revert due to the highlighted if condition, leaving epochPending[1] = 500 $ permanently & user A & B will not be able to withdraw funds)

PoC

The below POC is for impact 1 , i.e loss of funds for new user

Solidity
  function testBadDebt() external {
    // tests bad debt in system
    vm.label(address(sPar),"sUSP");
    vm.label(USDS,"USDS");
    vm.label(SUSDS,"sUSDS");
    vm.label(address(par),"USP");
    vm.label(address(queue),"queue");

    
    address user1 = makeAddr('user1');
    address user2 = makeAddr('user2');
    uint amount1 = 10000e18;
    uint amount2 = 5000e18;
    uint staked_amount = 1000e18;
    // 10% loss in yield source
    uint loss = 10e18; // i.e 1500 $ loss
    uint bad_debt = 500e18; // bad debt = total_loss - staked_amount

    _mintUSP(user1, USDS, amount1);
    _mintUSP(user2,USDS,amount2);

    //deposit into 4626 yield source
    uint shares = _deposit4626(SUSDS, amount1 + amount2);
    assertEq(par.balanceOf(user1), amount1);
    assertEq(par.balanceOf(user2), amount2);
    uint totals_before = queue.getTotalCollateralsScaled();
    // ~15000 total assets before
    emit log_named_decimal_uint("Totals before", totals_before,18);
    emit log_named_decimal_uint("shares before",shares,18);


    // assume user2 stakes 1000 $ in sPar
    vm.startPrank(user2);
    par.approve(address(sPar), staked_amount);
    sPar.deposit(staked_amount, user2);
    vm.stopPrank();

    // currently user2 is the only staker
    assertEq(sPar.totalSupply(),sPar.balanceOf(user2));

    // due to difficulty of simulating a bad debt in a Vault, we will just overwrite the share balance by loss_percentage
    // in simpler terms vault had a -ve apy & exchange rate to underlying token went down
    // previously if 1 vault share = 1 underlying, now 1 vault share = 0.90 underlying
    // here we simulated 10% -ve apy by directly decreasing share balance as manipulating exchange rate in this test suite is hard.
    uint shares_after = shares - ((shares * loss) / 100e18); 
    emit log_named_decimal_uint("shares_after", shares_after, 18);
    deal(SUSDS,address(queue),shares_after); // overwrite the share balance
    assertEq(IERC4626(SUSDS).balanceOf(address(queue)), shares_after);

    // now after loss, owner offsets the loss from sPAR, only 1000$ is offset here.
    vm.startPrank(TL_MULTISIG);
    sPar.emergencyWithdraw(address(par),staked_amount);
    par.emergencyBurn(staked_amount);
    vm.stopPrank();
    
    // now 500$ bad debt is still left
    //request for redemption after loss happens
    _requestRedeemUSP(user1, par.balanceOf(user1));
    _requestRedeemUSP(user2, par.balanceOf(user2));
    _stopEpoch(); // moves epoch forward to process withdrawals

    // a new unsuspecting user comes in this epoch
    address user3 = makeAddr('user3');
    uint amount3  = 2000e18; // deposits 2k
    _mintUSP(user3,USDS,amount3);

    // manager redeems
    _redeem4626(SUSDS, IERC4626(SUSDS).balanceOf(address(queue)), queue.epochNumber() -1 );


    assertApproxEqAbs(queue.epochPending(queue.epochNumber() -1), bad_debt,1);
    // starting new epoch reverts as epochPending for previous epoch is != 0 
    vm.expectRevert(abi.encodeWithSelector(IParetoDollarQueue.NotReady.selector));
    _stopEpoch();

    //manager calls deposit with 0, to reset pending
    // as unlent balance = 15000(initial deposit) - 1500(loss) + 2000 ( user C deposits)
    // unlent balance = 15500 > totalReservedWithdrawals (14k), 10k user A + 4k user B
    _deposit4626(SUSDS, 0);

    assertEq(queue.epochPending(queue.epochNumber() -1),0);

    // now user1 & 2 withdraw all their funds making user3 bear all the remaining losses
    vm.startPrank(user1);
    par.claimRedeemRequest(queue.epochNumber() -1);
    vm.stopPrank();

    vm.startPrank(user2);
    par.claimRedeemRequest(queue.epochNumber() -1);
    vm.stopPrank();

    // user1 walks away with all of their funds intact.
    assertEq(IERC20Metadata(USDS).balanceOf(user1),amount1);
    // user2 faces 1k in loss due to staking
    assertEq(IERC20Metadata(USDS).balanceOf(user2),amount2 - staked_amount);
    // but user3 faces the entirety of remaining 500 $ loss, which he should not have
    // as he was not even a depositer in the epoch where loss happened.
    assertEq(IERC20Metadata(USDS).balanceOf(address(queue)),1500e18);
    // as now queue only has 1500 $ he cant withdraw his 2k $
    emit log_named_decimal_uint("Totals after", queue.getTotalCollateralsScaled(),18);
    // the 500$ loss happens to user C
  }

& run using

Bash
FOUNDRY_PROFILE=lite forge test --match-test testBadDebt --force

Mitigation

Diff
-  function requestRedeem(address _receiver, uint256 _amount) external {
-    _requireNotPaused();
-    _onlyPar();
-    uint256 _epoch = epochNumber;
-    userWithdrawalsEpochs[_receiver][_epoch] += _amount;
-    epochPending[_epoch] += _amount;
-    totReservedWithdrawals += _amount;
-  }

+   function requestRedeem(address _receiver, uint256 _amount) external {
+    _requireNotPaused();
+    _onlyPar();
+    uint256 _epoch = epochNumber;

+    uint relative_amt =  ((_amount) * ((getTotalCollateralsScaled() * 1e18) /  (IERC20Metadata(address(par)).totalSupply() + _amount)) / 1e18 ); //@audit totalSupply() + _amount cause _amount has already been reduced by _burn in par

+    relative_amt = _amount > relative_amt ?relative_amt : _amount; //@audit take minimum of both as all the yield is going to sPar.

+    userWithdrawalsEpochs[_receiver][_epoch] += relative_amt;
+    epochPending[_epoch] += relative_amt;
+    totReservedWithdrawals += relative_amt;
+  }

The recommended mitigation sets userWithdrawalsEpochs mapping in accordance to how much underlying collateral does withdrawer's USP represent instead of directly assuming that his 1 USP represents 1 underlying collateral, which is only true in happy cases but fails when bad debt happens, as shown in POC. This mitigation works perfectly & passes all test suite except 2 cases where it fails due to dust amount mismatch due to additional multiplications & divisions it adds to entire flow.

Note that the test suite tries to emulate loss in testClaimRedeemRequest test in ParetoDollarQueue.t.sol but it simulates the loss after epochPending[1] =0 has been set by redeemFunds call & manually transfers out a token, but in real-world the exchange rate will do down due to -ve returns & epochPending[1] will not be set to 0.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/pareto-credit/USP/pull/8

The original report as published on Sherlock, by Atharv. 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

Likely the requestRedeem function assumes one USP always equals one unit of underlying collateral, so it records the full burn amount as a withdrawal claim even when the system's collateral is worth less due to losses.

Impact

Newer depositors can lose funds that should have been socialised among earlier investors, and if no new depositor arrives the epoch functions may revert permanently, blocking withdrawals.

What the attacker needed

A yield source suffers a loss; loss exceeds sUSP absorption; a new depositor joins in a later epoch

The fix

The requestRedeem function should record a withdrawal amount proportional to the user's share of total collateral rather than the full USP burn amount, and the protocol team fixed this issue.

How it was found

  1. Users A and B deposit collateral totalling 15k, which is put into a yield source.
  2. User B also stakes 1k USP in sUSP.
  3. The yield source suffers a 10% loss of 1500, and the owner offsets 1k by burning sUSP, leaving 500 bad debt.
  4. Both users request redemption of their entire balance, recording 10k for A and 4k for B.
  5. The manager moves the epoch forward and calls redeemFunds while a new user C deposits 2k in the same epoch.
  6. The manager calls depositFunds with zero to reset the pending amount, then users A and B claim their full amounts, leaving user C to bear the 500 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.

When you deposit money, the system gives you a token representing your share. If the investments lose value, the system should spread that loss among everyone who was invested at the time. Here, a flaw in how withdrawal requests are recorded meant that older users could withdraw their full original amount, leaving the loss to be paid by someone who joined later.

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 Atharv

View all

3 more disclosed reports, best first.

More from Pareto USP, a credit-backed synthetic dollar

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.