# In retain function, checkpoint nominee function is not called which can cause zero amount of tokens being retained

Dispenser.retain() omits checkpointNominee before reading nomineeRelativeWeight, so stale weights yield zero staking weight and permanently forfeit retained OLAS incentives for those epochs.

- 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/56
- Library page: https://bugbountylibrary.com/r/c4%3A2024-05-olas%3AM-07
- Tags: area:web3 domain:web3 impact:funds-loss impact:integrity kind:contest platform:code4rena sev:medium tech:solidity technique:source-review vuln:accounting-error vuln:business-logic

**Target:** Dispenser.sol retain() in Olas tokenomics contracts
**Root cause:** retain() computes stakingWeight via nomineeRelativeWeight without first calling checkpointNominee(retainer), unlike calculateStakingIncentives; if the nominee's vote-weighting checkpoint is stale, the returned weight is zero.
**Steps:**
1. Deploy/observe retainer nominee whose vote-weighting checkpoint is not up to date for recent epochs.
2. Call `retain()` (permissionless) on Dispenser.sol#L1129.
3. Inside loop, `nomineeRelativeWeight(retainer, chainid, endTime)` returns stakingWeight = 0 for uncheckpointed epochs.
4. `stakingPoint.stakingIncentive * stakingWeight` = 0, totalReturnAmount stays 0, refundFromStaking skipped.
5. mapLastClaimedStakingEpochs[retainerHash] is advanced, so those epochs can never be retained again.
**How found:** Compared retain() against calculateStakingIncentives() and noticed the latter explicitly calls checkpointNominee before reading nomineeRelativeWeight, while retain() does not; reasoned that stale weights return zero and the last-claimed-epoch write makes the loss irreversible.
**Exploitation:** Any external caller can invoke retain() at a moment when the retainer's nominee weight is stale, causing the loop to compute zero weight for pending epochs and permanently mark them claimed, forfeiting the retainer's staking incentives (less OLAS minted).
**Insight:** When two functions read the same vote-weighting value, diff their preconditions: a checkpoint call present in one path but missing in a sibling path is a reliable stale-state bug, especially where a cursor is advanced afterward making the miss permanent.

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

**retain function missing checkpointNominee call**

```
function retain() external {
        // Reentrancy guard
        if (_locked > 1) {
            revert ReentrancyGuard();
        }
        _locked = 2;

        // Get first and last claimed epochs
        (uint256 firstClaimedEpoch, uint256 lastClaimedEpoch) =
            _checkpointNomineeAndGetClaimedEpochCounters(retainerHash, maxNumClaimingEpochs);

        // Write last claimed epoch counter to start retaining from the next time
        mapLastClaimedStakingEpochs[retainerHash] = lastClaimedEpoch;

        uint256 totalReturnAmount;

        // Go over epochs and retain funds to return back to the tokenomics
        for (uint256 j = firstClaimedEpoch; j < lastClaimedEpoch; ++j) {
            // Get service staking info
            ITokenomics.StakingPoint memory stakingPoint = ITokenomics(tokenomics).mapEpochStakingPoints(j);

            // Get epoch end time
            uint256 endTime = ITokenomics(tokenomics).getEpochEndTime(j);

            // Get the staking weight for each epoch
            (uint256 stakingWeight, ) = IVoteWeighting(voteWeighting).nomineeRelativeWeight(retainer,
                block.chainid, endTime);

            totalReturnAmount += stakingPoint.stakingIncentive * stakingWeight;
        }
        totalReturnAmount /= 1e18;

        if (totalReturnAmount > 0) {
            ITokenomics(tokenomics).refundFromStaking(totalReturnAmount);
        }
```

