Skip to content
Business logic Audit finding Beginner

Unstake function does not unstake all as mentioned in the natspec

The unstake function's NatSpec says that passing an amount of zero should unstake all funds, but the implementation reverts when the amount is zero. A user following the documentation would have their transaction fail instead of withdrawing their full stake.

holydevoti0n Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

49919 sc insight unstake function does not unstake all as mentioned in the natspec

Submitted on Jul 20th 2025 at 15:04:14 UTC by @holydevoti0n for Attackathon | Plume Network

Description

Summary

The unstake function in StakingFacet.sol contradicts its NatSpec documentation regarding zero-amount behavior. The NatSpec states that passing amount = 0 should unstake all funds, but the implementation reverts when amount == 0, preventing users from unstaking their complete stake through the documented method.

Vulnerability Details

The NatSpec explicitly documents that passing 0 as the amount parameter should trigger an "unstake all" behavior. However, both the public function and the internal implementation revert when amount == 0.

Snippet from the repository (link preserved): https://github.com/immunefi-team/attackathon-plume-network/blob/580cc6d61b08a728bd98f11b9a2140b84f41c802/plume/src/facets/StakingFacet.sol#L371-L373

Solidity
   function unstake(uint16 validatorId, uint256 amount) external returns (uint256 amountUnstaked) {
@>        if (amount == 0) {
@>            revert InvalidAmount(0);
@>        }
        return _unstake(validatorId, amount);
    }
    
    
    /**
     * @notice Internal logic for unstaking, handles moving stake to cooling or parked.
     * @param validatorId ID of the validator to unstake from.
@>     * @param amount The amount of PLUME to unstake. If 0, unstakes all.
     * @return amountToUnstake The actual amount that was unstaked.
     */
    function _unstake(uint16 validatorId, uint256 amount) internal returns (uint256 amountToUnstake) {
        ...
        // Validate unstaking conditions
        _validateValidatorForUnstaking(validatorId);
@>        if (amount == 0) {
@>            revert InvalidAmount(amount);
@>        }
        ...
     }

Impact

Users cannot unstake their complete stake using the documented zero-amount method, because the function reverts with InvalidAmount(0) instead of unstaking all the user's funds.

{% hint style="warning" %} Behavior mismatch between documentation and implementation can lead to user confusion and failed transactions when callers expect the documented "unstake all" shortcut. {% endhint %}

Recommendation

Either:

  • Update the implementation so that when amount == 0 the function unstakes the user's full stake (implement the "unstake all" behavior), or
  • Update the NatSpec documentation to reflect that passing 0 is invalid and will revert.

Proof of Concept

{% stepper %} {% step %}

  1. User calls:
JavaScript
unstake(validatorId, 0)

{% endstep %}

{% step %} 2. Expected behavior: function unstakes all user's funds from the validator and the transaction succeeds. {% endstep %}

{% step %} 3. Actual behavior: transaction reverts with InvalidAmount(0). {% endstep %} {% endstepper %}

The original report as published on Immunefi, by holydevoti0n. 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 a mismatch between the documented zero-amount shortcut and the input validation, which rejects zero in both the external and internal unstake functions.

Impact

Users cannot unstake their complete stake using the documented zero-amount method, and callers expecting that shortcut see failed transactions.

What the attacker needed

A staked position on a validator

The fix

Either the implementation should treat a zero amount as a request to unstake the full stake, or the NatSpec should state that zero is invalid and will revert.

How it was found

  1. A user calls unstake with a validator id and an amount of zero.
  2. The expected result is that all of the user's stake is withdrawn and the transaction succeeds.
  3. The actual result is that the transaction reverts with an invalid amount error.

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 later take them back. Its documentation promised a shortcut: ask to unstake zero and the contract would return everything. In reality the contract rejects a zero amount, so anyone using that shortcut gets an error and their tokens stay locked until they try a different amount.

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 holydevoti0n

View all

28 more disclosed reports, best first.

More from Plume Network

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.