<!-- XE-13264 · net/sync: syncTracker recreates per-peer state after removePeer, leaking a full frontier map per throwaway peer ID · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13264>. The page is the record; this is the same page for reading.*

XE-13264 · Bounty

# net/sync: syncTracker recreates per-peer state after removePeer, leaking a full frontier map per throwaway peer ID

Triaging
[xe#388](https://github.com/xeprotocol/xe/issues/388)
filed 2026-11-11 12:57 UTC
by jalesfeva

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   —

Area
:   P2P / sync

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-21 08:12 UTC

Told
:   2026-11-20 00:15 UTC

### Patches

- [xe#415](https://github.com/xeprotocol/xe/pull/415) open by arturbarszcz78
  fix(net/sync): prevent peer state resurrection after disconnect and bound rejections (#388)

### History

- [547513](https://bounty.xe.network/log/547513) 2026-11-20 00:16 UTC github.labels
- [546177](https://bounty.xe.network/log/546177) 2026-11-20 00:15 UTC reply.mirrored
- [546003](https://bounty.xe.network/log/546003) 2026-11-20 00:15 UTC proposal.adopted
- [546002](https://bounty.xe.network/log/546002) 2026-11-20 00:15 UTC ticket.award
- [545920](https://bounty.xe.network/log/545920) 2026-11-20 00:15 UTC proposal.adopted
- [545919](https://bounty.xe.network/log/545919) 2026-11-20 00:15 UTC reply.sent
- [545839](https://bounty.xe.network/log/545839) 2026-11-20 00:15 UTC proposal.adopted
- [545838](https://bounty.xe.network/log/545838) 2026-11-20 00:15 UTC ticket.status new → triaging
- [545501](https://bounty.xe.network/log/545501) 2026-11-20 00:15 UTC proposal.adopted
- [545500](https://bounty.xe.network/log/545500) 2026-11-20 00:15 UTC ticket.facts area
- [545499](https://bounty.xe.network/log/545499) 2026-11-20 00:15 UTC proposal.adopted
- [545498](https://bounty.xe.network/log/545498) 2026-11-20 00:15 UTC ticket.facts

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

### Report

## Summary

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

## Affected code

| Location | Fact |
| --- | --- |
| `net/sync.go:70-72,84-86` | `lastFrontiers map[peer.ID]map[string]string` and initialisation |
| `net/sync.go:127-136` | `recordSync` copies the whole frontier map and assigns `st.lastFrontiers[pid] = cp`, no liveness check |
| `net/sync.go:145-150` | `removePeer` — the only cleaner (`delete` over three maps) |
| `net/sync.go:320-342` | `ConnectedF` → `requestSync` → `recordSync` (336); `DisconnectedF` → `removePeer` (341) |
| `net/sync.go:345-376` | periodic resync path, second `recordSync` call site (376) |
| `net/sync.go:602-604,648` | apply loop of up to 10 passes over up to 10,000 blocks; `requestSync` always returns nil |
| `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) |

## Reproduction

1. Connect to a node with a fresh libp2p identity (identities are free; connection limits are per IP, so a handful of identities suffice).
2. Serve a terminal page plus blocks so the apply loop runs, then close the connection during the apply phase.
3. `DisconnectedF` → `removePeer(pid)` runs first; `recordSync(pid, ledger.Frontiers())` then resurrects `lastFrontiers[pid]`.
4. Repeat with new peer IDs; each iteration leaves one full frontier-map copy that nothing can delete.

## Evidence

- No liveness guard in `recordSync` (`net/sync.go:127-136`).
- `removePeer` has exactly one call site (`net/sync.go:341`); no other path deletes these entries.
- 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).
- 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.

## Impact

Monotonic, 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.

## Suggested fix

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

## Notes

- **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`).
- **Evidence status:** code-level plus scratch harness heap measurements; no end-to-end run against the live testnet.
- **XE Address for Reward:** `b83e7e31358b8c1e1509de6cd34e7540425eb17a190e48b486909df11080033d`

> Reward address updated to the official desk-bound address.

### Thread

**Joseph Denne**team2026-11-20 00:15 UTCgithub

Thanks for the report. We have read it against the code and it is being handled. The assessment and any award follow the fix.

**jalesfeva**2026-11-21 08:12 UTCweb

Thanks for the update, I'll wait for the fix and assessment
