Skip to content
Business logic Audit finding Intermediate

Penallty can be bypassed in Staking.sol::_emergencyWithdraw

The emergency withdrawal function in the staking contract applies a penalty, but the reporter claims a user can avoid it by withdrawing many small amounts instead of one large amount. This would let an attacker keep funds that should have gone to the treasury as a penalty.

Bx4 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

57917 sc medium penallty can be bypassed in staking sol emergencywithdraw

Submitted on Oct 29th 2025 at 13:03:25 UTC by @Bx4 for Audit Comp | Belong

Description

Brief/Intro

When a user invokes an emergency withdrawal they can bypass fees by withdrawing small amounts continuously.

Vulnerability Details

In Staking.sol there is an internal function called _emergencyWithdraw which external functions such as emergencyRedeem and emergencyWithdraw call to make instant withdrawals. Emergency withdrawals attract a penalty. However, attackers can bypass this penalty by repeatedly withdrawing small amounts until they reach the desired total, avoiding the intended penalty on the full amount.

Example: If penalty is set to 1000 BPS (10%), an attacker can withdraw 10 assets 100 times to obtain 1000 assets while skipping the 10% penalty that would apply if withdrawing 1000 at once.

Impact Details

The contract fails to retain or forward the intended penalty amount when an emergency withdrawal is invoked repeatedly by an attacker.

References

Proof of Concept

{% stepper %} {% step %}

Modify test amount

Edit the test in staking.ts and change the withdrawn amount to 10 (instead of 1000). {% endstep %}

{% step %}

Observe penalty behavior

Run the test and observe that after execution the penalty equals 0, demonstrating the penalty bypass when withdrawing small amounts repeatedly. {% endstep %} {% endstepper %}

Code excerpt of the test for context:

{% code title="staking.ts (excerpt)" %}

{% endcode %}

```solidity it('emergencyWithdraw()', async () => { const { staking, long, treasury, admin, user1 } = await loadFixture(fixture);

  const amount = ethers.utils.parseEther('1000');

  await long.connect(admin).transfer(user1.address, amount);
  await long.connect(user1).approve(staking.address, amount);

  await staking.connect(user1).deposit(amount, user1.address);

  await expect(
    staking.connect(user1).emergencyWithdraw(amount.add(1), user1.address, user1.address),
  ).to.be.revertedWithCustomError(staking, 'WithdrawMoreThanMax');

  const tx = await staking.connect(user1).emergencyWithdraw(amount, user1.address, user1.address);

  const penalty = getPercentage(amount, await staking.penaltyPercentage());
  const payout = amount.sub(penalty);

  await expect(tx)
    .to.emit(staking, 'EmergencyWithdraw')
    .withArgs(user1.address, user1.address, user1.address, amount, amount);
  await expect(tx)
    .to.emit(staking, 'Withdraw')
    .withArgs(user1.address, user1.address, user1.address, amount, amount);
  expect(await staking.balanceOf(user1.address)).to.eq(0);
  expect(await long.balanceOf(staking.address)).to.eq(0);
  expect(await long.balanceOf(treasury.address)).to.eq(penalty);
  expect(await long.balanceOf(user1.address)).to.eq(payout);
  await expect(staking.stakes(user1.address, 0)).to.be.reverted;
});

The original report as published on Immunefi, by Bx4. 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 penalty is computed per withdrawal with integer maths that rounds down to zero for small amounts, so splitting a withdrawal avoids the fee.

Impact

The contract may fail to collect the intended penalty, so the treasury loses funds it should have received, though the report gives no working end-to-end exploit.

What the attacker needed

A staked position in the contract; ability to make many small withdrawals

How it was found

  1. Change the withdrawn amount in the staking test to a small value such as 10 instead of 1000.
  2. Run the test and check the penalty value after the emergency withdrawal.

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 lock tokens and take them out early, but charges a fee (a penalty) for leaving early. The report says that if you take out a tiny amount at a time, the fee ends up being zero, so you keep money that should have gone to the project. The claim is that the fee is calculated in a way that rounds down to nothing on small withdrawals.

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 Bx4

View all

4 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.