# vestTokens bug in MultiFeeDistribution.sol causes new incentives to erase previous incentives

vestTokens calls _notifyReward without _updateReward, resetting lastUpdateTime and erasing lockers' previously accrued rewards whenever a minter adds new incentives.

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

**Target:** MultiFeeDistribution.sol reward accounting (vestTokens/_notifyReward)
**Root cause:** _notifyReward sets r.lastUpdateTime = block.timestamp without first calling _updateReward to checkpoint rewardPerTokenStored, so the elapsed reward period since the last update is never accounted for.
**Steps:**
1. Deploy MultiFeeDistribution, set lock types, stake 1 ether as Alice (locker).
2. Minter mints 10000 ether and calls `vestTokens(address(multiFeeDistribution), 10000 ether, false)` to add incentives.
3. Skip 31 days; `claimableRewards(Alice)` shows ~10000 ether accrued.
4. Minter adds a second incentive of 1 ether via `vestTokens(address(multiFeeDistribution), 1 ether, false)`.
5. `claimableRewards(Alice)` now returns 0; after another 31 days only ~1 ether remains — the first 10000 ether is erased.
**How found:** Code review of vestTokens: noticed it calls _notifyReward directly, unlike all other callers which invoke _updateReward first; traced that _notifyReward writes lastUpdateTime without checkpointing rewardPerTokenStored, then confirmed with a Foundry PoC.
**Exploitation:** Any minter adding a new incentive via vestTokens silently wipes the rewardPerTokenStored accrual for the elapsed period; lockers lose all rewards accumulated since the last _updateReward. Triggered by normal protocol operation, not attacker capital.
**Insight:** In Synthetix-style staking contracts, any path that writes lastUpdateTime/rewardPerSecond must first checkpoint rewardPerTokenStored via _updateReward; audit every caller of the internal notify function for a missing checkpoint, not just the obvious stake/withdraw paths.

