Skip to content
Business logic Audit finding Intermediate

Off-by-one in _claimableDelegationPeriods allows claimRewards() to pay for periods after delegation end — Over-claim / Theft of unclaimed yield

An off-by-one comparison in the claimable-period calculation lets a token owner claim VTHO rewards for periods after their delegation ended. An attacker can arrange the delegation end to equal the next claimable period, let the validator's completed periods advance, and then claim rewards for the extra periods.

daxun Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

59361 sc high off by one in claimabledelegationperiods allows claimrewards to pay for periods after delegation end over claim theft of unclaimed yield

Submitted on Nov 11th 2025 at 14:25:06 UTC by @daxun for Audit Comp | Vechain | Stargate Hayabusa

Description

Brief / Intro

Stargate.sol computes the range of claimable periods for a delegated token and then pays VTHO rewards for every claimable period. Due to an off-by-one conditional in _claimableDelegationPeriods, when the delegation endPeriod equals the token's nextClaimablePeriod, the function fails to cap the last claimable period at endPeriod. If the validator’s completedPeriods later advances past endPeriod, claimRewards() will allow claims up to completedPeriods — including periods after the delegation ended — causing the contract to pay rewards the token wasn’t entitled to.

Vulnerability Details

Location: packages/contracts/contracts/Stargate.sol — function _claimableDelegationPeriods(...).
https://github.com/immunefi-team/audit-comp-vechain-stargate-hayabusa/blob/e9c0bc9b0f24dc0c44de273181d9a99aaf2c31b0/packages/contracts/contracts/Stargate.sol#L879-L934

Problematic code fragment:

Solidity
if (
    endPeriod != type(uint32).max &&
    endPeriod < currentValidatorPeriod &&
    endPeriod > nextClaimablePeriod
) {
    return (nextClaimablePeriod, endPeriod);
}
  • endPeriod is the period when the delegation ends (set to type(uint32).max when no exit requested).
  • nextClaimablePeriod is lastClaimedPeriod + 1, adjusted to delegation startPeriod if needed.
  • currentValidatorPeriod = completedPeriods + 1 (the ongoing period).

