{"id":"XE-0267","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"244","source_url":"https://github.com/xeprotocol/xe/issues/244","reporter_id":121,"title":"net/sync: frontiers request above 1 MiB is truncated; fresh sync stalls at ~7,800 accounts","area":null,"claimed_tier":"high","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-02T22:50:04.634397+00:00","updated_at":"2026-11-05T04:17:56.177314+00:00","source_created_at":"2026-11-02T22:48:24+00:00","told_at":null,"status_changed_at":"2026-11-05T04:17:39.227653+00:00","url":"https://bounty.xe.network/XE-0267","body":"# net/sync: frontiers request above 1 MiB is truncated; fresh sync stalls at ~7,800 accounts\n\nSuggested tier: **High** (Medium fallback). Availability/recovery only; no state,\nfinality, or supply divergence.\n\n## Summary\n\nA `net/sync` request carries the requester's entire frontiers map as one JSON\nobject. The server reads at most `maxSyncRequestBytes = 1<<20` (1 MiB) and then\ndecodes JSON. If the map crosses 7,824 entries (first failing wire size 7,825\nincluding `json.Encoder.Encode`'s trailing newline; wire size is the\n`json.Marshal` length + 1 B) **while the requester still has missing blocks**, the\nrequest is truncated mid-object, `json.Decoder` returns `unexpected EOF`, and\n`handleSyncStream` returns without sending a response. The requester cannot\nfetch the remaining blocks through that path.\n\nThis is conditional, not universal. `r-013` (8,501 accounts) converges because\nits final batch fits before the boundary. It does not depend on dependency\norder; ascending order still stalls at the crossing (`r-015`).\n\n## Target\n\n- Pinned commit: `978785929bc17a2f4ab30c383e5fc9cf4d634512`\n- Unmodified binary SHA-256:\n  `c3bbf2612ab282fd31ea9b78eec109e9554a260b4ca6e6aa6e01d9fb04ff1f34`\n- Network: `t104b-lab` (custom local genesis)\n- Ledger genesis:\n  `be79a8c7fa04ebb76f2fba9d8e9d5311007544029876a3c3e3e534aeb2fa0d16`\n- Statechain genesis:\n  `cdac6a19f67c2a8f38c426570992ed91fd82aceb4dbb4490fcc13452be3fc0fb`\n- Activation state: tip 0, no active features, protocol 1.0.0\n- Store/topology: Badger; loopback API/metrics; `--disable-mdns --no-discovery`\n\n## Preconditions\n\nAn honest server, a client that sends its full frontiers map, and missing blocks\nremaining when the map first exceeds 1 MiB. No attacker is required.\n\n## Invariant\n\nA valid full-frontiers request is accepted up to the protocol's own\n`maxFrontiers` or rejected explicitly. A server parse rejection must not be\nrecorded as a successful empty round. A fresh node with one honest peer reaches\nthe server tip in bounded rounds.\n\n## Unmodified-target wire proof (`r-029` / `r-031`)\n\nThe unmodified target server (`xe/9787859`) served a 9,001-account / 54,001-block\nchain. A rebuilt `lab/tools/syncprobe` sent one request with synthetic 64-hex\nfrontiers:\n\n| Frontiers | `json.Marshal` bytes | Wire bytes (+1 B newline) | Result |\n|---:|---:|---:|---|\n| 7,800 | 1,045,230 | 1,045,231 | decoded: 157 pages / 10,000 blocks |\n| 7,900 | 1,058,630 | 1,058,631 | 0 pages / 0 blocks; server `sync: decode request: unexpected EOF` |\n| 8,000 | 1,072,030 | 1,072,031 | over the limit |\n| 8,335 | 1,116,920 | 1,116,921 | over the limit |\n| 10,001 | 1,340,164 | 1,340,165 | over the limit |\n\nLimit: `1,048,576 B`. First failing entry count: **7,825 including the newline**.\n\n`/node` before and after: `xe/9787859`, `network_id=t104b-lab`,\n`block_count=54,001`, `accounts=9,001`, `pow_difficulty=fffff80000000000`.\nThe server flags were `--data <copy of chain>/data --genesis-dir <chain>/genesis\n--port 23000 --api --api-bind 127.0.0.1 --api-port 23100 --metrics-addr\n127.0.0.1:23200 --disable-mdns --no-discovery`.\n\nReproduction: `lab/scenarios/t-104b/probe-request-cap.sh <chain> <run-id>`; a\ncopy is `r-029/run.sh` and `r-031/run.sh`. Probe source SHA-256:\n`4ee9b1d72fc484b014944301010ebdf16418d083473f100dd0face81c45938dd`; probe\nbinary SHA-256:\n`f20c2513c2bf268d744d5f89ac1e0cfe2245ad740ff44908e72c09b4ad8ea933`.\nThe synthetic frontiers match the real 64-hex frontier shape and length; they do\nnot name real accounts, so the probe measures decode/start behavior, not real\nsync data for those keys.\n\nThe 9k chain's blocks are low-PoW lab data generated with `-difficulty low`; the\nunmodified server only serves the already-stored chain, and the probe does not\napply or validate the blocks. The request-reader path under test is independent\nof PoW; the `/node` `pow_difficulty` is the server's configured difficulty, not\nthe stored blocks' difficulty. The pinned target has the same request reader\nand 64-hex frontier shape; the live build (`xe/4f19518`) was not source-audited,\nso live reachability is inferred.\n\n## End-to-end stall (instrumented, single observed run)\n\n`r-015`: 9,001 accounts / 54,001 blocks, `XE_DIFFICULTY=low`,\n`XE_SYNC_ORDER=chain_asc`. The client applies 50,000 blocks in five rounds,\nthen applies 0 in two further rounds and stalls at 8,335/9,001 accounts with\n4,000 blocks still missing; the server logs `decode request: unexpected EOF`.\nThe instrumentation changes ordering, logging, and PoW difficulty only; the\nrequest reader and EOF handling are unchanged. This is one observed run; `r-013`\nis the converging counterexample.\n\n## Client-side false success (code reading)\n\n`net/sync.go:565-569` treats a clean server EOF as a normal end of response;\n`net/sync.go:334-337,375-377` records the caller's **own** frontiers under the\npeer ID and returns success. This false-success path was not observed end-to-end\non the unmodified target; the unmodified observation is the wire boundary.\n\n## Root cause\n\n- `net/sync.go:31`: `maxSyncRequestBytes = 1 << 20`.\n- `net/sync.go:430`: `json.NewDecoder(io.LimitReader(s, maxSyncRequestBytes))`.\n- `net/sync.go:431-436`: decode error logs and returns; no error response.\n- `net/sync.go:544-554`: the client sends\n  `SyncRequest{Frontiers: ledger.Frontiers(), PageSize: ...}` as one JSON object.\n- `net/sync.go:438-449`: `maxFrontiers` trimming happens after a successful\n  decode, so it cannot protect the reader.\n- `net/sync.go:565-569`: EOF is treated as a normal end; the caller records the\n  round as successful.\n\n## Impact\n\nA node that crosses the cap with missing blocks cannot ask for them through this\npath. Fresh onboarding and post-loss recovery are the affected cases. A mature\nnode that already holds the chain may still log repeated decode errors, but has\nnothing missing. Live reachability is inferred from 26,513 live accounts; the\nlive build (`xe/4f19518`) was not source-audited. No funds, finality, or supply\neffect.\n\n## Duplicate cross-references\n\n- **#219 / PR #223** cover the 10,000-block **response** cap's\n  terminal/continuation signal and a readiness false-green. PR #223 adds\n  `Truncated`/`HasMore` handling and convergence accounting but does **not**\n  change `maxSyncRequestBytes` or the request reader. This report is the 1 MiB\n  **request** cap.\n- **#196** is the statechain **response** byte cap; **#8 finding 4** is\n  nil-block/empty-page amplification; **#44/#59** are sync-client\n  allocation/resource issues; **#60** is the SIGTERM/shutdown hang.\n- No existing issue was found for truncating the frontiers request at 1 MiB.\n\n## Suggested fix\n\nPaginate or stream the frontiers map (e.g., hash-range cursors), or raise the\nrequest cap above one full map. Return an explicit error response on decode\nfailure so the client does not record a false success. Add a regression test\nthat builds a ledger with 10k+ accounts and round-trips a sync request at the\n1 MiB boundary.\n\n## Payout\n\nXE address: `b50f71f5ad1743456550ad7bd7720e18ce3a271f1c73eb90c56a79915404521b`\n","patch_refs":[{"id":242,"repo":"xeprotocol/xe","kind":"pr","ref":"249","title":"fix(core,store,net): atomic genesis final-height commit/repair and sync request/dependency convergence (fixes #244, #245, #246)","url":"https://github.com/xeprotocol/xe/pull/249","note":"","state":"open","author":"Khanhtnq","added_by":"desk","created_at":"2026-11-03T14:28:53.094909+00:00"}],"thread":[]}