Sudden addition of rewards will be frontrun with deposits just to steal part of reward
The staking contract adds rewards instantly, increasing the value of all shares at once. An attacker can deposit just before a reward distribution and withdraw after the lock period to capture part of the reward meant for long-term stakers.
- Disclosed after under an hour
56841 sc high sudden addition of rewards will be frontrun with deposits just to steal part of reward
Submitted on Oct 21st 2025 at 06:49:04 UTC by @kaysoft for Audit Comp | Belong
- Report ID: #56841
- Report Type: Smart Contract
- Report severity: High
- Target: https://github.com/belongnet/checkin-contracts/blob/main/contracts/v2/periphery/Staking.sol
- Impacts:
- Theft of unclaimed yield
Description
Brief / Intro
Sudden addition of reward token to the Staking.sol will be frontrun with deposits by adversaries just to steal part of the reward and exit after lock duration.
Vulnerability Details
The distributeRewards(...) function adds reward LONG amount to increase the value of user shares at an instant. This invites opportunists that wait until the owner is about to distribute rewards, then frontrun distributeRewards(...) with a deposit to obtain shares that immediately become worth more LONG tokens.
After the lock duration the malicious users withdraw their assets plus part of the added reward. Their aim is not to stake as expected by the protocol but to steal part of the rewards that are meant for long-term stakers.
Relevant snippet from Staking.sol:
File: Staking.sol
/// @notice Adds rewards to the vault, increasing the asset backing per share.
/// @dev Caller must approve this contract to pull `amount` LONG beforehand.
/// @param amount Amount of LONG to transfer in as rewards (must be > 0).
function distributeRewards(uint256 amount) external onlyOwner {
if (amount == 0) revert ZeroReward();
LONG.safeTransferFrom(msg.sender, address(this), amount);
emit RewardsDistributed(amount);
}
Impact Details
Attackers can frontrun distributeRewards(...) by depositing immediately before a reward distribution, then withdraw after the lock period to capture a portion of the newly added reward, effectively stealing from long-term stakers.
Recommendation
Consider implementing time-based reward emission (e.g., Synthetix-style reward emission) so users are rewarded based on the duration of staking LONG tokens rather than instantaneous balance increases.
Proof of Concept
{% stepper %} {% step %}
Test setup and transfers
Copy and paste the test below into the staking.tests.ts test file in the 'Rewards distribution (rebase)' test suite and run the test.
This scenario demonstrates user2 frontrunning distributeRewards to steal part of the distributed rewards.
Initial transfers:
- user1 and user2 both receive 1000 LONG from admin. {% endstep %}
{% step %}
Staking and frontrun
User1 deposits earlier (start of staking period). Later, just before admin distributes rewards, user2 frontruns the admin by depositing as well. Then admin calls distributeRewards.
{% endstep %}
{% step %}
Withdrawal and result
After shortening the min stake period for the test, user2 redeems immediately after the timelock and is able to withdraw a portion of the distributed reward that should have been for earlier stakers. {% endstep %} {% endstepper %}
Test code:
{% code title="staking.tests.ts" %}
it('Frontruns distributeRewards (with deposit) to steal rewards', async () => {
const { staking, long, admin, user1, user2 } = await loadFixture(fixture);
const depositAmt = ethers.utils.parseEther('1000');
const reward = ethers.utils.parseEther('250');
await long.connect(admin).transfer(user1.address, depositAmt);
await long.connect(admin).transfer(user2.address, depositAmt);
//1. User1 deposits earlier as the start of the staking period
await long.connect(user1).approve(staking.address, depositAmt);
await staking.connect(user1).deposit(depositAmt, user1.address);
//2. After 2 months when other other users have stake their long token in good faith
//Then admin is about to reward users
// User2 frontruns admin's distributeRewards just to steal part of the rewards
await long.connect(user2).approve(staking.address, depositAmt);
await staking.connect(user1).deposit(depositAmt, user1.address);
//3. Admin distributeRewards is executed just after user2's deposit
await long.connect(admin).approve(staking.address, reward);
await staking.connect(admin).distributeRewards(reward);
await staking.connect(admin).setMinStakePeriod(1);
//4. user1 and user2 have same amount of shares
const shares = await staking.balanceOf(user2.address);
const expectedAssets = await staking.previewRedeem(shares);
//5. user2 withdraws immediately after timelock while
// user1 keeps their long staked in the contract
const tx = await staking.connect(user2).redeem(shares, user2.address, user2.address);
expect(await long.balanceOf(user2.address)).to.eq(expectedAssets);
//6. User2 is able to take half of the distributed reward and exits
expect(expectedAssets).to.approximately(depositAmt.add(reward.div(2)), 1);
});
{% endcode %}
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 distribution increases the value of all existing shares instantly, without weighting rewards by how long each user has staked.
Impact
An attacker could steal a portion of newly distributed rewards from long-term stakers by frontrunning the reward distribution with a deposit and withdrawing after the lock period.
What the attacker needed
Attacker has LONG tokens to deposit; attacker can frontrun the reward transaction; minimum stake period is short enough
The fix
Rewards should be emitted over time based on staking duration, for example using a Synthetix-style emission schedule, rather than increasing share value instantly.
How it was found
- User1 deposits LONG tokens early in the staking period.
- User2 deposits LONG tokens just before the admin calls distributeRewards.
- Admin calls distributeRewards, adding reward tokens to the contract.
- Admin shortens the minimum stake period for the test.
- User2 redeems their shares immediately after the timelock and receives part of the reward.
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 staking contract lets people put in tokens and get shares. When the owner adds rewards, every share becomes worth more straight away. Someone can put in tokens just before the reward is added, wait the minimum time, then take out their tokens plus a slice of the reward, even though they did not stake for long.
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.