{"id":"XE-0123","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"199","source_url":"https://github.com/xeprotocol/xe/issues/199","reporter_id":39,"title":"store: pending-by-destination index is one JSON array rewritten per send — a few thousand 1-unit sends pin any node's 5 s watch loop forever (Θ(N²) writes, no expiry)","area":"node-api","claimed_tier":"medium","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T16:51:36.805248+00:00","updated_at":"2026-11-08T20:17:41.885067+00:00","source_created_at":"2026-10-29T16:51:18+00:00","told_at":"2026-11-08T20:18:40.224930+00:00","status_changed_at":"2026-11-08T20:17:52.079304+00:00","url":"https://bounty.xe.network/XE-0123","body":"**Suggested severity: Medium (2,500 XE)**\n**Area:** `store/badger_store.go` (pending-by-destination index), `core/ledger.go` (`validateAndAddSend`), `node/node.go` (`leaseWatchLoop`)\n**Repo pin:** 9787859 (testnet-0005)\n\n## Summary\n\nThe pending-by-destination index is a single JSON array per destination, rewritten in full on **every** send:\n\n```go\n// store/badger_store.go:776-785\ndestHashes = append(destHashes, c.AddPending.SendHash)\ndestData, err := json.Marshal(destHashes)\n...\nif err := txn.Set(destKey, destData); err != nil { ... }\n```\n\nReading it is symmetric — one value, then one `Get` per hash:\n\n```go\n// store/badger_store.go:291-301\nitem, err := txn.Get(prefixedKey(prefixPendingDst, account))\n...\nreturn item.Value(func(val []byte) error { return json.Unmarshal(val, &hashes) })\n```\n\nA send needs only the **sender's** signature (`validateAndAddSend`, `core/ledger.go:972-1023`); the destination is arbitrary, the minimum amount is one base unit, and there is no fee and no pending expiry. So a third party can grow any address's index without that account's participation, and the account's own node pays for it:\n\n```go\n// node/node.go:1657-1665 — every node watches its own pending every 5 s\nticker := time.NewTicker(5 * time.Second)\n...\nn.leaseWatchTick(now, &n.wg)     // -> GetPendingForAccount(myAddr) -> GetPendingByDest -> N+1 Gets\n```\n\n## Measurements (probe against the shipped store)\n\nSingle destination, sequential sends:\n\n```\n2 000 sends: total 3.983 s, last commit 5.6 ms, GetPendingByDest 34 ms\n4 000 sends: total 15.068 s, last commit 8.3 ms, GetPendingByDest 72 ms\n```\n\nWrite cost is Θ(N) per send and Θ(N²) overall (4× time for 2× N); read cost is Θ(N) and is paid **every 5 s** by the destination's node.\n\n## Attack\n\n1. Pick any account with a public address (directory, gossip, explorer) — no key, no relationship.\n2. Send 1 base unit to it N times (N sends cost N × one block; a few thousand cost well under 1 XE at the current fee/PoW settings).\n3. Every node holding that account now does N+1 DB reads + a 67·N-byte JSON decode every 5 s, forever: entries never expire and are only removed when the destination receives.\n4. 20 000 sends (≈0.02 XE) ⇒ ~20 000 Gets + ~1.3 MB decode per tick per node — a targeted, permanent DoS on any node that watches that account, plus Θ(N²) write amplification on **every** node in the network.\n\n## Suggested fix\n\n- Replace the per-destination JSON array with bucket keys (`prefixPendingDst | dest | page`), so a write touches one bounded page instead of the whole index.\n- Cap pending entries per sender (and per destination), and expire them at the consensus level (timestamp + rule), not only when received.\n- Paginate `GetPendingByDest` and stop `leaseWatchTick` from materialising the full list when the page is unchanged.\n","patch_refs":[{"id":210,"repo":"xeprotocol/xe","kind":"pr","ref":"210","title":"fix(store): replace monolithic JSON array with indexed keys for pending-by-destination (fixes #199)","url":"https://github.com/xeprotocol/xe/pull/210","note":"","state":"open","author":"NePreby","added_by":"desk","created_at":"2026-10-29T18:09:53.842569+00:00"}],"thread":[{"id":1596,"source":"desk","source_ref":"reply:512","author":"Joseph Denne","team":true,"body":"Thanks for the report and the measurements. We have confirmed the storage behaviour you describe and it is being handled; we will update this ticket when there is a fix to point at.","created_at":"2026-11-08T20:17:41.885067+00:00"}]}