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.
- 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
- Report ID: #60210
- Report Type: Smart Contract
- Report severity: High
- Target: https://github.com/immunefi-team/audit-comp-vechain-stargate-hayabusa/tree/main/packages/contracts/contracts/Stargate.sol
- Impacts: Permanent freezing of funds
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
- A user requests to exit delegation validator X.
InrequestDelegationExitthe validator's effective stake for the next period is reduced:
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()
- 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_updatePeriodEffectiveStakeagain — 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():
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
Proof of Concept
<details> <summary>PoC test (paste into Rewards.test.ts and run)</summary>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)
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
- Stake tokens and delegate them to a validator.
- Advance the validator's completed periods.
- Request to exit the delegation.
- Set the validator status to EXITED.
- 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.