# Rewards Can Be Harvested Even When Distribution Is Marked As Finished

finishDistribution() in StakedEXA only sets finishAt to now; harvest() still pulls rewards from the market and restarts a new distribution via notifyRewardAmount, letting users claim rewards after distribution was meant to end.

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

**Target:** StakedEXA.sol staking/reward contract
**Root cause:** finishDistribution() only sets rewardData.finishAt = block.timestamp and transfers accrued rewards, but does not disable harvest(); notifyRewardAmount() treats block.timestamp >= finishAt as a fresh distribution start, recomputing rate and extending finishAt.
**Steps:**
1. Admin calls `finishDistribution(reward)` at StakedEXA.sol#L425, setting finishAt = block.timestamp.
2. User calls `harvest()` (L344); it computes assets from distributor allowance and withdraws them from the market.
3. harvest() calls `notifyRewardAmount()` (L209); since block.timestamp >= finishAt, `rewardData.rate = amount / rewardData.duration`.
4. notifyRewardAmount sets `finishAt = block.timestamp + duration` and `updatedAt = block.timestamp`, starting a new distribution.
5. User calls `claim()` to collect the newly harvested rewards.
**How found:** Code reading of finishDistribution() vs harvest()/notifyRewardAmount(): noticed finishDistribution only updates finishAt without gating harvest, and that notifyRewardAmount's `block.timestamp >= finishAt` branch re-arms the distribution.
**Exploitation:** Any user with a stake calls harvest() after the admin finalizes rewards; the contract pulls reward tokens from the market via the distributor allowance and re-notifies them as a new distribution, which the caller then claims, draining provider assets that were meant to be excluded.
**Insight:** When a 'finalize/stop' function only mutates a timestamp, check every other entrypoint that reads that timestamp — here notifyRewardAmount treats expiry as a fresh-start condition, so the stop is reversible by any caller.

