# Rewards may be spread out among the wrong time period due to the way the protocol calculates it

LoopFi MultiFeeDistribution _notifyReward stretches leftover rewards over a new incentive's full duration, delaying and diluting earlier stakers' payouts.

- Payout: Audit contest
- Severity: medium
- Program: LoopFi
- Found by: rscodes
- Disclosed: 2025-02-17
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-07-loopfi-findings/issues/133
- Library page: https://bugbountylibrary.com/r/c4%3A2024-07-loopfi%3AM-27
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:reward-distribution

**Target:** MultiFeeDistribution staking/reward contract (_notifyReward)
**Root cause:** When a new reward is notified mid-period, leftover is recomputed and rewardPerSecond is reset over the full rewardsDuration instead of the remaining time, stretching old rewards into the new period.
**Steps:**
1. Deploy MultiFeeDistribution with rewardsDuration=30 days; stake 1 ether as Alice with a lock type.
2. vestTokens 10000 ether at day 0 (1st incentive).
3. skip(15 days); Alice getReward -> ~5000 ether.
4. vestTokens another 10000 ether at day 15 (2nd incentive) -> _notifyReward recomputes rewardPerSecond over full 30 days.
5. skip(15 days); Alice getReward -> total ~12500 ether instead of rightful 15000 ether; remainder leaks to days 30-45.
6. Late staker joining day 30 can capture part B rewards Alice should have earned.
**How found:** Code-reading of _notifyReward's else branch: noticed leftover is divided by full rewardsDuration rather than remaining time, then modeled the timeline with a Foundry test.
**Exploitation:** A staker who joins between day 30 and day 45 captures a share of the first incentive's leftover rewards that were incorrectly stretched, permanently diluting early stakers' payouts.
**Insight:** In Synthetix-style staking forks, check the mid-period _notifyReward branch: leftover should be spread over remaining time, not the full duration; forked code inherits the flaw even if upstream calls it intended.

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

**Vulnerable _notifyReward leftover calculation**

```
uint256 remaining = r.periodFinish - block.timestamp;
->    uint256 leftover = (remaining * r.rewardPerSecond) / 1e12;
->    r.rewardPerSecond = ((reward + leftover) * 1e12) / rewardsDuration;
```

