Skip to content
Business logic Audit finding Beginner

Incorrectly returned values and emitted data on staking emergency functionality

The emergency withdrawal and redeem functions in a staking contract return and emit the pre-penalty asset or share amount rather than the actual payout after the penalty is deducted. An attacker cannot gain funds, but callers and indexers relying on the return value or events receive incorrect information about how much was withdrawn.

blackgrease Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

57348 sc insight incorrectly returned values and emitted data on staking emergency functionality

Submitted on Oct 25th 2025 at 12:16:31 UTC by @blackgrease for Audit Comp | Belong

Description

Affected Files: Staking.sol

The Staking contract has emergency withdrawal functions — emergencyWithdraw and emergencyRedeem — that allow a user to bypass the minimum staking period in order to remove their locked stakes.

However, the returned value in the emergencyWithdraw and emergencyRedeem functions is incorrect because it misrepresents the amount of assets/shares actually withdrawn/redeemed. The returned value does not factor in the penalty fee that is charged to users on locked tokens.

Scenario:

{% stepper %} {% step %}

Scenario example

  1. User stakes 1000 LONG while the minimum staking period is 5 days.
  2. They initiate an emergency withdrawal of the full amount. The penalty is 10% meaning they will receive only 900 LONG.
  3. emergencyWithdraw and emergencyRedeem incorrectly return that the user has received 1000 LONG while in practice they have been transferred 900 LONG. {% endstep %} {% endstepper %}

Furthermore, this incorrect data is emitted in the related events — EmergencyWithdraw and Withdraw — propagating the misrepresented data.

Note: The natspec includes a note: "// @return assets /shares Assets calculated from shares/assets before penalty." In practice, returning the actual payout after penalty would be more beneficial for users and for indexers/analytics.

This is a logic issue where an external function meant to return a value does not return the correct thing. Importantly, users are transferred the correct amount of tokens; no value is lost.

The problematic code

Below are the relevant functions highlighting where the issue exists:

Solidity
function emergencyWithdraw(uint256 assets, address to, address _owner) external returns (uint256 shares) { //@audit-issue: incorrect value returned
    if (assets > maxWithdraw(_owner)) revert WithdrawMoreThanMax(); 
    shares = previewWithdraw(assets); //@audit-issue: this does not factor in the penalty
    _emergencyWithdraw(msg.sender, to, _owner, assets, shares);
}

function emergencyRedeem(uint256 shares, address to, address _owner) external returns (uint256 assets) {//@audit-issue: incorrect value returned
    if (shares > maxRedeem(_owner)) revert RedeemMoreThanMax();
    assets = previewRedeem(shares); //@audit-issue: this does not factor in the penalty
    _emergencyWithdraw(msg.sender, to, _owner, assets, shares);
}

function _emergencyWithdraw(address by, address to, address _owner, uint256 assets, uint256 shares) internal {
    require(shares > 0, SharesEqZero());

    uint256 penalty = FixedPointMathLib.fullMulDiv(assets, penaltyPercentage, SCALING_FACTOR);
    uint256 payout;
    unchecked {
        payout = assets - penalty; //@audit-issue: this is the correct value that should be returned to the external functions
    }

    if (by != _owner) _spendAllowance(_owner, by, shares);

    _removeAnySharesFor(_owner, shares);
    _burn(_owner, shares);

    LONG.safeTransfer(to, payout);
    LONG.safeTransfer(treasury, penalty);

    emit EmergencyWithdraw(by, to, _owner, assets, shares); //@audit-issue: emits the wrong data. Should emit payout for both assets and shares (as they share the same decimals) -> incorrect information
    
    // also emit standard ERC4626 Withdraw for indexers/analytics
    emit Withdraw(by, to, _owner, assets, shares);
}

Impact

This is a low impact issue because the external functions emergencyWithdraw and emergencyRedeem do not return the correct values, and the returned value is only provided to callers (it is not consumed internally). However, indexers and analytics that rely on returned values or emitted events will see incorrect data, misrepresenting the actual payout amounts. The user receives the correct token amount; no funds are lost.

Mitigation

Suggested fix: return the actual payout (after penalty) from the external functions and from the internal _emergencyWithdraw, and emit the correct values in EmergencyWithdraw.

A tested fix (applies small API change: the external functions return payout instead of pre-penalty assets/shares):

