Off-by-one in Stargate.sol _claimableDelegationPeriods lets exited NFTs siphon validator rewards, leading to protocol insolvency
An off-by-one error in the _claimableDelegationPeriods function of Stargate.sol allows an exited NFT to continue claiming validator rewards for periods after its delegation ended. An attacker could repeatedly claim these rewards, diverting other delegators' unclaimed yield and potentially draining the reward pool to insolvency.
- Disclosed after under an hour
60019 sc high off by one in stargate sol claimabledelegationperiods lets exited nfts siphon validator rewards leading to protocol insolvency
Submitted on Nov 17th 2025 at 15:40:21 UTC by @ElouJoe for Audit Comp | Vechain | Stargate Hayabusa
- Report ID: #60019
- 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:
- Protocol insolvency
- Theft of unclaimed yield
Description
Brief/Intro
An off-by-one in Stargate.sol’s _claimableDelegationPeriods allows an exited NFT to keep claiming future validator rewards after its delegation ended, diverting other delegators’ VTHO and ultimately draining the reward pool to insolvency.
Vulnerability Details
When an exit is requested, endPeriod is set. After the user claims through the true endPeriod, lastClaimedPeriod = endPeriod, so nextClaimablePeriod becomes endPeriod + 1 and the check endPeriod > nextClaimablePeriod fails. The code falls back to (nextClaimablePeriod, completedPeriods) and treats the NFT as still active. This lets post-exit periods be claimed indefinitely.
Affected code: _claimableDelegationPeriods in packages/contracts/contracts/Stargate.sol.
Impact Details
- Theft of other delegators’ unclaimed yield each completed period (misrouted to the exited NFT).
- Persistent drain escalates to Critical: Protocol insolvency as the reward stream is continuously siphoned.
References
- Source: https://github.com/immunefi-team/audit-comp-vechain-stargate-hayabusa/tree/main/packages/contracts/contracts/Stargate.sol
- In-repo PoC: packages/contracts/test/unit/Stargate/DelegationBugGhostRewards.test.ts
Run: yarn hardhat test --network hardhat test/unit/Stargate/DelegationBugGhostRewards.test.ts
Link to Proof of Concept
https://gist.github.com/eloufirjawad/283c7077fdccd6eee3953ff4125a5be6
Proof of Concept
{% stepper %} {% step %}
Step 1
Stake and delegate an NFT (attacker) to a valid validator; also stake and delegate a second NFT (honest user) so the validator has a non-zero denominator. {% endstep %}
{% step %}
Step 2
Advance validator completed periods until the delegation is ACTIVE and claimable. {% endstep %}
{% step %}
Step 3
Call requestDelegationExit(attackerTokenId); advance until exit finalizes (endPeriod set and currentValidatorPeriod > endPeriod).
{% endstep %}
{% step %}
Step 4
Claim once to bring lastClaimedPeriod up to endPeriod (this makes nextClaimablePeriod = endPeriod + 1).
{% endstep %}
{% step %}
Step 5
Advance one or more periods; observe claimableRewards(attackerTokenId) > 0 even though status is EXITED, because endPeriod > nextClaimablePeriod is false and the function falls back to (nextClaimablePeriod, completedPeriods).
{% endstep %}
{% step %}
Step 6
Call claimRewards(attackerTokenId); attacker receives VTHO for post‑exit periods. Repeat steps 5–6 indefinitely.
{% endstep %}
{% endstepper %}
What proves the bug
- After claiming through
endPeriod,claimableRewardsremains positive for each new completed period andclaimRewardscontinues paying the exited NFT. - Root cause: once
lastClaimedPeriod == endPeriod,nextClaimablePeriod = endPeriod + 1, makingendPeriod > nextClaimablePeriodfalse;_claimableDelegationPeriodsfalls back to(nextClaimablePeriod, completedPeriods), treating the NFT as still active and enabling post‑exit claims.
How to run the in-repo PoC
One-liner (copy/paste):
cd /Users/jawad/Documents/Python/Crypto/Immunefi/vechain/stargate-contracts-jose-update-contracts-to-hayabusa/packages/contracts && VITE_APP_ENV=local yarn hardhat test --network hardhat test/unit/Stargate/DelegationBugGhostRewards.test.ts
Two-step:
cd /Users/jawad/Documents/Python/Crypto/Immunefi/vechain/stargate-contracts-jose-update-contracts-to-hayabusa/packages/contracts
export VITE_APP_ENV=local
yarn hardhat test --network hardhat test/unit/Stargate/DelegationBugGhostRewards.test.ts
If you want, I can:
- Extract the exact vulnerable code snippet from the referenced repository and include a minimal annotated excerpt,
- Suggest a minimal patch (preserving original semantics) to fix the off-by-one logic.
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 an off-by-one error in the condition `endPeriod > nextClaimablePeriod` causes the function to fall back to treating the NFT as active when `lastClaimedPeriod` equals `endPeriod`.
Impact
The attacker could steal other delegators' unclaimed yield each period, and persistent draining could lead to protocol insolvency.
What the attacker needed
Attacker stakes and delegates an NFT; Honest user stakes and delegates an NFT; Validator has completed periods
The fix
The off-by-one condition should be corrected so that exited NFTs cannot claim rewards for periods after their endPeriod.
How it was found
- Stake and delegate an NFT (attacker) to a valid validator; also stake and delegate a second NFT (honest user) so the validator has a non-zero denominator.
- Advance validator completed periods until the delegation is ACTIVE and claimable.
- Call `requestDelegationExit(attackerTokenId)`; advance until exit finalizes (`endPeriod` set and `currentValidatorPeriod > endPeriod`).
- Claim once to bring `lastClaimedPeriod` up to `endPeriod` (this makes `nextClaimablePeriod = endPeriod + 1`).
- Advance one or more periods; observe `claimableRewards(attackerTokenId) > 0` even though status is EXITED, because `endPeriod > nextClaimablePeriod` is false and the function falls back to `(nextClaimablePeriod, completedPeriods)`.
- Call `claimRewards(attackerTokenId)`; attacker receives VTHO for post‑exit periods. Repeat steps 5–6 indefinitely.
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.
This report describes a bug in a smart contract that manages staking rewards. When a user exits their delegation, the contract is supposed to stop paying them rewards for future periods. However, due to a small mistake in the code, the contract still thinks the exited NFT is active and keeps paying it rewards that belong to other users. This can slowly drain the reward pool and make the protocol insolvent.
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.