# Incorrect tier tracking when tier 3 staker exits in a certain case

LayerEdge staking records tier boundary at wrong rank when a T3 staker exits, leaving an extra T2 staker and overpaying APY.

- Payout: Audit contest
- Severity: high
- Program: Layeredge
- Found by: MysteryAuditor
- Disclosed: 2025-05-21
- Write-up quality: 7/10
- Original: https://github.com/sherlock-audit/2025-05-layeredge-judging/issues/83
- Library page: https://bugbountylibrary.com/r/sherlock%3A2025-05-layeredge%3AH-1
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Solidity staking contract tier-boundary logic
**Root cause:** On removal, `_findAndRecordTierChange(new_t1 + new_t2, n)` uses the post-removal T1+T2 count, but when a T3 staker exits the T1/T2 ranks are unchanged, so the boundary rank is off by one and the wrong staker is demoted.
**Steps:**
1. Stake MIN_STAKE from 15 distinct users so distribution is 3 T1 / 4 T2 / 8 T3.
2. Have a T3 staker (e.g. address(10)) call `unstake(MIN_STAKE)`.
3. Removal path hits `else if (isRemoval) { _findAndRecordTierChange(new_t1 + new_t2, n); }` writing to rank 6 instead of rank 7.
4. Observe resulting counts: 2 T1 (correct), 5 T2 (incorrect), 7 T3 (incorrect) via `getTier` loop.
**How found:** Reasoned about boundary rank arithmetic: noticed that when a T3 staker exits, T1/T2 counts don't change, so the rank written by `new_t1 + new_t2` no longer matches the actual last-T2 position; confirmed with a Foundry PoC asserting tier counts.
**Insight:** When a removal recomputes a boundary index from post-removal tier counts, check whether the removed staker was in the tier being bounded — if not, the boundary rank must be derived from the unchanged tier's current membership, not the new totals.

