Skip to content
Business logic Audit finding Intermediate

Double subtraction of validator effective stake will permanently lock other delegators’ staked VET

A validator's aggregated delegators' effective stake is subtracted twice for the same delegation when a user requests a delegation exit and then unstakes after the validator has exited. This drives the per-validator total to zero, so other delegators' unstake calls revert with an arithmetic underflow and their staked funds are permanently locked.

xKeywordx Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

59802 sc high double subtraction of validator effective stake will permanently lock other delegators staked vet

Submitted on Nov 16th 2025 at 00:10:54 UTC by @xKeywordx for Audit Comp | Vechain | Stargate Hayabusa

Description

The Stargate contract maintains a per-validator checkpointed value of delegators’ effective stake in this mapping:

Solidity
mapping(address validator => Checkpoints.Trace224 amount) delegatorsEffectiveStake;

This is updated via _updatePeriodEffectiveStake whenever delegations are added, moved, exited, or unstaked.

There is a sequence of interaction between the Stargate::requestDelegationExit, Stargate::unstake and Stargate::getDelegationStatus functions, which can cause the delegatorsEffectiveStake of a validator to be subtracted twice, corrupting the delegatorsEffectiveStake accounting and leading to a permanent freezing of funds.

The following stepper explains how the bug can occur:

{% stepper %} {% step %}

Step

We have two users, Alice and Bob. Both of them staked and have some valid Stargate NFTs. Assume Alice and Bob staked the same amounts for simplicity (50 tokens each). {% endstep %}

{% step %}

Step

They both delegate their stakes to the same validator. The validator's delegatorsEffectiveStake = 100 right now. {% endstep %}

{% step %}

Step

While the validator is active Bob wants to exit, so he calls requestDelegationExit, which updates the delegatorsEffectiveStake mapping for the validator. Bob's amount will be subtracted from the total because he's exiting, so the delegatorsEffectiveStake of the validator will be 50 now. {% endstep %}

{% step %}

Step

The validator exits. This enables the bug. {% endstep %}

{% step %}

Step

Bob calls unstake. Because the validator exited in the meantime, unstake will reduce the validator's delegatorsEffectiveStake again. This is wrong because Bob's amount was already subtracted when he called requestDelegationExit. Excerpt from the code:

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
        );
    }
    // ..
}

{% endstep %}

{% step %}

Step

Bob will successfully exit, because the validator had an extra 50 tokens from Alice, but Alice's funds will be permanently locked. {% endstep %} {% endstepper %}

Root cause

Double subtraction of delegators’ effective stake for the same delegation, combined with a global (per-validator) aggregation.

{% stepper %} {% step %}

Issue

requestDelegationExit already removes the token’s effective stake from the delegatorsEffectiveStake[validator] mapping via:

Solidity
_updatePeriodEffectiveStake($, validator, tokenId, completedPeriods + 2, false);

{% endstep %}

{% step %}

Issue

If the validator exits before the user gets to unstake, but after they have already requested an exit, unstake will again call:

Solidity
if (currentValidatorStatus == VALIDATOR_STATUS_EXITED || delegation.status == DelegationStatus.PENDING) {
    //..
    _updatePeriodEffectiveStake($, validator, tokenId, oldCompletedPeriods + 2, false);
}

This will remove the same amount twice, although it was already fully removed at the first call. {% endstep %}

{% step %}

Issue

Because delegatorsEffectiveStake is a global variable stored per validator, the second subtraction is taken out of the aggregated sum, which may now consist only of other delegators’ stake. {% endstep %} {% endstepper %}

Impact

Critical – Permanent freezing of funds

At some point, when other delegators later attempt to unstake, _updatePeriodEffectiveStake(..., false) runs with currentValue == 0 and effectiveStake > 0, causing a checked arithmetic underflow and revert.

In other words, a user with a staked NFT will reach a state where they have a valid delegation that should be exited, but any call to unstake(...) reverts with a panic 0x11, because delegatorsEffectiveStake[validator] has been driven to 0 by other delegators’ double subtraction.

Recommended mitigation

Ensure that each delegation’s effective stake is added and removed exactly once.

Proof of Concept

Add this test in the following file Stake.test.ts and run it:

