# Game doesn't accrued rewards for previous rebalance period in case if rebalanceBasket is called in next period

Derby Game.addToTotalRewards skips reward accrual when currentRebalancingPeriod equals lastRebalancingPeriod, so users rebalancing every period lose all prior-period rewards.

- Payout: Contest reward
- Severity: medium
- Program: Derby
- Credited: XKET
- Disclosed: 2022-10-17
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2023-01-derby-judging/issues/119
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-01-derby%3AM-36
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity vuln:accounting-error vuln:business-logic

**Target:** Game.sol rebalanceBasket / addToTotalRewards
**Root cause:** addToTotalRewards returns early when currentRebalancingPeriod <= lastRebalancingPeriod, but lastRebalancingPeriod is set to the next period at allocation time, so the period the user allocated for is never accrued before lastRebalancingPeriod advances again.
**Steps:**
1. currentRebalancingPeriod = 10; user calls `rebalanceBasket`, lastRebalancingPeriod set to 11
2. `pushAllocationsToController` advances currentRebalancingPeriod to 11
3. `settleRewards` accrues rewards for cycle 11
4. user calls `rebalanceBasket` for cycle 12; `addToTotalRewards` sees current==last==11 and returns without accruing
5. lastRebalancingPeriod becomes 12; repeat each period to lose all rewards
**How found:** Code reading of addToTotalRewards' early-return condition against the ordering of lastRebalancingPeriod assignment and pushAllocationsToController period advancement.
**Exploitation:** Any user who rebalances every period silently forfeits the rewards of the period they allocated for; only skipping a period lets accrual occur.
**Insight:** When a guard compares a stored 'last processed' marker to a global period counter, check whether the marker is advanced before the accrual for that same period can run; equality guards often silently drop the boundary period.
