# Discrepancy between the lastRewadTime and the lastAllPoolUpdate can allow for incorrect reward distribution to pools if registerRewardDeposit deposits less assets

Timestamp mismatch between lastRewardTime and lastAllPoolUpdate in LoopFi's reward accounting lets pools claim unearned rewards after endRewardTime is surpassed.

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

**Target:** Solidity reward distribution contract (massUpdatePools/registerRewardDeposit)
**Root cause:** _massUpdatePools sets lastAllPoolUpdate=block.timestamp while _updatePool clamps lastRewardTime to endRewardTime when endRewardTime<=block.timestamp, so the two timestamps diverge and endRewardTime() recomputes from lastAllPoolUpdate, granting extra reward accrual.
**Steps:**
1. Set rewardsPerSecond=1, endRewardTime=100, block.timestamp=110, pools A and B 1:1.
2. Call registerRewardDeposit with small amount so new endRewardTime=105.
3. Call massUpdatePools: lastRewardTime=105, lastAllPoolUpdate=110; a second massUpdatePools (e.g. via claim) sets new endTime=110.
4. Call claim for pool A: its lastRewardTime becomes 110, B stays 105.
5. At t=120 registerRewardDeposit large amount; B accrues (120-105)/2, A only (120-110)/2.
**How found:** Code reading of _massUpdatePools vs _updatePool revealed lastAllPoolUpdate is set to block.timestamp while lastRewardTime is clamped to endRewardTime, and endRewardTime() derives from lastAllPoolUpdate, creating a divergence exploitable via small deposits.
**Exploitation:** Trigger registerRewardDeposit with a small deposit after endRewardTime has passed, then call massUpdatePools and claim on one pool to desync lastRewardTime between pools, then deposit large rewards so the lagging pool accrues disproportionate rewards.
**Insight:** When a contract maintains both a global and per-pool timestamp, check whether one is clamped (e.g. to endTime) while the other is set to block.timestamp; any function deriving future time from the unclamped one creates a reward-accrual gap.

