# Incorrect handling of last nominee removal in removeNominee function

Removing the last nominee in VoteWeighting.removeNominee reassigns its own ID back into mapNomineeIds, leaving a stale entry that corrupts nominee bookkeeping.

- Payout: Audit contest
- Severity: medium
- Program: Olas
- Found by: Limbooo
- Disclosed: 2024-08-06
- Write-up quality: 6/10
- Original: https://github.com/code-423n4/2024-05-olas-findings/issues/16
- Library page: https://bugbountylibrary.com/r/c4%3A2024-05-olas%3AM-18
- Tags: area:web3 domain:web3 impact:integrity kind:contest platform:code4rena sev:medium tech:evm tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** VoteWeighting.sol governance contract (Solidity/EVM)
**Root cause:** The swap-and-pop removal unconditionally copies the last array element into the removed slot and rewrites its mapNomineeIds entry; when the removed nominee IS the last element, it re-writes its own ID after zeroing it, leaving a stale mapping entry.
**Steps:**
1. Deploy OLAS, veOLAS, VoteWeighting; add two nominees via `addNomineeEVM(nominees[i], chainId)`.
2. Call `removeNominee(nominees[1], chainId)` where nominees[1] is the last element.
3. Observe `getNomineeId(nominees[1], chainId)` still returns 2 instead of 0.
4. `getNextAllowedVotingTimes` with the removed nominee succeeds instead of reverting NomineeDoesNotExist.
5. Re-removing reverts with Panic(0x32); after adding a new nominee, removing the stale nominee deletes the wrong (new) nominee, corrupting setNominees.
**How found:** Code review of the swap-and-pop removal logic in removeNominee, noticing the last-element case is not special-cased before reassigning mapNomineeIds.
**Escalation:** Stale ID lets a removed nominee pass existence checks; subsequent add/remove cycles delete the wrong nominee, corrupting the nominee set.
**Insight:** In swap-and-pop array removal, always check whether the removed index equals length-1 before copying the last element into it; otherwise the element rewrites its own mapping entry after being zeroed.

