Skip to content
Smart contracts Audit finding Intermediate

Incorrect double reduction of effective stake in stargate sol

The Stargate contract reduces a validator's effective stake twice for the same token when a user requests a delegation exit and later unstakes after the validator has exited. This incorrect accounting could affect reward calculations and may cause an underflow that prevents some users from exiting delegations.

T0nraq Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

60586 sc high incorrect double reduction of effective stake in stargate sol

Submitted on Nov 24th 2025 at 08:05:31 UTC by @T0nraq for Audit Comp | Vechain | Stargate Hayabusa

Description

Description:

When a user requests a delegation exit and subsequently unstakes their NFT after the validator has exited, the contract logic can trigger a double reduction of the validator's effective stake for the same token. This occurs because both requestDelegationExit() and unstake() call _updatePeriodEffectiveStake() to decrease the validator's effective stake, but for overlapping periods and the same token.

Relevant Code Snippets:

requestDelegationExit()

Solidity
// decrease the effective stake
// Get the latest completed period of the validator
(, , , uint32 completedPeriods) = $.protocolStakerContract.getValidationPeriodDetails(
    delegation.validator
);
// decrease the effective stake
_updatePeriodEffectiveStake($, delegation.validator, _tokenId, completedPeriods + 2, false);

unstake()

Solidity
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
    );
}

_updatePeriodEffectiveStake()

Solidity
function _updatePeriodEffectiveStake(
    StargateStorage storage $,
    address _validator,
    uint256 _tokenId,
    uint32 _period,
    bool _isIncrease
) private {
    // calculate the effective stake
    uint256 effectiveStake = _calculateEffectiveStake($, _tokenId);

    // get the current effective stake
    uint256 currentValue = $.delegatorsEffectiveStake[_validator].upperLookup(_period);

    // calculate the updated effective stake
    uint256 updatedValue = _isIncrease
        ? currentValue + effectiveStake
        : currentValue - effectiveStake;

    // push the updated effective stake
    $.delegatorsEffectiveStake[_validator].push(_period, SafeCast.toUint224(updatedValue));
}

Steps to Reproduce/Attack path:

  1. Stake and delegate an NFT to a validator.
  2. Call requestDelegationExit(tokenId) for the NFT.
  3. Advance the validator to VALIDATOR_STATUS_EXITED.
  4. Call unstake(tokenId) for the same NFT.
  5. Observe that the validator's effective stake is reduced twice for the same token in future periods.

Expected Behavior:
The validator's effective stake should only be reduced once per token exit event, regardless of whether the user unstakes after requesting a delegation exit.

Actual Behavior:
The effective stake is reduced twice: once during requestDelegationExit() and again during unstake(), resulting in an incorrect accounting of the validator's effective stake.

Impact:

  • Will affect reward calculations.
  • Over-penalizes the validator's effective stake.
  • May lead to inconsistencies in protocol accounting and user expectations.
  • Some users may not be able to exit delegations as it could cause an underflow

Suggested Fix:

  • Track whether the effective stake has already been reduced for a given token/period, and prevent redundant reductions in unstake().
  • Refactor the logic so that only one reduction occurs per exit/unstake lifecycle.

Proof of Concept

Proof of Concept

Add the following unit test to stake.test.ts

Solidity
    it.only("should show double reduction of effective stake when unstaking after validator exit", async () => {
        // stake an NFT for user1
        const levelSpec = await stargateNFTMockContract.getLevel(LEVEL_ID);
        
        await stargateContract.connect(user).stake(LEVEL_ID, {
            value: levelSpec.vetAmountRequiredToStake,
        });
        const tokenId1 = await stargateNFTMockContract.getCurrentTokenId();
        await stargateContract.connect(user).delegate(tokenId1, validator.address);

        // stake an NFT for user2 (second staker/delegator)
        const user2 = otherAccounts[2];
        await stargateContract.connect(user2).stake(LEVEL_ID, {
            value: levelSpec.vetAmountRequiredToStake,
        });
        const tokenId2 = await stargateNFTMockContract.getCurrentTokenId();
        await stargateContract.connect(user2).delegate(tokenId2, validator.address);

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

        // get effective stake before exit
        let period = 12; // oldCompletedPeriods + 2 after exit
        const stakeBefore = await stargateContract.getDelegatorsEffectiveStake(validator.address, period);

        // request delegation exit for user1
        await stargateContract.connect(user).requestDelegationExit(tokenId1);

        // get effective stake after exit
        const stakeAfterExit = await stargateContract.getDelegatorsEffectiveStake(validator.address, period + 2);

        await protocolStakerMockContract.helper__setValidationCompletedPeriods(validator.address, 15);

        // Exit Validator
        await protocolStakerMockContract.helper__setValidatorStatus(
            validator.address,
            VALIDATOR_STATUS_EXITED
        );

        // advance some periods so is exited
        await protocolStakerMockContract.helper__setValidationCompletedPeriods(validator.address, 20);
        
        // unstake the NFT for user1
        await stargateContract.connect(user).unstake(tokenId1);
        
        // get effective stake after unstake
        period = 22; // oldCompletedPeriods + 2
        const stakeAfterUnstake = await stargateContract.getDelegatorsEffectiveStake(validator.address, period);
        
        await protocolStakerMockContract.helper__setValidationCompletedPeriods(validator.address, 23);
        // await stargateContract.connect(user2).requestDelegationExit(tokenId2);

        // Print the values to show double reduction
        console.log("Stake before exit:", stakeBefore.toString());
        console.log("Stake after exit:", stakeAfterExit.toString());
        console.log("Stake after unstake:", stakeAfterUnstake.toString());

        // The bug: stakeAfterUnstake should equal stakeAfterExit, but will be reduced again
        expect(stakeAfterUnstake).to.be.lt(stakeAfterExit);
    });

The original report as published on Immunefi, by T0nraq. 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

Both requestDelegationExit() and unstake() call _updatePeriodEffectiveStake() to decrease the validator's effective stake for the same token without tracking that a reduction has already occurred.

Impact

The double reduction over-penalises the validator's effective stake, may affect reward calculations, and could cause an underflow that prevents some users from exiting delegations.

What the attacker needed

A staked NFT delegated to a validator; validator reaches exited status

The fix

The logic should track whether the effective stake has already been reduced for a given token and period, and prevent redundant reductions in unstake().

How it was found

  1. Stake an NFT and delegate it to a validator.
  2. Call requestDelegationExit(tokenId) for the NFT.
  3. Advance the validator to VALIDATOR_STATUS_EXITED.
  4. Call unstake(tokenId) for the same NFT.
  5. Observe that the validator's effective stake is reduced twice for the same token in future periods.

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 someone delegates a token to a validator, the system tracks how much 'effective stake' that validator has. This report shows that if a user first asks to leave the validator and later unstakes the token after the validator has exited, the system subtracts the token's stake twice instead of once. That makes the validator's recorded stake too low, which can distort rewards and even block other users from leaving.

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 T0nraq

View all

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