Skip to content
Business logic Audit finding Intermediate

Emergencywithdraw cost more penalty than expected

The emergency withdrawal penalty is calculated on the total amount withdrawn rather than only the locked portion, because the share removal function ignores each deposit's unlock status. An attacker could trigger a larger-than-expected penalty on their own funds by mixing locked and unlocked deposits.

ox9527 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

57485 sc medium emergencywithdraw cost more penalty than expected

Submitted on Oct 26th 2025 at 16:09:18 UTC by @ox9527 for Audit Comp | Belong

Description

Brief/Intro

The penalty cost in emergencyWithdraw / emergencyRedeem depends on the user’s withdrawal amount. Each deposit must individually wait for its own unlock period, and there is no method for a user to unlock already locked shares.

Assume the following scenario:

  • Bob deposits 5e18 for the first time.
  • After staking.minStakePeriod() + 1 time has passed, Bob deposits another 5e18.
  • At this point, the first 5e18 is already unlocked, while the second deposit remains locked.

When Bob performs emergencyWithdraw(10e18), the penalty is calculated based on the total withdrawal amount, resulting in a 1e18 penalty instead of the expected 0.5e18.

Vulnerability Details

The problematic function in Staking.sol:

{% code title="Staking.sol (excerpt)" %}

{% endcode %}

Solidity
function _removeAnySharesFor(address staker, uint256 shares) internal {
    Stake[] storage userStakes = stakes[staker];
    uint256 remaining = shares;

    for (uint256 i; i < userStakes.length && remaining > 0;) {
        uint256 stakeShares = userStakes[i].shares;
        if (stakeShares <= remaining) {
            remaining -= stakeShares;
            userStakes[i] = userStakes[userStakes.length - 1];
            userStakes.pop();
            // don't ++i: a new element is now at index i
        } else {
            userStakes[i].shares = stakeShares - remaining;
            remaining = 0;
            unchecked {
                ++i;
            }
        }
    }
}

This implementation does not consider whether individual stakes are unlocked or locked; it removes arbitrary shares across the user's stakes when withdrawing, which mixes locked and unlocked stakes and causes the penalty calculation for emergency withdraws to be based on the total withdrawal amount rather than only the locked portion.

Impact Details

{% hint style="warning" %} User funds can be permanently frozen or incur larger-than-expected penalties due to locked shares being incorrectly considered when removing shares for emergency withdrawals. {% endhint %}

Proof of Concept

<details> <summary>PoC Test (expand to view)</summary>

{% code title="tests/PoC.sol" %}

{% endcode %}

```solidity // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.13;

import {Test} from "forge-std/Test.sol"; import {Staking} from "../contracts/v2/periphery/Staking.sol"; import "node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "forge-std/console2.sol";

contract Long is ERC20 { constructor() ERC20("LONG Mock", "Long") { _mint(msg.sender, 1_000_000_000_000 * 10 ** decimals()); }

function mint(address to, uint256 amount) public {
    _mint(to, amount);
}

} contract StakingTest is Test {

Staking public staking;
Long public long;
function setUp() public {
    staking = new Staking();
    long = new Long();
    staking.initialize(address(this), address(this), address(long));

}

//PoC3. Emergency withdraw not consider the already unlocked assets.
//Assume user have 10e18 totaly assets , 5e18->locked,5e18->unlocked.
function test_POC_3() public {
    address alice = address(0x1001);
    address bob = address(0x1002);
    long.mint(alice,10e18);
    long.mint(bob,10e18);

    vm.startPrank(alice);
    long.approve(address(staking), 10e18);
    staking.deposit(10e18,alice);
    vm.stopPrank();

    vm.startPrank(bob);
    long.approve(address(staking), 10e18);
    staking.deposit(5e18,bob);
    vm.stopPrank();

    vm.warp(block.timestamp + staking.minStakePeriod() + 1);

    //bob stake another 5e18.
    vm.startPrank(bob);
    staking.deposit(5e18,bob);

    //bob withdraw.
    staking.emergencyWithdraw(10e18, bob, bob);

    //10e18 - 10e18 * 1% = 9e18.
    console2.log("bob get assets:",long.balanceOf(bob));
}

}

</details>

<details>
<summary>PoC Output (expand to view)</summary>

[PASS] test_POC_3() (gas: 395902) Logs: bob get assets: 9000000000000000000

Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 6.84ms (2.07ms CPU time)

Ran 1 test suite in 142.64ms (6.84ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)

</details>

## References

(Original target file) https://github.com/immunefi-team/audit-comp-belong/blob/main/contracts/v2/periphery/Staking.sol

--- 

Notes:
- The report highlights that stake removal doesn't respect per-deposit unlock state; thus emergency penalty calculations can be larger than intended when mixing locked and unlocked deposits.
- No remediation or code changes are proposed in the original report; this page preserves the original content as submitted.
</details>

The original report as published on Immunefi, by ox9527. 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 share removal function removes shares without checking whether each individual stake is locked or unlocked, so the penalty is applied to the total withdrawal amount instead of only the locked shares.

Impact

Users could incur larger-than-expected penalties, and funds may be permanently frozen due to locked shares being incorrectly considered during emergency withdrawals.

What the attacker needed

A staking account; multiple deposits with different lock states; calling emergencyWithdraw

How it was found

  1. Bob deposits 5e18 for the first time.
  2. After the minimum stake period plus one second, Bob deposits another 5e18.
  3. Bob calls emergencyWithdraw for 10e18.
  4. The penalty is calculated on the full 10e18, resulting in a 1e18 penalty instead of 0.5e18.

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.

When you deposit money into a staking contract, each deposit has its own lock-up period. If you withdraw early, you pay a penalty. This report shows that the contract charges the penalty on the whole withdrawal amount, even the part that was already unlocked, so you can lose more money than you should.

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 ox9527

View all

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