When endPeriod == nextClaimablePeriod (the equal case), the endPeriod > nextClaimablePeriod check fails. Execution falls through and later the function may return (nextClaimablePeriod, completedPeriods) (the validator's completedPeriods) if nextClaimablePeriod < currentValidatorPeriod. If completedPeriods > endPeriod, the claimable window now includes periods after endPeriod. The reward calculation _claimableRewardsForPeriod() uses stored effectiveStake values and does not verify per-period participation; therefore, the token owner receives VTHO for those extra periods.

This is a pure logic bug (off-by-one) — no race conditions, no privileged access, and reproducible with protocol state manipulation.

Impact Details

  • Category: Theft of unclaimed yield (in-scope, High severity).
  • Concrete impact: Token owners can receive VTHO for periods during which their token was not delegated. The attacker can:
    • Create a delegation with startPeriod = X, endPeriod = X (equal to nextClaimablePeriod), or otherwise arrange state so endPeriod == nextClaimablePeriod.
    • Let completedPeriods advance beyond endPeriod (natural protocol progression).
    • Call claimRewards() and receive rewards through completedPeriods, including periods after endPeriod.
  • Financial impact: Any amount of VTHO paid per period × number of over-claimable periods. Depending on production reward sizes and multiple tokens this can be materially high. This is direct protocol loss (funds transfer out of protocol-controlled VTHO).
  • Exploit prerequisites: None privileged. Requires only an attacker-controlled token and normal protocol progression of completedPeriods. Fully reproducible via local test harness or mainnet fork.

References

  • Contract: packages/contracts/contracts/Stargate.sol (function _claimableDelegationPeriods)
  • Relevant functions: _claimRewards, _claimableRewards, _claimableRewardsForPeriod in same file.
  • Program scope: Stargate.sol is explicitly in-scope per the audit competition.

Proof of Concept

{% stepper %} {% step %}

Setup

  1. Deploy contracts (or use a mock):
    • Stargate (initialize with protocolStakerContract pointing to a mock ProtocolStaker and stargateNFTContract pointing to a mock StargateNFT).
    • MockProtocolStaker should allow controlling completedPeriods and provide delegation period responses.
    • MockStargateNFT should allow minting a token whose vetAmountStaked and level are known. {% endstep %}

{% step %}

Create delegation

  1. Create a delegation for token T:
    • Ensure at delegation time completedPeriods = N.
    • On delegation, Stargate sets lastClaimedPeriod = completedPeriods + 1 (which equals N+1), so nextClaimablePeriod = N+2 normally — but craft mocks so that the delegation start/end results in nextClaimablePeriod == endPeriod. Achieve this by configuring the mock ProtocolStaker to set delegation startPeriod and endPeriod appropriately during PoC. {% endstep %}

{% step %}

Signal exit

  1. Signal an exit on the delegation such that endPeriod == nextClaimablePeriod (the equal case). For example, set endPeriod to the delegation’s start period. {% endstep %}

{% step %}

Advance validator periods

  1. Advance completedPeriods on the mock to a value greater than endPeriod. Example: set completedPeriods = endPeriod + 2. {% endstep %}

{% step %}

Claim rewards

  1. Call Stargate.claimRewards(tokenId). {% endstep %}

{% step %}

Observe over-claim

  1. Observe that claimRewards() computes lastClaimablePeriod = completedPeriods and transfers VTHO rewards for periods including those > endPeriod. On a mock, assert that transfer amount corresponds to number of over-claimed periods. {% endstep %} {% endstepper %}

Minimal deterministic test skeleton (conceptual)

  • Use a MockProtocolStaker that:
    • Returns controlled completedPeriods via getValidationPeriodDetails.
    • When addDelegation is called, returns a delegation id with startPeriod = completedPeriods + 1 and end = type(uint32).max.
    • When signalDelegationExit(delegationId) is called, sets end = start (so end == nextClaimablePeriod).
    • getDelegatorsRewards(validator, period) returns fixed reward per period (e.g., 1e18) so the PoC can assert transfer amounts.
  • Use a MockStargateNFT that:
    • mint() returns a token with vetAmountStaked and level that produce a stable effectiveStake.
    • ownerOf returns the attacker address.
  • Run the sequence: stakeAndDelegate() -> signalDelegationExit() -> advance completedPeriods -> claimRewards() -> assert VTHO transfer includes periods after endPeriod.

Notes

  • The root cause is an off-by-one comparison: the > check on endPeriod excludes the equal case, which should be capped at endPeriod to avoid paying out periods after delegation end.
  • Fix should ensure endPeriod >= nextClaimablePeriod (or equivalently adjust comparisons) so the returned last claimable period is at most endPeriod when endPeriod is not type(uint32).max.

The original report as published on Immunefi, by daxun. 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 an off-by-one in the comparison that caps the last claimable period: the strict greater-than check excludes the case where the delegation end equals the next claimable period, so the cap is not applied.

Impact

A token owner could receive VTHO rewards for periods when their token was not delegated, causing direct loss of protocol-controlled VTHO; the text does not mention any defence that would limit this.

What the attacker needed

An attacker-controlled token; normal protocol progression of completed periods

The fix

The comparison should be changed so that the last claimable period is capped at the delegation end period whenever the end period is not the maximum value.

How it was found

  1. Deploy the Stargate contract with mock staker and NFT contracts that allow controlling completed periods and token details.
  2. Create a delegation for a token and configure the mock so that the delegation end period equals the next claimable period.
  3. Signal an exit on the delegation so that the end period equals the next claimable period.
  4. Advance the validator's completed periods to a value greater than the delegation end period.
  5. Call claimRewards for the token.
  6. Observe that the contract pays rewards for periods after the delegation end.

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 pays rewards for each period a token is delegated to a validator. A mistake in the code that decides which periods can be claimed means that, in one specific situation, the contract also pays for periods after the delegation has already ended. Someone can set up that situation and collect rewards they should not get.

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 daxun

View all

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