<!-- XE-16703 · [High] Duplicate Epoch numbers accepted; latestEpoch/epochAtFn pick nondeterministically, splitting consensus on emission parameters · testnet -->
*Markdown view of <https://bounty.xe.network/XE-16703>. The page is the record; this is the same page for reading.*

XE-16703 · Bounty

# \[High\] Duplicate Epoch numbers accepted; latestEpoch/epochAtFn pick nondeterministically, splitting consensus on emission parameters

Closed · duplicate
—claimed High
[xe#646](https://github.com/xeprotocol/xe/issues/646)
filed 2026-11-17 05:13 UTC
by kecedanzz77-bit

Verdict
:   Duplicate

Tier
:   —

Claimed
:   High

Area
:   Consensus

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-22 23:26 UTC

Told
:   2026-11-22 23:26 UTC

### Patches

None linked.

### History

- [770289](https://bounty.xe.network/log/770289) 2026-11-22 23:26 UTC reply.mirror\_failed
- [770119](https://bounty.xe.network/log/770119) 2026-11-22 23:26 UTC proposal.adopted
- [770118](https://bounty.xe.network/log/770118) 2026-11-22 23:26 UTC reply.sent
- [770117](https://bounty.xe.network/log/770117) 2026-11-22 23:26 UTC proposal.adopted
- [770116](https://bounty.xe.network/log/770116) 2026-11-22 23:26 UTC ticket.status new → closed
- [769369](https://bounty.xe.network/log/769369) 2026-11-22 23:26 UTC proposal.adopted
- [769368](https://bounty.xe.network/log/769368) 2026-11-22 23:26 UTC ticket.facts area
- [769367](https://bounty.xe.network/log/769367) 2026-11-22 23:26 UTC proposal.adopted
- [769366](https://bounty.xe.network/log/769366) 2026-11-22 23:26 UTC ticket.facts
- [769365](https://bounty.xe.network/log/769365) 2026-11-22 23:26 UTC proposal.adopted
- [769364](https://bounty.xe.network/log/769364) 2026-11-22 23:26 UTC ticket.facts
- [766064](https://bounty.xe.network/log/766064) 2026-11-22 23:17 UTC note.added

[Full history](https://bounty.xe.network/log?ref=XE-16703) · [JSON](https://bounty.xe.network/v1/tickets/XE-16703) · [markdown](https://bounty.xe.network/XE-16703.md)

### Report

## Summary

The oracle can publish two different epoch keys (`epoch.5`, `epoch.6`) carrying the same `Epoch` number but different R / TWAP / payout-cap values. Nothing validates `Epoch` uniqueness or monotonicity, and every consumer that selects "the latest epoch" is nondeterministic (Go map iteration order \+ unstable sort). Honest nodes with identical chain state compute different emission parameters \-- a permanent, nondeterministic consensus split on money amounts, triggered by two validly-signed oracle blocks. The shipped genesis makes `sys.oracle` 1-of-1, so a single compromised oracle key can do this with no DAO involvement. Epoch keys are write-once, so the conflicting entries can never be corrected.

## Root Cause

- `validateEpochValue` (`statechain/kvstore.go:350`) validates StartNS\<EndNS, phase, TWAP\>0, payout-cap range, R-values and RSource, but never checks the `Epoch` field for uniqueness or monotonicity against already-stored epochs.
- The oracle write-once guard in `AddBlock` is per key string (`epoch.<n>`), not per `Epoch` value.
- `GetKVByPrefix` (`statechain/chain.go:337`) returns a Go `map[string]json.RawMessage` (random iteration order).
- `latestEpoch` (`node/node.go:391-405`) iterates that map and keeps the first max Epoch (strict `>` comparison, so ties keep whichever the random map order surfaced first). `epochRFn` / `epochPayoutCapFn` / `epochTWAPFn` (`node/node.go:407-427`) all derive from it.
- `epochAtFn` (`node/node.go:429-457`) builds candidates from the same map and sorts with unstable `sort.Slice` by Epoch desc; `EpochParamsAt` (`core/ledger.go:2157`) uses `candidates[0]`.

## Impact

Lease emission and settlement amounts (`CapR`, `LeaseEmissionChecked`, `EpochLockTolerance = 3` consumers) diverge across nodes. A permanent, nondeterministic consensus split on money amounts.

## Verification (executed PoC)

Harness: standalone Go module with a `replace` to the repo (nothing written into the repo). Both blocks pass full `validateEpochValue` and full signature verification:

```
AddBlock epoch.5 (Epoch=7, R=2000, TWAP=250): err=<nil>
AddBlock epoch.6 (Epoch=7, R=1900, TWAP=500): err=<nil>
latestEpoch() winners over 500 runs (keyed by R): map[1900:117 2000:383]  <- nondeterministic
epochAtFn() first-two orderings over 200 runs (by R): map[1900,2000:53 2000,1900:147]  <- nondeterministic
```

Audited at HEAD `8cc209d` (testnet-0006).

## Suggested fix

In `validateEpochValue`/oracle admission: reject an epoch value whose `Epoch` already exists under any other key, and require `Epoch` strictly greater than all existing epochs. Defense-in-depth: make consumers deterministic regardless \-- `latestEpoch` should break ties deterministically (e.g. lexicographically smallest key), and `epochAtFn` should use `sort.SliceStable` with a deterministic tie-break.

### Thread

**Joseph Denne**team2026-11-22 23:26 UTCdesk

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the
first verifiable submission, so this one closes as a duplicate. If you believe it is a different
bug, file a new report that links https://bounty.xe.network/XE-16703 and says what differs; it is read like any other.