Diff
//Fix in `emergencyWithdraw` function
-    function emergencyWithdraw(uint256 assets, address to, address _owner) external returns (uint256 shares) { //@audit-issue: incorrect value returned
+    function emergencyWithdraw(uint256 assets, address to, address _owner) external returns (uint256 payout) { //@audit-fix
   
        if (assets > maxWithdraw(_owner)) revert WithdrawMoreThanMax(); 
-        shares = previewWithdraw(assets); //@audit-issue: this does not factor in the penalty
+        uint256 shares = previewWithdraw(assets); //@audit-fix
-        _emergencyWithdraw(msg.sender, to, _owner, assets, shares);
+        payout = _emergencyWithdraw(msg.sender, to, _owner, assets, shares); //@audit-fix
    }


//Fix in `emergencyRedeem` function
-    function emergencyRedeem(uint256 shares, address to, address _owner) external returns (uint256 assets) {//@audit-issue: incorrect value returned
+    function emergencyRedeem(uint256 shares, address to, address _owner) external returns (uint256 payout) {//@audit-fix
   
        if (shares > maxRedeem(_owner)) revert RedeemMoreThanMax();
-        assets = previewRedeem(shares); //@audit-issue: this does not factor in the penalty
+        uint256 assets = previewRedeem(shares);
-        _emergencyWithdraw(msg.sender, to, _owner, assets, shares);
+        payout = _emergencyWithdraw(msg.sender, to, _owner, assets, shares);
    }


//Fix in the internal `_emergencyWithdraw` function
+    function _emergencyWithdraw(address by, address to, address _owner, uint256 assets, uint256 shares) internal returns(uint256 payout){
        require(shares > 0, SharesEqZero());

        uint256 penalty = FixedPointMathLib.fullMulDiv(assets, penaltyPercentage, SCALING_FACTOR);
        // uint256 payout;
        unchecked {
            payout = assets - penalty; 
        }

        if (by != _owner) _spendAllowance(_owner, by, shares); //@audit-info: protects against other users stealing funds

        _removeAnySharesFor(_owner, shares);
        _burn(_owner, shares);

        LONG.safeTransfer(to, payout);
        LONG.safeTransfer(treasury, penalty);

-        emit EmergencyWithdraw(by, to, _owner, assets, shares);
+        emit EmergencyWithdraw(by, to, _owner, payout, payout); //@audit:fix
        // also emit standard ERC4626 Withdraw for indexers/analytics
        emit Withdraw(by, to, _owner, assets, shares); //@audit-note: this can remain the same or remove or change data as it may be conflicting with an actual withdraw operation where there are no penalties
    }

Link to Proof of Concept

https://gist.github.com/blackgrease/fe2ecf8ec4a0e9793ea829dfd9247648

Proof of Concept

A Foundry PoC outlines the incorrect data returned and emitted and what data should be returned. It demonstrates that the returned value does not correctly represent the assets that the user receives.

  • Run with: forge test --mt testWrongDataReturnedAndEmittedOnEmergencyWithdraw -vvv --via-ir

Logs from the PoC:

[PASS] testWrongDataReturnedAndEmittedOnEmergencyWithdraw() (gas: 222213)
Logs:
  --PoC incorrectly emitted and returned data---
  Amount of shares/assets the withdrawal is SUPPOSED to return:  900000000000000000000
  Amount of shares/assets that is incorrectly returned:  1000000000000000000000
  Amount of shares/assets that are incorrectly emitted in `EmergencyWithdraw`/`Withdraw` events:  1000000000000000000000
  Note: user does not loose any value as they correctly receive the right amount

Foundry setup (how the author ran the PoC):

{% stepper %} {% step %}

1. Clone the repo

git clone https://github.com/belongnet/checkin-contracts.git {% endstep %}

{% step %}

2. Install Foundry dependencies

  1. forge install OpenZeppelin/[email protected] --no-commit
  2. forge install OpenZeppelin/[email protected] --no-commit
  3. npm install solady --force {% endstep %}

{% step %}

3. Update remappings in foundry.toml

Replace previous remappings (commented out in the PoC) with:

TOML
remappings = ["@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts","@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts"]

{% endstep %} {% endstepper %}

The original report as published on Immunefi, by blackgrease. 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 external functions return the pre-penalty preview value and the internal function emits the pre-penalty assets and shares instead of the computed payout.

Impact

This is a low impact logic issue: users receive the correct token amount and no funds are lost, but callers and indexers/analytics relying on the return values or emitted events see incorrect payout data.

What the attacker needed

A staking position with a minimum lock period; emergency withdrawal before the lock ends

The fix

The functions should return the actual payout after penalty and emit the correct values in the EmergencyWithdraw event.

How it was found

  1. Stake 1000 LONG with a 5 day minimum staking period.
  2. Initiate an emergency withdrawal of the full amount with a 10% penalty.
  3. Observe that the function returns 1000 LONG and the event emits 1000 LONG, while only 900 LONG is transferred.

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 for a minimum period. If they take them out early, a penalty fee is kept, so they receive less than they asked for. The functions that perform this early exit tell the caller the full amount instead of the reduced amount, and the event log records the same wrong figure, which can confuse dashboards and tools that read those values.

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 blackgrease

View all

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