# User is unable to claim their reward for the expanded epochs if farm is expanded

Claiming during preliminary_end_epoch sets LAST_CLAIMED_EPOCH past it, so a later farm expansion leaves the user unable to claim rewards for the expanded epoch.

- Payout: Audit contest
- Severity: medium
- Program: MANTRA
- Credited: 0xRajkumar
- Disclosed: 2025-03-31
- Write-up quality: 6/10
- Original: https://code4rena.com/reports/2024-11-mantra-dex#m-03
- Library page: https://bugbountylibrary.com/r/c4%3A2024-11-mantra-dex%3AM-03
- Tags: domain:web3 impact:funds-loss kind:contest platform:code4rena sev:medium tech:rust technique:source-review vuln:accounting-error vuln:business-logic

**Target:** CosmWasm farm-manager claim/expand_farm commands
**Root cause:** claim() advances LAST_CLAIMED_EPOCH to the current epoch even though compute_farm_emissions caps emissions at preliminary_end_epoch-1; expand_farm can later raise preliminary_end_epoch, but the user's cursor already skipped those epochs.
**Steps:**
1. Farm configured start_epoch=1, preliminary_end_epoch=2, farm_expiration_time=1h, epoch=1 day.
2. User with position in epoch 1 calls claim during epoch 2; emissions computed only up to epoch 1, LAST_CLAIMED_EPOCH set to 2.
3. Farm owner calls expand_farm in epoch 2, raising preliminary_end_epoch to 3.
4. User claims in epoch 3; loop starts at LAST_CLAIMED_EPOCH+1=3, so epoch 2 reward is never paid.
**How found:** Code reading of is_farm_expired showing expansion is allowed after preliminary_end_epoch, combined with compute_farm_emissions capping at preliminary_end_epoch-1 while claim still advances LAST_CLAIMED_EPOCH to current epoch.
**Exploitation:** Farm owner (or timing) expands the farm after a user claims during the preliminary_end_epoch window; the user's last_claimed_epoch cursor skips the newly added epoch, permanently forfeiting that epoch's emission.
**Escalation:** Issue extends to a second epoch if the user claims between farm_ending_at and farm_ending_at+farm_expiration_time and expansion happens in that same window.
**Insight:** When a claim cursor is advanced to the current epoch but emission computation is capped by a mutable end-epoch, check whether that end-epoch can be extended later; the gap between cursor and cap is unclaimable.
