{"id":"XE-13264","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"388","source_url":"https://github.com/xeprotocol/xe/issues/388","reporter_id":1787,"title":"net/sync: syncTracker recreates per-peer state after removePeer, leaking a full frontier map per throwaway peer ID","area":"p2p-sync","claimed_tier":null,"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-11-14T20:42:05.567947+00:00","updated_at":"2026-11-21T08:12:10.633815+00:00","source_created_at":"2026-11-11T12:57:10+00:00","told_at":"2026-11-20T00:15:40+00:00","status_changed_at":"2026-11-20T00:15:28.772196+00:00","url":"https://bounty.xe.network/XE-13264","body":"## Summary\n\n`syncTracker.recordSync` stores a full copy of the local frontier map keyed by peer ID without checking that the connection still exists. `removePeer` is called only from `DisconnectedF`, so a disconnect that happens while `requestSync` is still running removes the entry first and the later `recordSync` recreates it. No second `DisconnectedF` fires for that peer ID, so the copy survives for the process lifetime. The window is not a narrow race: the apply phase (up to 10 retries over up to 10,000 blocks) runs before `recordSync` and performs no network I/O, so the peer can disconnect at leisure while the node applies attacker-chosen blocks. `recordRejections` has the same shape with a narrower window.\n\n## Affected code\n\n| Location | Fact |\n|---|---|\n| `net/sync.go:70-72,84-86` | `lastFrontiers map[peer.ID]map[string]string` and initialisation |\n| `net/sync.go:127-136` | `recordSync` copies the whole frontier map and assigns `st.lastFrontiers[pid] = cp`, no liveness check |\n| `net/sync.go:145-150` | `removePeer` — the only cleaner (`delete` over three maps) |\n| `net/sync.go:320-342` | `ConnectedF` → `requestSync` → `recordSync` (336); `DisconnectedF` → `removePeer` (341) |\n| `net/sync.go:345-376` | periodic resync path, second `recordSync` call site (376) |\n| `net/sync.go:602-604,648` | apply loop of up to 10 passes over up to 10,000 blocks; `requestSync` always returns nil |\n| `net/messages.go:21-26`, `net/sync.go:556-563` | `SyncResponse.Rejected []string` has no element/length bound (up to 10 MB decoded per page) |\n\n## Reproduction\n\n1. Connect to a node with a fresh libp2p identity (identities are free; connection limits are per IP, so a handful of identities suffice).\n2. Serve a terminal page plus blocks so the apply loop runs, then close the connection during the apply phase.\n3. `DisconnectedF` → `removePeer(pid)` runs first; `recordSync(pid, ledger.Frontiers())` then resurrects `lastFrontiers[pid]`.\n4. Repeat with new peer IDs; each iteration leaves one full frontier-map copy that nothing can delete.\n\n## Evidence\n\n- No liveness guard in `recordSync` (`net/sync.go:127-136`).\n- `removePeer` has exactly one call site (`net/sync.go:341`); no other path deletes these entries.\n- Harness result on the pinned commit: two leak assertions FAIL (state resurrected for a disconnected peer) and two control assertions PASS (full-copy-per-peer confirmed; healthy delete confirmed).\n- Per-identity cost measured on the same scratch harness: `recordSync` ≈ 82.6 KB at a 1,000-account lattice and ≈ 1.31 MB at 20,000 accounts (≈ 65 B per entry); the `Rejected` amplification path ≈ 5.75 MB per identity with 50,000 attacker-chosen strings.\n\n## Impact\n\nMonotonic, attacker-paced memory growth on every syncing node, keyed on identities that cost nothing to mint. Enough identities exhaust RAM; the state persists until restart.\n\n## Suggested fix\n\nCheck connection liveness inside `recordSync` (or gate it on a disconnect generation counter), bound the `Rejected` list length, and make the disconnect handler authoritative regardless of callback ordering.\n\n## Notes\n\n- **Duplicate check:** checked issues — no duplicate as of 2026-11-11 (closest: #59 in-flight guard OOM within one round, #44 per-round page allocation, #254/#265 dirty-flag poisoning via `MarkDirtyFromPeer`, #219/#245 truncation/retry, #223 `recordSync` timing semantics; none covers state resurrected after `removePeer`).\n- **Evidence status:** code-level plus scratch harness heap measurements; no end-to-end run against the live testnet.\n- **XE Address for Reward:** `b83e7e31358b8c1e1509de6cd34e7540425eb17a190e48b486909df11080033d`\n\n\n\n> Reward address updated to the official desk-bound address.\n","patch_refs":[{"id":555,"repo":"xeprotocol/xe","kind":"pr","ref":"415","title":"fix(net/sync): prevent peer state resurrection after disconnect and bound rejections (#388)","url":"https://github.com/xeprotocol/xe/pull/415","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-11-14T20:42:20.081226+00:00"}],"thread":[{"id":12890,"source":"github","source_ref":"7026048955","author":"Joseph Denne","team":true,"body":"Thanks for the report. We have read it against the code and it is being handled. The assessment and any award follow the fix.","created_at":"2026-11-20T00:15:40+00:00"},{"id":16453,"source":"web","source_ref":"reporter:1787:8c94c6e939c0e5d0","author":"jalesfeva","team":false,"body":"Thanks for the update, I'll wait for the fix and assessment","created_at":"2026-11-21T08:12:10.619290+00:00"}]}