[High] Duplicate Epoch numbers accepted; latestEpoch/epochAtFn pick nondeterministically, splitting consensus on emission parameters
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 theEpochfield for uniqueness or monotonicity against already-stored epochs.- The oracle write-once guard in
AddBlockis per key string (epoch.<n>), not perEpochvalue. GetKVByPrefix(statechain/chain.go:337) returns a Gomap[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 unstablesort.Sliceby Epoch desc;EpochParamsAt(core/ledger.go:2157) usescandidates[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
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.