# Having no deposits in `StakedEXA` will lead to stuck rewards when harvesting

StakedEXA::globalIndex returns stale index when totalSupply is zero, so harvested rewards accrue to no one and are permanently stuck.

- Payout: Audit contest
- Severity: medium
- Program: Exactly Stacking Contracts
- Found by: 0x73696d616f
- Disclosed: 2024-07-17
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-07-exactly-stacking-contracts-judging/issues/48
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-07-exactly-stacking-contracts%3AM-7
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:reward-distribution

**Target:** StakedEXA staking/rewards contract
**Root cause:** globalIndex() early-returns rewardData.index when totalSupply()==0 instead of accruing rate*deltaTime, yet updateIndex() still advances rewardData.updatedAt, discarding undistributed rewards.
**Steps:**
1. Deploy StakedEXA with a reward stream configured (rate, finishAt) via harvest setup.
2. Ensure totalSupply()==0 (no deposits yet, or all users withdraw mid-stream).
3. Call harvest()/updateIndex(reward): globalIndex returns stale index because totalSupply()==0.
4. updateIndex sets rewardData.updatedAt = lastTimeRewardApplicable(finishAt), skipping the elapsed window.
5. Rewards for that window are never credited to any index and remain stuck in the contract.
**How found:** Code review of the reward index accounting: noticed globalIndex short-circuits on zero totalSupply while updateIndex unconditionally bumps updatedAt, creating a mismatch that loses rate*deltaTime.
**Exploitation:** Not an attacker-driven exploit; occurs naturally when rewards stream while no deposits exist or after full withdrawal, permanently stranding the unaccrued reward amount.
**Insight:** In Synthetix-style staking rewards, any early-return in the index calculation must not advance updatedAt; check zero-supply branches for lost accrual windows.

## Proof of concept (copied exactly from the original report)

**globalIndex returns stale index when totalSupply is zero**

```
function globalIndex(IERC20 reward) public view returns (uint256) {
  RewardData storage rewardData = rewards[reward];
  if (totalSupply() == 0) return rewardData.index;

  return
    rewardData.index +
    (rewardData.rate * (lastTimeRewardApplicable(rewardData.finishAt) - rewardData.updatedAt)).divWadDown(
      totalSupply()
    );
}
```

**updateIndex advances updatedAt despite stale index**

```
function updateIndex(IERC20 reward) internal {
  RewardData storage rewardData = rewards[reward];
  rewardData.index = globalIndex(reward);
  rewardData.updatedAt = uint40(lastTimeRewardApplicable(rewardData.finishAt));
}
```

