# Farms can be created to start in past epochs

MANTRA farm-manager's validate_farm_epochs omitted a check that start_epoch be in the future, letting anyone create retroactive farms and skew reward distribution.

- Payout: Audit contest
- Severity: high
- Program: MANTRA
- Found by: Abdessamed
- Disclosed: 2025-03-31
- Write-up quality: 6/10
- Original: https://code4rena.com/reports/2024-11-mantra-dex#h-05
- Library page: https://bugbountylibrary.com/r/c4%3A2024-11-mantra-dex%3AH-05
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:rust technique:source-review vuln:accounting-error vuln:business-logic vuln:reward-distribution

**Target:** CosmWasm farm-manager contract, validate_farm_epochs in helpers.rs
**Root cause:** validate_farm_epochs only checks start_epoch > 0, start < end, end > current_epoch, and start <= current_epoch + buffer; it never enforces start_epoch >= current_epoch + 1, so past start epochs pass.
**Steps:**
1. Advance chain to epoch 10 via `add_one_epoch()` x10.
2. Call `manage_farm` with `FarmAction::Fill` and `FarmParams { start_epoch: Some(1), preliminary_end_epoch: Some(28), ... }`.
3. Transaction succeeds instead of reverting, creating a farm retroactively starting at epoch 1.
**How found:** Code review of validate_farm_epochs against the stated invariant that per-epoch rewards are proportional to locked LP share; noticed the missing lower-bound check on start_epoch relative to current_epoch and confirmed with an integration test.
**Exploitation:** Attacker creates a farm with a start_epoch in the past, retroactively assigning rewards to already-elapsed epochs; users who already claimed for those epochs miss the newly assigned rewards, breaking the proportional-share invariant and misallocating farm_asset funds.
**Insight:** When auditing epoch/period-based reward contracts, enumerate every bound on the period parameters (start, end, buffer) and check each against the invariant; a missing lower bound on start lets rewards be assigned to already-settled periods.

