{"id":"XE-0137","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"229","source_url":"https://github.com/xeprotocol/xe/issues/229","reporter_id":44,"title":"[Track 1 Bug Bounty] Descendant-receive race in conflict-resolution swap → supply inflation (plan→apply window skips pending-send destinations)","area":"consensus","claimed_tier":null,"assessed_tier":"high","verdict":"likely-valid","duplicate_of":null,"tracked":true,"internal_ref":"#1229","internal_url":"https://github.com/xeprotocol/core/issues/1229","status":"patched","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-31T07:48:30.888610+00:00","updated_at":"2026-11-24T19:03:44.295985+00:00","source_created_at":"2026-10-31T07:47:45+00:00","told_at":"2026-11-20T13:12:50+00:00","status_changed_at":"2026-11-24T19:03:14.446153+00:00","url":"https://bounty.xe.network/XE-0137","body":"[Track 1 Bug Bounty] Descendant-receive race in conflict-resolution swap → supply inflation (plan→apply window skips pending-send destinations)\n\n## Summary\n\nTwo compounding defects in the conflict-resolution path let a receive that lands **inside** the swap's plan→apply window survive the cascade, leaving the destination holding tokens from a send the resolved chain no longer contains — i.e. balance inflation. Proven on master `9787859` with deterministic and statistical PoCs (public gist: https://gist.github.com/ox-code/8f403d80d2161866d1c65e118f370443).\n\n## Root cause (two defects)\n\n**Defect 1 — incomplete receive gate** (`core/ledger.go:1102`):\n\n```go\nif src := l.GetBlockOrStaged(b.Source); src != nil {\n\tif l.GetConflict(src.Account, src.Previous) != nil {\n\t\treturn fmt.Errorf(\"source send %s is contested by an unresolved conflict — receive deferred pending resolution\", ...)\n\t}\n}\n```\n\nThe gate defers a receive only when the SEND ITSELF is a conflict participant (`GetConflict` at the send's own `previous`). A send that is a **descendant** of a conflicted block passes: the conflict is registered at the fork point `(X, P)`, while the check looks at `(X, L.Hash)` — the send's own previous.\n\n**Defect 2 — plan/skip race in the cascade** (`core/ledger.go:2889-2975`):\n\n`swapBlockLocked` builds its rollback plan from **unlocked** reads. For each descendant send it checks `GetPendingSend(b.Hash)`; if the send is pending, the destination is **skipped** (assumed not-yet-credited). Foreign-account locks are acquired only *after* planning, and skipped destinations are neither locked, snapshotted, nor rolled back. If a receive resolves the pending send **after** the plan read but **before/during** the cascade apply, the destination keeps tokens from a send the resolved chain no longer contains.\n\nWhen the receive lands *before* the plan, the cascade behaves correctly (the pending send is already resolved, the destination is included in the plan and unwound) — the machinery works; the gate and the window are the flaw.\n\n## Evidence (all on master 9787859, includes #9 hardening)\n\n- **poc5 (deterministic)**: with a conflict open at `(X,P)`, a receive of the descendant send `S1` is accepted — `GetConflict(X, L.Hash) = nil` while `(X,P)` is open. The gate gap, demonstrated without any race.\n- **poc6 (statistical)**: 300 iterations racing `SwapBlock` against the receive → **6 BUG** (destination kept the tokens), 222 safe (receive preceded the plan → unwound), 72 rejected.\n- **poc6b (state dump, single-shot)**: hit on attempt 0 —\n\n```\nX chain (len=2): mint send            <- S1 dropped by the swap\nD chain (len=1): receive(src=080582e7) <- receive of S1 survived\npending send S1 record exists: false\nX XUSD: 930000 | D XUSD: 1000 | E XUSD: 0\n```\n\n  The resolved chain (mint 1,000,000 → W) supports 930,000 at X + 70,000 pending to E. D's 1,000 is recognized by the ledger but supported by no block: **1,000 XUSD created from nothing** (amount is attacker-controlled up to the pending send's size).\n- **Perpetuity check**: a fresh ledger rebuilt on the same store still recognizes D's 1,000 XUSD — the inflation survives restart on the producing node.\n\n## Impact\n\n- **Supply inflation**: ledger-recognized balances exceed what the resolved chain supports; perpetual on the producing node (verified via rebuild).\n- **Two reachable shapes**:\n  1. *Attacker-driven*: attacker forks their own account, wins/forces resolution, and lands the receive inside the window (spamming receives raises the hit rate; the window widens with descendant count — 40 descendants in the PoC).\n  2. *Honest network*: any user receiving during any conflict resolution on the sender's account can be credited from a rolled-back send — a safety violation with no attacker at all.\n- No theft of existing funds; the gain is minted value.\n\n## Relation to #226 / #227\n\n#226 (cascade unwind stale store reads; SwapBlock credential bypass) and its fix PR #227 address *lease-state staleness* and *credential verification* inside the same function family. This report is a distinct defect: the pending-**send** destination skip plus the receive-gate ancestry gap, with a different failure mode (supply inflation via a race window) and a different fix. I checked #227's diff — it does not touch the plan/skip logic or the receive gate (its only `GetPendingSend` mention is a test mock). #227 is open and does not fix this bug.\n\n## Suggested fix direction\n\n- Gate on **ancestry**: defer the receive if any conflict exists on the send's account at or before the send's height (`GetConflictsForAccount(src.Account)` + height compare), not only at the send's own `previous`.\n- Or close the window: re-check `GetPendingSend` for every skipped destination inside the cascade apply (under the destination's lock), or acquire destination locks *before* planning.\n\n## Severity\n\nHigh — \"Races, replays & state transitions\" tier (race condition / TOCTOU). Honest bounds: the per-event amount is bounded by the pending send's size, there is no direct theft, and exploitation requires a receive landing inside the conflict-resolution window (PoC hit rate 2% with a tight local loop; the window is real but narrow). The balance-inflation class is noted; I am not claiming the Critical tier because of the bounded amount and the concurrency precondition.\n\n## Affected version\n\nmaster `9787859`. PoCs are Go programs (`go build && go run`) against a local `MemStore` ledger — no network setup needed.\n\nResearcher: oxcode\n","patch_refs":[{"id":232,"repo":"xeprotocol/xe","kind":"pr","ref":"231","title":"fix(core): prevent supply inflation from descendant-receive race in conflict-resolution swap (fixes #229)","url":"https://github.com/xeprotocol/xe/pull/231","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-10-31T10:12:34.599981+00:00"}],"thread":[{"id":818,"source":"github","source_ref":"6719916844","author":"Joseph Denne","team":true,"body":"Thank you for the report. We have reviewed the behaviour you describe against the current tree and it is being handled; we will update this ticket as the work progresses.","created_at":"2026-11-08T09:39:40+00:00"},{"id":14656,"source":"github","source_ref":"7040422105","author":"XE desk","team":true,"body":"Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is\nupdated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0137.","created_at":"2026-11-20T13:12:50+00:00"},{"id":20660,"source":"github","source_ref":"7154370944","author":"ncgeja","team":false,"body":"Status note — not a new report. The desk marks XE-0137 patched, but the fix PR xeprotocol/xe#231 is still open (not merged), and both defects are still present verbatim in the public tree at testnet-0006 HEAD 8cc209d: (1) validateAndAddReceive (core/ledger.go:1159–1163) checks only GetConflict(src.Account, src.Previous) — the source send's own previous, no ancestry check; (2) planSwap (ledger.go:3303) skips a pending send when planning the unwind, and swapBlockLocked (:3200–3247) plans first and acquires the foreign locks after, never re-checking GetPendingSend under lock. Either the patch landed somewhere the public tree doesn't show, or the patched status is premature.","created_at":"2026-11-25T06:01:52+00:00"}]}