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.
Originally disclosed on Immunefi
- 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
- Report ID: #49919
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/immunefi-team/attackathon-plume-network/blob/main/plume/src/facets/StakingFacet.sol
- Impacts: Users cannot unstake all funds using the documented zero-amount method.
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
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 == 0the function unstakes the user's full stake (implement the "unstake all" behavior), or - Update the NatSpec documentation to reflect that passing
0is invalid and will revert.
Proof of Concept
{% stepper %} {% step %}
- User calls:
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 %}
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
- A user calls unstake with a validator id and an amount of zero.
- The expected result is that all of the user's stake is withdrawn and the transaction succeeds.
- 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.