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)
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
- Pick any account with a public address (directory, gossip, explorer) — no key, no relationship.
- 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).
- 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.
- 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
GetPendingByDestand stopleaseWatchTickfrom materialising the full list when the page is unchanged.
Thread
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.