reward will be locked in the farm if no LP join the pool at epoch.startBlock
If no liquidity provider deposits at the exact start block of a farming epoch, a portion of the reward tokens remains locked in the contract because the reward calculation only counts from the first deposit block. An attacker cannot directly steal these tokens, but they become permanently stuck, reducing the rewards available to participants.
Submitted by TrungOre
LPFarming.sol#L214 LPFarming.sol#L107
A part of reward tokens will be locked in the farming pool if no user deposits lpToken at the epoch.startBlock.
Proof of Concept
it("a part of reward should be locked in farm if no LP join the pool at epoch.startBlock", async() => {
// manual mine new block
await network.provider.send("evm_setAutomine", [false]);
// prepare
await lpTokens[0].transfer(alice.address, units(1000));
await lpTokens[0].connect(alice).approve(farming.address, units(1000));
await mineBlocks(1);
// create new pool
await farming.add(10, lpTokens[0].address);
await mineBlocks(1);
expect(await farming.poolLength()).to.equal(1);
let pool = await farming.poolInfo(0);
expect(pool.lpToken).to.equal(lpTokens[0].address);
expect(pool.allocPoint).to.equal(10);
// create new epoch ==> balance of pool will be 1000
let blockNumber = await ethers.provider.getBlockNumber();
await farming.newEpoch(blockNumber + 1, blockNumber + 11, 100);
// skip the epoch.startBlock
// it mean no one deposit lpToken to farm at this block
await mineBlocks(1);
expect(await jpeg.balanceOf(farming.address)).to.equal(1000);
// alice deposit
await farming.connect(alice).deposit(0, units(100));
await mineBlocks(1);
// skip the blocks to the end of epoch
await mineBlocks(13);
await farming.connect(alice).claim(0);
await mineBlocks(1);
console.log("reward of alice: ", (await jpeg.balanceOf(alice.address)).toString());
console.log("reward remain: ", await jpeg.balanceOf(farming.address));
// 100 jpeg will be locked in the pool forevers
expect(await jpeg.balanceOf(alice.address)).to.equal(900);
expect(await jpeg.balanceOf(farming.address)).to.equal(100);
});
In the example above, I create an epoch from blockNumber + 1 to blockNumber + 11 with the reward for each block being 100JPEG. So, the total reward for this farm will be 1000JPEG. When I skip the epoch.startBlock and let Alice deposit 100 lpToken at the block right after, at the end of the farm (epoch.endBlock), the total reward of Alice is just 900JPEG, and 100JPEG still remains in the farming pool. Since there is no function for the admin (or users) to withdraw the remaining, 100JPEG will be stucked in the pool forever !!!
Tools Used
typescript
Recommended Mitigation Steps
Add a new function for the admin (or user) to claim all rewards which remained in the pool when epoch.endTime has passed
function claimRemainRewardsForOwner() external onlyOwner {
require(
block.number > epoch.endBlock,
'epoch has not ended'
);
uint256 remain = jpeg.balanceOf(address(this));
jpeg.safeTransfer(msg.sender, remain);
}
spaghettieth (JPEG’d) acknowledged, but disagreed with Medium severity and commented:
This is a very minor issue, severity should be 0.
I disagree with the sponsor. Funds are lost in this scenario and it is very easy to mitigate.
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 calculation only starts from the first deposit block, ignoring the epoch's start block, and there is no function to recover undistributed rewards.
Impact
A portion of reward tokens (100 out of 1000 in the example) becomes permanently locked in the contract, reducing the rewards distributed to users.
What the attacker needed
No deposit at epoch start block; reward tokens funded in contract
The fix
Add a function for the admin to claim remaining rewards after the epoch ends, as suggested in the report.
How it was found
- Create a new farming pool with a reward token.
- Start a new epoch with a defined start block and end block.
- Skip the epoch's start block without any deposit.
- Deposit liquidity after the start block.
- Wait until the epoch ends and claim rewards.
- Observe that some reward tokens remain locked in the contract.
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.
In a farming pool, users earn rewards over a set period called an epoch. The reward for each block is calculated, but if nobody joins at the very first block, that block's reward is never given out. Since there is no way to withdraw leftover tokens, they stay stuck in the contract forever.
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.