<!-- XE-0123 · 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) · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0123>. The page is the record; this is the same page for reading.*

XE-0123 · Bounty

# 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)

Triaging
claimed Medium
[xe#199](https://github.com/xeprotocol/xe/issues/199)
filed 2026-10-29 16:51 UTC
by hayokakoweda75

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   Medium

Area
:   Node / API

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-08 20:17 UTC

Told
:   2026-11-08 20:18 UTC

### Patches

- [xe#210](https://github.com/xeprotocol/xe/pull/210) open by NePreby
  fix(store): replace monolithic JSON array with indexed keys for pending-by-destination (fixes #199)

### History

- [43805](https://bounty.xe.network/log/43805) 2026-11-08 20:19 UTC reply.mirror\_failed
- [43369](https://bounty.xe.network/log/43369) 2026-11-08 20:18 UTC proposal.adopted
- [43368](https://bounty.xe.network/log/43368) 2026-11-08 20:18 UTC reply.sent
- [40449](https://bounty.xe.network/log/40449) 2026-11-08 20:17 UTC proposal.adopted
- [40448](https://bounty.xe.network/log/40448) 2026-11-08 20:17 UTC ticket.facts area
- [40447](https://bounty.xe.network/log/40447) 2026-11-08 20:17 UTC proposal.adopted
- [40446](https://bounty.xe.network/log/40446) 2026-11-08 20:17 UTC ticket.facts
- [40445](https://bounty.xe.network/log/40445) 2026-11-08 20:17 UTC proposal.adopted
- [40444](https://bounty.xe.network/log/40444) 2026-11-08 20:17 UTC ticket.facts
- [40443](https://bounty.xe.network/log/40443) 2026-11-08 20:17 UTC proposal.adopted
- [40442](https://bounty.xe.network/log/40442) 2026-11-08 20:17 UTC ticket.facts
- [40441](https://bounty.xe.network/log/40441) 2026-11-08 20:17 UTC proposal.adopted

[Full history](https://bounty.xe.network/log?ref=XE-0123) · [JSON](https://bounty.xe.network/v1/tickets/XE-0123) · [markdown](https://bounty.xe.network/XE-0123.md)

### Report

**Suggested severity: Medium (2,500 XE)**
**Area:** `store/badger_store.go` (pending-by-destination index), `core/ledger.go` (`validateAndAddSend`), `node/node.go` (`leaseWatchLoop`)
**Repo pin:** 9787859 (testnet-0005)

## Summary

The pending-by-destination index is a single JSON array per destination, rewritten in full on **every** send:

```
// store/badger_store.go:776-785
destHashes = append(destHashes, c.AddPending.SendHash)
destData, err := json.Marshal(destHashes)
...
if err := txn.Set(destKey, destData); err != nil { ... }
```

Reading it is symmetric — one value, then one `Get` per hash:

```
// store/badger_store.go:291-301
item, err := txn.Get(prefixedKey(prefixPendingDst, account))
...
return item.Value(func(val []byte) error { return json.Unmarshal(val, &hashes) })
```

A 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:

```
// node/node.go:1657-1665 — every node watches its own pending every 5 s
ticker := time.NewTicker(5 * time.Second)
...
n.leaseWatchTick(now, &n.wg)     // -> GetPendingForAccount(myAddr) -> GetPendingByDest -> N+1 Gets
```

## Measurements (probe against the shipped store)

Single destination, sequential sends:

```
2 000 sends: total 3.983 s, last commit 5.6 ms, GetPendingByDest 34 ms
4 000 sends: total 15.068 s, last commit 8.3 ms, GetPendingByDest 72 ms
```

Write 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.

## Attack

1. Pick any account with a public address (directory, gossip, explorer) — no key, no relationship.
2. 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).
3. 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.
4. 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.

## Suggested fix

- Replace the per-destination JSON array with bucket keys (`prefixPendingDst | dest | page`), so a write touches one bounded page instead of the whole index.
- Cap pending entries per sender (and per destination), and expire them at the consensus level (timestamp \+ rule), not only when received.
- Paginate `GetPendingByDest` and stop `leaseWatchTick` from materialising the full list when the page is unchanged.

### Thread

**Joseph Denne**team2026-11-08 20:17 UTCdesk

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.
