{"id":"XE-16810","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"660","source_url":"https://github.com/xeprotocol/xe/issues/660","reporter_id":2708,"title":"[BugBounty][High] Oracle epoch with TWAP above $950 collapses all lease emissions to 1 µXE — validateEpochValue has no TWAP upper bound and no R floor","area":"leasing-ledger","claimed_tier":"high","assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":true,"internal_ref":"#1120","internal_url":"https://github.com/xeprotocol/core/issues/1120","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-17T06:18:09.376240+00:00","updated_at":"2026-11-22T23:27:19.579579+00:00","source_created_at":"2026-11-17T06:17:31+00:00","told_at":"2026-11-22T23:26:13+00:00","status_changed_at":"2026-11-22T23:26:05.571089+00:00","url":"https://bounty.xe.network/XE-16810","body":"**Target:** `github.com/xeprotocol/xe` @ `8cc209d` (\"release: testnet-0006 build\")\n**Severity: High — CVSS 3.1: 6.5** (`AV:N/AC:H/PR:H/UI:N/S:U/C:N/I:H/A:H`)\n**Reporter:** brikzeni / lolopapa3491@gmail.com — payout XE address `1522be0b3fd8bd46da1021c3e090b7a4b9cdbe8e3eed2c55e66a4440aab07b0e`\n**Program area:** LEASING / LEDGER, CONSENSUS\n\n### Summary\n`validateEpochValue` (`statechain/kvstore.go:350`) has **no upper bound on `TWAPMilliUSD`** and **no floor on any R value**. The collusion factor is computed by integer division — `expectedRCollusion(twap, s, factor) = factor*(1000-s)/twap` — so once TWAP exceeds $950 (phase 1), the expected collusion R floors to **0**, and an epoch carrying `RVolume = RPriceFloor = RCollusion = REffective = 0` passes every check. `CapR(0, cap, twap)` is 0, so `LeaseEmissionChecked` returns its **1 µXE minimum** for every lease, regardless of cost. A single 1-of-1 oracle key can publish four such epochs, evicting every sane epoch from the `EpochLockTolerance+1 = 4` candidate window in `epochAtFn`, after which **every lease accepted network-wide locks 1 µXE emissions permanently** — a 99.9% cut (1,034 µXE → 1 µXE for a standard 517-cost lease) that no later sane epoch can repair for those leases.\n\n### Relationship to #372 — disclosed up front\nThis is the same *class* as open #372 (\"Unbounded oracle R + TWAP=0 disables the lease payout cap\"), but a **distinct vector with a distinct fix**, and it survives the testnet-0006 fix for #372:\n- #372's vectors were **R unbounded upward** (R=1e9) and **TWAP=0** (cap disabled). Both are fixed in 0006: `RVolume`/`RPriceFloor`/`REffective` are capped at `RInit = 2000`, and `TWAP == 0` is rejected. Verified by the controls in this PoC (RVolume=2001 rejected, TWAP=0 rejected).\n- This vector is the **opposite direction**: TWAP unbounded **upward** (never mentioned in #372 — its PoC used TWAP=0) and R with **no floor**. The fix #372 suggested (\"bound R to a sane maximum, reject TWAP==0\") does not cover it; the fix here is a **TWAP ceiling** (or requiring `expectedRCollusion > 0`) plus an **R floor** (`REffective`/`RVolume`/`RPriceFloor ≥ RFloor = 100`).\n- It is also distinct from #646 (duplicate Epoch numbers — nondeterministic split; #646's suggested fix, uniqueness/strictly-greater Epoch, does **not** stop this: the poisoned epochs have distinct, increasing Epoch numbers) and from #377/#175 (locking a *past* epoch's higher R — this publishes a *new* poisoned epoch).\n\n### Root cause\n`statechain/kvstore.go:350-460`, `validateEpochValue`:\n1. `TWAPMilliUSD == 0` is rejected (line 359) — but there is **no upper bound**. Any TWAP is accepted.\n2. `expectedRCollusion` (`kvstore.go:455`) is `factor*(1000-s)/twap` in integer arithmetic. Phase 1 (`s = 0`, `factor = 950`): `950000/twap`. At TWAP = 950,001 milli-USD ($950.001) this is **0**. The check requires `RCollusion == expectedRCollusion` exactly — so at TWAP > $950, `RCollusion` **must be 0** to pass. (Phase 2, `s = 300`: threshold is $665.)\n3. `REffective` must equal `supportive = max(RVolume, RPriceFloor)` unless `RCollusion` is non-zero and smaller. With `RVolume = RPriceFloor = RCollusion = 0`, `expectedR = 0`, so `REffective = 0` passes.\n4. No check anywhere requires any R value to be > 0 (tokenomics defines `RFloor = 100`, but it is never enforced in `validateEpochValue`).\n5. `RSource = \"tied\"` passes trivially (`0 == 0`; its `RCollusion < supportive` guard is skipped when `RCollusion == 0`).\nNet: the validator *forces* R=0 at high TWAP instead of rejecting it.\n\nDownstream (`core/ledger.go:2168-2242`): `CapR(0, payoutCap, twap) = min(0, ceil(cap*1000/twap)) = 0`; `LeaseEmissionChecked(cost, 0)` returns the **1 µXE floor**. `epochAtFn` (`node/node.go:429-457`) takes the 4 most recent epochs (`EpochLockTolerance+1`); four sequential poisoned epochs evict all sane epochs from the window, so `validateLockedEmissionAt` can only lock poisoned params. `latestEpoch` (`node/node.go:391-405`) likewise returns the poisoned epoch. Leases lock their params at accept time and there is no re-lock path, so leases accepted during the poisoned window are **permanently** underpaid.\n\n### Proof (local, real code — no live testnet)\nStandalone Go module (module `xer6oracle`, `replace` to the xe checkout @ `8cc209d`). It builds a local in-memory statechain from a self-authored genesis (own throwaway oracle key, threshold 1 — the validation rules under test do not depend on which key signs, only that `verifyOracleMultisig` passes for the configured keyset), then calls the real `statechain.Chain.AddBlock` and the real `core.CapR` / `core.LeaseEmissionChecked`. Run `go test -v .` — **5/5 PASS**:\n- `TestPoisonedEpochAccepted`: Poisoned epoch.2 (TWAP=1e9, R=0) **ACCEPTED**; epochs 3–5 accepted; `latestEpoch` = poisoned epoch 5 (R=0, TWAP=1e9); all 4 `epochAtFn` candidates poisoned; sane emission **1,034 µXE** → poisoned emission **1 µXE** for a 517-cost lease.\n- `TestAbsurdEpochNumberAccepted`: A single epoch with `Epoch = 2^64-1` **ACCEPTED** and permanently wins `latestEpoch` (no uniqueness/monotonicity/sequence check; #646's suggested fix would not prevent it — 2^64-1 *is* strictly greater and unique).\n- `TestZeroRWithSaneTWAPAccepted`: R=0 **rejected** at TWAP=250 (`r_collusion (0) != expected 3800`) and at TWAP=950,000 (`!= expected 1`); R=0 **ACCEPTED** at TWAP=950,001 — the exact threshold is pinned (TWAP > $950 phase 1, $665 phase 2).\n- `TestEpochValidationControls`: TWAP=0 rejected; RVolume=2001 rejected; duplicate key `epoch.1` rejected (write-once); non-oracle signer rejected — the harness discriminates.\n- `TestForgedAttestationRejected`: 2 forged sigs (trusted pubkeys, random sigs) rejected; non-trusted signer rejected; 1 valid + 1 forged rejected (below 2-of-3 threshold); stale (1h) attestations rejected on the live path, accepted on the sync path (known #19 behaviour).\n\nPoisoned epoch value used (JSON): `{\"epoch\":2,\"start_ns\":0,\"end_ns\":1099511627776,\"twap_milli_usd\":1000000000, \"r_volume\":0,\"r_price_floor\":0,\"r_collusion\":0,\"r_effective\":0, \"r_source\":\"tied\",\"phase\":1,\"s_milli\":0,\"payout_cap\":1120}`\n\n### Impact\n- **Every provider, network-wide.** Four poisoned epochs (one oracle key, four blocks) collapse the emission of every lease accepted afterwards to 1 µXE — a 99.9% pay cut (1,034 → 1 µXE on a standard lease). Providers earn ~nothing while still delivering the VM.\n- **Permanent for leases in the window.** Locked params are fixed at accept; no re-lock exists. A lease accepted while the window is poisoned settles for 1 µXE even after the oracle is rotated and sane epochs resume.\n- **Slow, DAO-only recovery.** The DAO (2-of-3) can rotate `sys.oracle` (DAO blocks may write `sys.oracle`; only the `epoch.*` prefix is DAO-forbidden, `chain.go:210`) and the new oracle must publish 4 sane epochs with higher Epoch numbers before the window heals. Until then the network's provider economy is halted.\n- **Deterministic, not probabilistic.** Unlike #646's nondeterministic split, every node computes the same poisoned params — the damage is uniform and total.\n\nHonest limits, stated up front:\n- Exploitation requires the **1-of-1 oracle private key** (compromise, insider, or misconfiguration) — the same precondition as #372 and #646, both accepted as in-scope findings. Without the key, nothing here is reachable. This is a single-point-of-failure / missing-validation issue, not a remotely exploitable bug — which is why it is High, not Critical.\n- The live testnet's `sys.oracle` is 1-of-1 by genesis design (one key, threshold 1). No new key material is claimed; the live oracle key was never touched.\n- The absurd-`Epoch` observation is only harmful combined with poisoned R values (with sane R it merely pins `latestEpoch`); it is reported as a supporting observation, not a separate finding.\n\n### Suggested fix\nIn `validateEpochValue` (`statechain/kvstore.go`):\n1. **TWAP ceiling:** reject `TWAPMilliUSD` above a sane maximum (e.g. a tokenomics-derived cap), or equivalently require `expectedRCollusion > 0` — a TWAP so high that the collusion factor floors to zero is not a price.\n2. **R floor:** require `RVolume`, `RPriceFloor`, and `REffective` to be ≥ `RFloor` (tokenomics already defines `RFloor = 100`; enforce it here), and require `RCollusion > 0` whenever `expectedRCollusion > 0` (already implied by the equality check at sane TWAPs — the ceiling in (1) makes it hold everywhere).\n3. **(Defence in depth)** Consider an `Epoch` sanity bound (e.g. reject `Epoch` values wildly ahead of the current tip) and raising the oracle threshold above 1 — the same 1-of-1 key underlies #372, #646, and this report.","patch_refs":[],"thread":[{"id":11914,"source":"github","source_ref":"6977156203","author":"brikzeni","team":false,"body":"Correction to the CVSS score stated in this report: it should be **5.9, not 6.5**.\n\nRe-checking my own scoring, the stated vector is `AV:N/AC:H/PR:H/UI:N/S:U/C:N/I:H/A:H`. With the CVSS 3.1 FIRST formula:\n\n- Impact: ISC = 1 − (1−0) × (1−0.56) × (1−0.56) = 0.8064, so 6.42 × 0.8064 = 5.18\n- Exploitability: 8.22 × 0.85 (AV:N) × 0.44 (AC:H) × 0.27 (PR:H) × 0.85 (UI:N) = 0.71\n- Base score: roundup(5.18 + 0.71) = **5.9**\n\nThe 6.5 figure corresponds to AC:L (0.77), not the AC:H (0.44) in the stated vector. The vector itself is unchanged, and nothing else in the report changes: the finding, the reproduction steps, and the PoC (5/5 passing) stand as submitted. I leave the severity tier to triage.\n\nNote: the related issue #802 uses AC:L in its vector, and its 6.5 is computed correctly — this correction does not affect #802. Apologies for the error.","created_at":"2026-11-18T11:24:11+00:00"},{"id":17925,"source":"github","source_ref":"7066417621","author":"kinoy-1","team":false,"body":"Additional evidence for #660 (same root cause — `validateEpochValue` has no TWAP upper bound). #660's poisoned epoch zeroes R. The same missing bound collapses emissions to the 1 micro-XE floor even when R is left at the sane maximum — no R-zeroing is needed at all. The crush comes from the other side of the same formula: `CapR` divides the payout cap by the absurd TWAP, so `R_capped` floors to 1 while `R = 2000`. Not a new issue.\n\nRepo: github.com/xeprotocol/xe @ `8cc209d` (testnet-0006). Comment by kinoy-1 (XE payout address `19f0b012f28b5954679765cad3c5795380fabec1f050f7a57e1f4dc34caf13c7` — for reference only; this is evidence on #660, not a new claim).\n\n## PoC (local only, real code, no live testnet contact, no funds)\n\nEpoch accepted by the real `validateEpochValue` (`statechain/kvstore.go:350`):\n\n```json\n{\"epoch\":2,\"start_ns\":0,\"end_ns\":1000000000,\"twap_milli_usd\":1000000000,\n \"r_volume\":2000,\"r_price_floor\":2000,\"r_collusion\":0,\n \"r_effective\":2000,\"r_source\":\"tied\",\"phase\":1,\"s_milli\":0,\"payout_cap\":1527}\n```\n\nWhy it passes every check in `validateEpochValue`:\n\n- `TWAP == 0` is rejected but there is no upper bound — `TWAP = 1e9` passes.\n- `expectedRCollusion = 950*(1000-0)/1e9 = 0` (integer floor), so `RCollusion = 0` matches exactly.\n- `RCollusion == 0` skips the `RCollusion < supportive` guards; `REffective = supportive = max(2000, 2000) = 2000` passes.\n- `RSource = \"tied\"`: `RVolume == RPriceFloor` (2000 == 2000); its collusion guard is skipped when `RCollusion == 0`.\n- `RVolume (2000) <= RInit (2000)`, `RPriceFloor (2000) <= tier1 (2000)`, `PayoutCap (1527)` in `[1120, 1550]`, `SMilli (0)` matches phase 1.\n\nDownstream (`core/ledger.go:2168` `CapR`, `:2184` `LeaseEmissionChecked`), standard 60s 1-vCPU lease, cost 517 mXCU:\n\n- `CapR(2000, 1527, 1000000000) = ceil(1527*1000/1e9) = 1`\n- `LeaseEmissionChecked(517, 1) = ceil(517*1/1000) = 1` micro-XE\n- Control at the live sane TWAP: `CapR(2000, 1527, 250) = 2000`, emission `1034` micro-XE.\n\nSo a lease locking this epoch settles for 1 micro-XE instead of 1034 — a 99.9% pay cut — with R at its full sane value. (At TWAP = $1,000 the same payload gives `CapR = 2`, emission 2 micro-XE; the collapse scales with TWAP.)\n\nReproduction: `git checkout 8cc209d`, add the test below as `statechain/poc_d_test.go`, `go test ./statechain/ -run TestPOC_D_HighTWAPNonzeroR -v -count=1` — PASS (2026-11-22): epoch ACCEPTED, CapR=1, emission=1 (sane: 1034).\n\n```go\npackage statechain\n\nimport (\n\t\"encoding/json\"\n\t\"testing\"\n\n\t\"github.com/xeprotocol/xe/core\"\n)\n\nfunc TestPOC_D_HighTWAPNonzeroR(t *testing.T) {\n\tev := EpochValue{\n\t\tEpoch: 2, StartNS: 0, EndNS: 1000000000,\n\t\tTWAPMilliUSD: 1000000000, // $1,000,000\n\t\tRVolume: 2000, RPriceFloor: 2000, RCollusion: 0, REffective: 2000,\n\t\tRSource: \"tied\", Phase: 1, SMilli: 0, PayoutCap: 1527,\n\t}\n\traw, _ := json.Marshal(ev)\n\tif err := validateEpochValue(raw, nil); err != nil {\n\t\tt.Fatalf(\"high-TWAP sane-R epoch REJECTED (fix present?): %v\", err)\n\t}\n\tcapped := core.CapR(2000, 1527, 1000000000)\n\tem, _ := core.LeaseEmissionChecked(517, capped)\n\tif em != 1 {\n\t\tt.Fatalf(\"expected 1 uXE floor, got %d\", em)\n\t}\n\tif c2 := core.CapR(2000, 1527, 250); c2 != 2000 {\n\t\tt.Fatalf(\"control CapR at TWAP 250 = %d, want 2000\", c2)\n\t}\n}\n```\n\nSame root cause as #660, same suggested fix (a TWAP ceiling, or requiring `expectedRCollusion > 0`), same 1-of-1 oracle precondition, same permanent lock-in for leases accepted in the window. Live sane reference (2026-11-22, `ldn.core.test.network/statechain/kv`): `epoch.1`: `twap_milli_usd 250, r_effective 2000, r_collusion 3800, payout_cap 1527` — the control values above match the live network.","created_at":"2026-11-21T17:21:17+00:00"},{"id":18699,"source":"github","source_ref":"7087572291","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-16810 and says what differs; it is read like any other.","created_at":"2026-11-22T23:26:13+00:00"}]}