# distributeYield() calls earningsTrancheuse() with outdated emaSTT & emaJTT while calculating senior & junior tranche yield distributions

ZivoeYDL.distributeYield() computes senior/junior tranche splits using stale emaSTT/emaJTT, updated only after earningsTrancheuse(), misallocating yield between tranches.

- Payout: Contest reward
- Severity: medium
- Program: Zivoe
- Credited: Ironsidesec
- Disclosed: 2024-03-19
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-03-zivoe-judging/issues/54
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-03-zivoe%3AM-3
- Tags: domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:evm tech:solidity technique:source-review vuln:business-logic vuln:reward-distribution

**Target:** ZivoeYDL yield distribution contract (Solidity)
**Root cause:** distributeYield() calls earningsTrancheuse() before recomputing emaSTT/emaJTT, so yieldTarget, seniorProportion and juniorProportion use EMA values from the prior distribution period instead of current adjusted supplies.
**Steps:**
1. Read ZivoeYDL.distributeYield() L229-239: earningsTrancheuse() invoked at L232, emaSTT/emaJTT updated at L238-239.
2. Observe earningsTrancheuse() L459-465 passes emaSTT/emaJTT into MATH.yieldTarget(), MATH.seniorProportion(), MATH.juniorProportion().
3. Note first distribution uses values from 60 days prior (unlock() L328-331) widening error.
4. Compare computed senior/junior split against split using freshly updated EMA to see tranche over/underpayment.
5. Fix: move adjustedSupplies()/MATH.ema updates before the earningsTrancheuse() call.
**How found:** Code-reading of distributeYield() ordering: noticed earningsTrancheuse() consumes emaSTT/emaJTT globals that are only written after the call returns, making the distribution math lag one period.
**Insight:** When auditing yield/reward accounting, check ordering of state updates vs. reads of smoothing variables (EMA, TWAP, accumulators) — a read-before-write of a lagging average silently misprices shares even without an external attacker.