JavaScript
it.only("should prove double subtraction error", async () => {
    // create a second user (Alice == user1 & Bob == user2)
    const levelSpec = await stargateNFTMockContract.getLevel(LEVEL_ID);
    const user2 = otherAccounts[2];

    // initial balance checks
    const bobBalanceBeforeStake = await ethers.provider.getBalance(user2.address);
    const validatorEffectiveStakeBeforeStake = await stargateContract.getDelegatorsEffectiveStake(validator.address, 0);
    console.log("Validator effective delegators balance before stake = ", validatorEffectiveStakeBeforeStake);

    // stake both NFTs
    tx = await stargateContract.connect(user).stake(LEVEL_ID, {
        value: levelSpec.vetAmountRequiredToStake,
    });
    await tx.wait();
    const tokenId1 = await stargateNFTMockContract.getCurrentTokenId();
    tx = await stargateContract.connect(user2).stake(LEVEL_ID, {
        value: levelSpec.vetAmountRequiredToStake,
    });
    await tx.wait();
    const tokenId2 = await stargateNFTMockContract.getCurrentTokenId();

    // delegate the NFTs to the validator
    tx = await stargateContract.connect(user).delegate(tokenId1, validator.address);
    await tx.wait();
    tx = await stargateContract.connect(user2).delegate(tokenId2, validator.address);
    await tx.wait();
    const validatorEffectiveStakeAfterDelegations = await stargateContract.getDelegatorsEffectiveStake(validator.address, 2);
    console.log("Validator effective delegators balance after delegations = ", validatorEffectiveStakeAfterDelegations);

    // set validator completed periods to 10 so is active
    tx = await protocolStakerMockContract.helper__setValidationCompletedPeriods(validator.address, 10);
    await tx.wait();

    // Bob requests delegation exit
    tx = await stargateContract.connect(user2).requestDelegationExit(tokenId2);
    await tx.wait();

    const validatorEffectiveStakeAfterBobRequestExit = await stargateContract.getDelegatorsEffectiveStake(validator.address, 12);
    console.log("Validator effective delegators balance after Bob requests exit = ", validatorEffectiveStakeAfterBobRequestExit);

    // advance some periods so is exited
    tx = await protocolStakerMockContract.helper__setValidationCompletedPeriods(validator.address, 20);
    await tx.wait();

    // assert the delegation is exited
    expect(await stargateContract.getDelegationStatus(tokenId2)).to.equal(DELEGATION_STATUS_EXITED);
    await tx.wait();

    // change validator status to EXITED, this will enable the bug
    tx = await protocolStakerMockContract.helper__setValidatorStatus(validator.address, VALIDATOR_STATUS_EXITED);
    await tx.wait();

    // unstake the NFT of Bob and expect success
    tx = await stargateContract.connect(user2).unstake(tokenId2);
    await tx.wait();

    // PROVE THE BUG, effective delegations are wrongfully zeroed
    const validatorEffectiveStakeAfterBobUnstake = await stargateContract.getDelegatorsEffectiveStake(validator.address, 22);
    console.log("Validator effective delegators balance after Bob unstake = ", validatorEffectiveStakeAfterBobUnstake);

    const bobBalancePostUnstake = await ethers.provider.getBalance(user2.address);
    expect(bobBalancePostUnstake).to.be.closeTo(
        bobBalanceBeforeStake,
        ethers.parseEther("0.1") // gas tolerance
    );

    // assert the token is burned
    await expect(stargateNFTMockContract.ownerOf(tokenId2)).to.be.revertedWithCustomError(
        stargateNFTMockContract,
        "ERC721NonexistentToken"
    );
    expect(await stargateNFTMockContract.ownerOf(tokenId1)).to.equal(user.address);

    // Alice tries to unstake and it panics due to underflow. Alice's funds are stuck
    await expect(stargateContract.connect(user).unstake(tokenId1)).to.be.revertedWithPanic(0x11);
});

Test output:

JavaScript
  shard-u1: Stargate: Staking
Validator effective delegators balance before stake =  0n
Validator effective delegators balance after delegations =  3000000000000000000n
Validator effective delegators balance after Bob requests exit =  1500000000000000000n
Validator effective delegators balance after Bob unstake =  0n
    ✔ should prove double subtraction error (80ms)


  1 passing (1s)

As shown by the test, two users stake at the same level and delegate to the same validator. If the validator exits between requestDelegationExit and unstake called by one of the users, the validator's delegatorsEffectiveStake can be decreased twice, causing other delegators' funds to become permanently stuck.

The original report as published on Immunefi, by xKeywordx. 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 exit path removes a delegation's effective stake from the per-validator aggregate in both requestDelegationExit and unstake, without tracking that it was already removed.

Impact

Other delegators' staked funds become permanently locked because any unstake call reverts with an arithmetic underflow once the validator's effective stake has been driven to zero.

What the attacker needed

Two delegators on the same validator; validator exits between exit request and unstake

The fix

Each delegation's effective stake should be added and removed exactly once, for example by tracking whether it has already been removed before subtracting again.

How it was found

  1. Two users stake equal amounts and delegate to the same validator, so the validator's effective stake is the sum of both.
  2. One user calls requestDelegationExit, which subtracts their amount from the validator's effective stake.
  3. The validator exits, changing its status to exited.
  4. That user calls unstake, which subtracts the same amount a second time because the validator is exited.
  5. The other user calls unstake and the transaction reverts with a panic due to underflow, locking their funds.

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.

Staking contracts keep a running total of how much stake each validator holds on behalf of all its delegators. When one person leaves, their share should be removed from that total exactly once. Here it is removed twice, so the total drops below what it should be, and when another person later tries to leave the contract's maths goes negative and the transaction fails, leaving their money stuck.

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 xKeywordx

View all

6 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.

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.