Skip to content
Smart contracts Audit finding Intermediate

During a validator EXIT, users will be unable to unstake due to underflow

The unstake function deducts a validator's effective stake a second time when the validator has already exited, after the same deduction was made when the user requested to leave. This underflow reverts the unstake call, permanently locking the user's staked VET tokens.

oxrex Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

60210 sc high during a validator exit users will be unable to unstake due to underflow

Submitted on Nov 20th 2025 at 00:08:26 UTC by @oxrex for Audit Comp | Vechain | Stargate Hayabusa

Description

Brief / Intro

During a validator EXIT, users will be unable to unstake due to an underflow issue inside the unstake() function.

Vulnerability Details

The unstaking process in the current implementation of Vechain staking is implemented in two main user actions:

{% stepper %} {% step %}

User requests delegation exit

  1. A user requests to exit delegation validator X.
    In requestDelegationExit the validator's effective stake for the next period is reduced:
Solidity
function requestDelegationExit(
        uint256 _tokenId
    ) external whenNotPaused onlyTokenOwner(_tokenId) nonReentrant {
    ...

    // decrease the effective stake
    _updatePeriodEffectiveStake($, delegation.validator, _tokenId, completedPeriods + 2, false);

    emit DelegationExitRequested(_tokenId, delegation.validator, delegationId, exitBlock);
}

{% endstep %}

{% step %}

User calls unstake()

  1. The user then calls unstake() to get their staked VET tokens back and claim earned rewards. {% endstep %} {% endstepper %}

If the validator has not been exited before the user calls unstake(), the user receives their VET back as expected.

However, a problematic sequence creates an underflow:

{% stepper %} {% step %}

Problematic sequence — part 1

  • User requests exit from validator X (reducing the validator effective stake for the upcoming period). {% endstep %}

{% step %}

Problematic sequence — part 2

  • Validator X is exited (validator becomes status EXITED). {% endstep %}

{% step %}

Problematic sequence — part 3

  • User calls unstake(). Because the validator status is EXITED, unstake() attempts to call _updatePeriodEffectiveStake again — even though the effective stake was already reduced when the user requested exit. {% endstep %} {% endstepper %}

This double deduction creates two failure modes:

  • If the user is the sole delegator to that validator, the second deduction causes an underflow, permanently locking the user's tokens.
  • If there are multiple delegators, the second deduction corrupts the validator's effective stake and will cause other delegators' future unstake calls to underflow as well, propagating the issue.

Relevant excerpt from unstake():

Solidity
function unstake(
        uint256 _tokenId
    ) external whenNotPaused onlyTokenOwner(_tokenId) nonReentrant {
    ...
    // if the delegation is pending or the validator is exited or unknown
    // decrease the effective stake of the previous validator
    if (
        currentValidatorStatus == VALIDATOR_STATUS_EXITED ||
        delegation.status == DelegationStatus.PENDING
    ) {
        // get the completed periods of the previous validator
        (, , , uint32 oldCompletedPeriods) = $
            .protocolStakerContract
            .getValidationPeriodDetails(delegation.validator);

        // decrease the effective stake of the previous validator
        _updatePeriodEffectiveStake(
            $,
            delegation.validator,
            _tokenId,
            oldCompletedPeriods + 2,
            false // decrease
        );
    }
    ...
}

The PoC attached with this report demonstrates the bug. The fix is to avoid decreasing effective stake twice for the same delegation/validator (i.e., ensure _updatePeriodEffectiveStake isn't called redundantly when the exit was already processed in requestDelegationExit).

Impact Details

{% hint style="danger" %} Complete lock of the user's VET tokens (the token.vetAmountStaked associated with the NFT). The only contract function that sends out those VET tokens is unstake(), so this underflow can permanently prevent users from reclaiming funds. {% endhint %}

References

https://github.com/immunefi-team/audit-comp-vechain-stargate-hayabusa/blob/main/packages/contracts/contracts/Stargate.sol#L276-L283

Proof of Concept

<details> <summary>PoC test (paste into Rewards.test.ts and run)</summary>
JavaScript
it.only("poc for locked stake:", async () => {
        const levelSpec = await stargateNFTMock.getLevel(LEVEL_ID);
        tx = await stargateContract.connect(user).stake(LEVEL_ID, {
            value: levelSpec.vetAmountRequiredToStake,
        });
        await tx.wait();
        const tokenId = await stargateNFTMock.getCurrentTokenId();
        log("\n🎉 Staked token with id:", tokenId);

        tx = await stargateContract.connect(user).delegate(tokenId, validator.address);
        await tx.wait();
        log("\n🎉 Delegated token to validator", validator.address);

        // fast forward some periods
        tx = await protocolStakerMock.helper__setValidationCompletedPeriods(validator.address, 5); //
        await tx.wait();
        log("\n🎉 Set validator completed periods to 5");
        // request to exit the delegation
        tx = await stargateContract.connect(user).requestDelegationExit(tokenId);
        await tx.wait();
        log("\n🎉 Requested to exit the delegation");

        // validator exits
        tx = await protocolStakerMock.helper__setValidatorStatus(
            validator.address,
            VALIDATOR_STATUS_EXITED
        );
        await tx.wait();

        tx1 = await stargateContract.connect(user).unstake(tokenId);
        await tx1.wait();
    });

Expected revert seen when underflow occurs:

Error: VM Exception while processing transaction: reverted with panic code 0x11 (Arithmetic operation overflowed outside of an unchecked block)
at Stargate._updatePeriodEffectiveStake (contracts/Stargate.sol:1039)
at Stargate.unstake (contracts/Stargate.sol:285)
</details>

The original report as published on Immunefi, by oxrex. 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 unstake function calls _updatePeriodEffectiveStake again for a validator that was already reduced during requestDelegationExit, causing a double deduction.

Impact

The user's staked VET tokens are permanently locked because unstake is the only function that releases them, and with multiple delegators the corrupted stake can also break other users' unstake calls.

What the attacker needed

A staked and delegated token; validator reaches EXITED status; user has requested delegation exit

The fix

The contract should avoid decreasing the effective stake twice for the same delegation, for example by not calling _updatePeriodEffectiveStake in unstake when the exit was already processed in requestDelegationExit.

How it was found

  1. Stake tokens and delegate them to a validator.
  2. Advance the validator's completed periods.
  3. Request to exit the delegation.
  4. Set the validator status to EXITED.
  5. Call unstake, which reverts with an arithmetic underflow.

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 stake tokens through this contract, you first ask to leave a validator and later call unstake to get your tokens back. The contract subtracts your stake from the validator's total twice in that sequence, and the second subtraction goes below zero, which makes the transaction fail. Because unstake is the only way to retrieve the tokens, they stay stuck.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by oxrex

View all

13 more disclosed reports, best first.

More from Vechain | Stargate Hayabusa

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.