{"id":"XE-16703","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"646","source_url":"https://github.com/xeprotocol/xe/issues/646","reporter_id":2920,"title":"[High] Duplicate Epoch numbers accepted; latestEpoch/epochAtFn pick nondeterministically, splitting consensus on emission parameters","area":"consensus","claimed_tier":"high","assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-17T05:15:28.103899+00:00","updated_at":"2026-11-22T23:26:17.207918+00:00","source_created_at":"2026-11-17T05:13:24+00:00","told_at":"2026-11-22T23:26:17.256971+00:00","status_changed_at":"2026-11-22T23:26:17.221470+00:00","url":"https://bounty.xe.network/XE-16703","body":"## Summary\nThe 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.\n\n## Root Cause\n- `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.\n- The oracle write-once guard in `AddBlock` is per key string (`epoch.<n>`), not per `Epoch` value.\n- `GetKVByPrefix` (`statechain/chain.go:337`) returns a Go `map[string]json.RawMessage` (random iteration order).\n- `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.\n- `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]`.\n\n## Impact\nLease emission and settlement amounts (`CapR`, `LeaseEmissionChecked`, `EpochLockTolerance = 3` consumers) diverge across nodes. A permanent, nondeterministic consensus split on money amounts.\n\n## Verification (executed PoC)\nHarness: standalone Go module with a `replace` to the repo (nothing written into the repo). Both blocks pass full `validateEpochValue` and full signature verification:\n```\nAddBlock epoch.5 (Epoch=7, R=2000, TWAP=250): err=<nil>\nAddBlock epoch.6 (Epoch=7, R=1900, TWAP=500): err=<nil>\nlatestEpoch() winners over 500 runs (keyed by R): map[1900:117 2000:383]  <- nondeterministic\nepochAtFn() first-two orderings over 200 runs (by R): map[1900,2000:53 2000,1900:147]  <- nondeterministic\n```\nAudited at HEAD `8cc209d` (testnet-0006).\n\n## Suggested fix\nIn `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.","patch_refs":[],"thread":[{"id":18883,"source":"desk","source_ref":"reply:16560","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-16703 and says what differs; it is read like any other.","created_at":"2026-11-22T23:26:17.207918+00:00"}]}