{"id":"XE-13360","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"384","source_url":"https://github.com/xeprotocol/xe/issues/384","reporter_id":2132,"title":"[Medium] Pending sends never expire, have no cap, and cost ~nothing — permanent state bloat via reclaimable dust","area":null,"claimed_tier":"medium","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":true,"internal_ref":"","internal_url":null,"status":"accepted","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:11.693724+00:00","updated_at":"2026-11-18T08:56:08.264154+00:00","source_created_at":"2026-11-11T12:52:00+00:00","told_at":"2026-11-18T08:55:07+00:00","status_changed_at":"2026-11-18T08:39:45.850666+00:00","url":"https://bounty.xe.network/XE-13360","body":"### Summary\n\nA pending send, once admitted, lives **forever** in every node's state. There is no expiry/TTL/pruning, no per-account or global cap on pending sends, and the minimum send amount is 1 micro-XE (the only check in `validateAndAddSend` is `amount == 0`). Creating a pending costs one 32-bit PoW solve (~2^25 hashes at the live difficulty) plus 1 micro-XE locked in the pending — and that micro is **fully reclaimable**, because the attacker names their own second account as destination and receives it back. Net XE cost of a permanent pool entry: **0**. There is no transaction fee anywhere in the codebase. The only cost is PoW, which parallelises perfectly across cores/machines.\n\n### Impact\n\n- **Permanent, unbounded state growth on every node.** Pending entries are stored in Badger (`prefixPending` 0x03 + destination index 0x04, `store/badger_store.go:182-340`) and deleted only by a receive (`DeletePendingID`) or a rollback/swap unwind. Nothing else ever removes them. Disk, memory, startup load and every pool-wide read grow forever.\n- **Live network already shows the shape of it.** On testnet-0005 (LDN, read-only GETs, 11 Nov 2026): **332,011 pending sends vs 865,339 blocks (~38%)**, and the pool grew **+329 entries in ~40 min** (332,011 → 332,340) while blocks grew +1,205. Random sample of 1,000 pendings: **90% are ≤ 1,000 micro-XE, 4.8% exactly 1 micro-XE; 39.2% older than 7 days; oldest ~19 days (23 Oct 2026) and still unclaimed**. One source holds 79/1,000 sampled pendings (1 XE each to 79 distinct destinations). This looks like organic accumulation today, not an attack — which is the point: the protocol has no mechanism that would stop it becoming one.\n- **Every pool-wide read pays the full price.** `GET /pending` calls `GetAllPending()` (full Badger range scan) before slicing the page (`api/handler.go:622-625`); node observability also counts the whole pool per scrape (`node/observability.go:213`). The 2.05 s `/pending` response at 332k entries (see #70/#215 for the same pattern on other endpoints) gets slower as the pool grows, and the pool can only grow.\n- **Availability, not funds.** No XE is stolen and consensus does not break; the damage is resource exhaustion / node degradation. Hence Medium, not higher.\n\n### Root cause (repo `github.com/xeprotocol/xe`, commit `89a542ea51d38375299aee54c6c99102e9bfa666`)\n\n1. `PendingSend` (`core/types.go:141`) carries **no timestamp/expiry field at all** — there is nothing to expire against. A repo-wide grep for expir/TTL/prune/purge touching pending returns nothing.\n2. `validateAndAddSend` (`core/ledger.go:972`) rejects only `amount == 0`, self-sends, and insufficient balance. No minimum amount above 1 micro, no per-account pending count check, no global cap.\n3. `validateAndAddReceive` (`core/ledger.go:1081`) is SOUND and is not the issue: it rejects a receive unless `pending.Destination == receiver` (:1097), credits exactly `pending.Amount` via the balance check (:1145), and deletes the pending atomically (:1156). No cross-account claim, no double-claim, no wrong-amount receive — verified by code read.\n4. No fee exists anywhere (grep for \"fee\" in `core/`, `node/`, `api/` returns nothing relevant), so PoW is the only gate — and the live difficulty `0xfffff80000000000` (`pow_difficulty` on LDN) means ~2^25 (~33.5M) blake2b hashes per block.\n\n### PoC (all tests PASS)\n\nFile: `core/xe06_pending_dust_test.go` (test-only, no production code changed). Run with `TMPDIR=$HOME/workspace/xe-audit/tmp GOPROXY=direct go test ./core/ -run TestXE06 -v`:\n\n- `TestXE06DustSendAccepted` — a 1-micro-XE send is admitted and creates a pending entry.\n- `TestXE06NoPerAccountPendingCap` — **200 dust sends from a single account to 200 distinct destinations, all admitted**; pool = 200, no cap fires.\n- `TestXE06PendingNeverExpires` — a pending created at T is **still fully claimable at T + 365 days** (receive succeeds; balance credited).\n- `TestXE06DustFullyReclaimable` — attacker sends 1 micro to their own alt account, receives it back, sends it back to the source: **source balance restored to exactly 1,000,000** — net XE cost of a pool entry is 0.\n- `TestXE06PoWCostAtLiveDifficulty` — measured (this sandbox is slow/shared, so absolute seconds are a sandbox number; the invariant is the hash count): single-core 0.23 MHash/s → ~144 s/solve; 4 workers aggregate 0.28 MHash/s → ~122 s/solve. On unthrottled hardware the same 2^25 hashes take seconds, and the work parallelises perfectly — the binding constraint is aggregate hash power, not XE.\n\nHonest limits: the PoC proves ledger acceptance and zero net XE cost, not a live flood — no load test was run (forbidden by the bounty scope) and no live transaction was sent. The live numbers above are read-only observations, and the +329/40 min growth is consistent with organic traffic as well as low-rate dust; the vulnerability is the **absence of any bound**, proven in code, not a demonstrated live flood.\n\n### Fix suggestion\n\n- Add an expiry to pending sends (e.g. TTL in blocks/time, after which the send is prunable and the sender's funds are reclaimable via a cancel/reclaim path — today there is no way for a sender to reclaim an unclaimed send at all).\n- Or enforce a minimum send amount and/or a per-account pending cap.\n- Or charge a fee / raise PoW for dust amounts. Any one of these bounds the pool; expiry + reclaim is the cleanest since it also fixes the stranded-funds side effect.\n\n### Distinct from\n\n- #70 / #215 / #365 / #78 — pagination/full-lattice cost of the read endpoints. This report is about the **state itself** (unbounded, never-expiring pool), not the cost of reading it; fixing pagination would not shrink the pool.\n- #347 — pre-notice of a latency measurement on `GET /pending`, not a finding.\n- #312 (dust XUSD receives vs DAO vote snapshot), #53 (PoW-gated gossip spam), #156 (directory TTL), #161 (votes persisted forever), #247 (chat messages map) — different subsystems/mechanisms.\n- #323 (receive timestamp skew) — different; receive validation was checked here and is sound on destination/amount/double-claim.\n\n### Environment\n\n- Codebase: `github.com/xeprotocol/xe` @ `89a542e` (2026-11-10)\n- Go 1.25.0, `go test` as above, local reproduction only (live testnet used only for read-only observations)\n\nXE payout address: e3d3e4407fec5a846201c7ed8560484ffb881cc30068745a110dd8efb824500c","patch_refs":[{"id":734,"repo":"xeprotocol/xe","kind":"pr","ref":"883","title":"fix(xe): medium--pending-sends-never-e (fixes #384)","url":"https://github.com/xeprotocol/xe/pull/883","note":"","state":"open","author":"tipprb","added_by":"desk","created_at":"2026-11-19T19:16:06.717808+00:00"}],"thread":[{"id":11553,"source":"github","source_ref":"6973756161","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-13360.","created_at":"2026-11-18T08:55:07+00:00"}]}