# Removed nominee doesn't receive staking incentives for the epoch in which they were removed which is against the intended behaviour

Removed Olas nominee loses staking incentives for the removal epoch because their vote weight is zeroed before incentive calculation, contradicting intended eligibility.

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

**Target:** Dispenser/VoteWeighting staking incentive contracts
**Root cause:** removeNominee zeroes nominee bias from the next week, but calculateStakingIncentives queries nomineeRelativeWeight at the removal epoch endTime where weight is already zero, so the eligible removal epoch yields zero incentive.
**Steps:**
1. Nominee is removed via VoteWeighting.removeNominee, which sets pointsWeight[nomineeHash][nextTime].bias = 0 for nextTime = (block.timestamp + WEEK)/WEEK*WEEK and calls Dispenser.removeNominee setting mapRemovedNomineeEpochs[nomineeHash] = eCounter.
2. Dispenser.removeNominee only allows removal when block.timestamp < endTime + epochLen - 1 weeks (reverts if block.timestamp >= maxAllowedTime), i.e. more than a week before epoch end.
3. calculateStakingIncentives loops j from firstClaimedEpoch to lastClaimedEpoch-1, where lastClaimedEpoch is capped at mapRemovedNomineeEpochs+1, so the removal epoch is included.
4. For that epoch, nomineeRelativeWeight(stakingTarget, chainId, getEpochEndTime(j)) returns zero because bias was zeroed, so stakingIncentive = 0 and the nominee loses that epoch's rewards.
**How found:** Read the loop bound `j < lastClaimedEpoch` and the `epochAfterRemoved` capping logic showing the removal epoch is intended to be claimable, then cross-referenced removeNominee's bias-zeroing at nextTime to see the weight is already zero at that epoch's endTime.
**Insight:** When a reward loop intentionally includes an epoch (via `lastClaimedEpoch = removedEpoch + 1`), verify the weight/balance snapshot used for that epoch isn't zeroed by the removal itself; checkpoints keyed to week boundaries can invalidate the just-included epoch.

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

**removeNominee sets nominee weight to zero next week**

```
uint256 nextTime = (block.timestamp + WEEK) / WEEK * WEEK;
        pointsWeight[nomineeHash][nextTime].bias = 0;
        timeWeight[nomineeHash] = nextTime;

        // Account for the the sum weight change
        uint256 newSum = oldSum - oldWeight;
        pointsSum[nextTime].bias = newSum;
        timeSum = nextTime;

        // Add to the removed nominee map and set
        mapRemovedNominees[nomineeHash] = setRemovedNominees.length;
        setRemovedNominees.push(nominee);

        // Remove nominee from the map
        mapNomineeIds[nomineeHash] = 0;

        // Shuffle the current last nominee id in the set to be placed to the removed one
        nominee = setNominees[setNominees.length - 1];
        bytes32 replacedNomineeHash = keccak256(abi.encode(nominee));
        mapNomineeIds[replacedNomineeHash] = id;
        setNominees[id] = nominee;
        // Pop the last element from the set
        setNominees.pop();

        // Remove nominee in dispenser, if applicable
        address localDispenser = dispenser;
```

**Dispenser removeNominee records removal epoch**

```
uint256 maxAllowedTime = endTime + epochLen - 1 weeks;
        if (block.timestamp >= maxAllowedTime) {
            revert Overflow(block.timestamp, maxAllowedTime);
        }

        // Set the removed nominee epoch number
        mapRemovedNomineeEpochs[nomineeHash] = eCounter;
```

**Claim loop excludes removal epoch due to zero weight**

```
for (uint256 j = firstClaimedEpoch; j < lastClaimedEpoch; ++j) {
            // Get service staking info
            ITokenomics.StakingPoint memory stakingPoint =
                ITokenomics(tokenomics).mapEpochStakingPoints(j);

            uint256 endTime = ITokenomics(tokenomics).getEpochEndTime(j);

            // Get the staking weight for each epoch and the total weight
            // Epoch endTime is used to get the weights info, since otherwise there is a risk of having votes
            // accounted for from the next epoch
            // totalWeightSum is the overall veOLAS power (bias) across all the voting nominees
            (uint256 stakingWeight, uint256 totalWeightSum) =
                IVoteWeighting(voteWeighting).nomineeRelativeWeight(stakingTarget, chainId, endTime);
```

