# Immediately start getting rewards belonging to others after staking

MainRewarder reads stakeTracker balance after mint, so new stakers instantly accrue rewards owed to existing shareholders.

- Payout: Contest reward
- Severity: high
- Program: Tokemak
- Credited: 0x73696d616f
- Disclosed: 2023-06-30
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2023-06-tokemak-judging/issues/603
- Library page: https://bugbountylibrary.com/r/sherlock%3A2023-06-tokemak%3AH-10
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:reward-distribution

**Target:** LMPVault/DV share minting and MainRewarder staking hook
**Root cause:** ERC20 _mint updates balance before _afterTokenTransfer calls rewarder.stake; _updateReward computes earned() using the already-incremented stakeTracker balance while userRewardPerTokenPaid is still zero.
**Steps:**
1. User mints 100 LMPVault/DV shares via deposit
2. ERC20._mint increments _balances[user] then calls _afterTokenTransfer
3. LMPVault._afterTokenTransfer calls rewarder.stake(user, 100)
4. MainRewarder.stake calls _updateReward(user) before _stake
5. _updateReward computes earned = balanceOf(user)*(rewardPerToken()-0)/1e18 = 100r
6. rewards[user] set to 100r; user later claims/withdraws unearned reward tokens
**How found:** Code-reading of OpenZeppelin _mint ordering versus the _afterTokenTransfer staking hook and AbstractRewarder.earned() formula, noticing balance is read post-increment while reward debt is still zero.
**Exploitation:** Attacker mints shares to trigger the hook; the rewarder credits earned() against the fresh balance with zero userRewardPerTokenPaid, letting them claim reward tokens belonging to existing shareholders.
**Insight:** When a rewarder derives balance from an external stakeTracker, check hook ordering: any state read inside _updateReward that was already mutated by the transfer hook (mint/transfer) inflates earned() for first-time stakers.
