{"id":"XE-10574","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":1587,"title":"Statechain sync client: syncMaxBlocks (10,000) counts only successful adds — failing blocks processed in full, one uncapped Warn per block","area":"p2p-sync","claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":true,"internal_ref":"#1112","internal_url":"https://github.com/xeprotocol/core/issues/1112","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-12T14:52:08.111227+00:00","updated_at":"2026-11-20T00:04:40.171763+00:00","source_created_at":null,"told_at":"2026-11-20T00:04:40.195400+00:00","status_changed_at":"2026-11-20T00:04:40.179268+00:00","url":"https://bounty.xe.network/XE-10574","body":"# Statechain sync client: `syncMaxBlocks` (10,000) counts only successful adds — a page of failing blocks is processed in full, with one uncapped Warn log line per block\n\n## Summary\n\nThe statechain sync client's block ceiling counts successes only, so it never bounds the work a hostile response can force (`xeprotocol/xe`, HEAD 89a542e, testnet-0005). In `requestSync` (`statechain/sync.go:168-192`), every block in a response page is passed to `chain.AddBlock`; the counter `added` increments only on success, and the `added >= syncMaxBlocks` break (line 188) therefore never fires for a page of blocks that all fail. A page of failing blocks is processed in full — the only bound is how many blocks fit in the cumulative 10 MiB stream budget (~50k at the ~200-byte block size used in the PoC, more for smaller encodings). Each attempt is not cheap: `Chain.AddBlock` takes the chain mutex, runs `VerifyBlockHash` (canonical marshal + SHA-256), a store lookup, and — on the fork path — a fresh `DAOKeyset()` load/parse. The client also emits one Warn log line per failing block with no cap (line 180; contrast the ledger sync client, which caps rejection logging at 3). The round is re-triggered on every peer connection and by `ResyncOnGap`.\n\n## Mechanism\n\n```go\ndec := json.NewDecoder(io.LimitReader(s, syncMaxResponseSize)) // 10 MiB total\nfor {\n    var resp syncResponse\n    if err := dec.Decode(&resp); err != nil { ... }\n    for _, b := range resp.Blocks {\n        if err := chain.AddBlock(b); err != nil {\n            logging.Warnf(\"statechain sync: block %d: %v\", b.Index, err) // per block, no cap\n        } else {\n            added++\n        }\n    }\n    if !resp.HasMore { break }\n    if added >= syncMaxBlocks { break }   // failures never increment `added`\n}\n```\n\nUnlike the ledger client, the byte budget here is cumulative for the whole stream — but the block ceiling counts successes only, so failing blocks are effectively uncounted work plus an unbounded log flood.\n\n## Impact\n\nUnauthenticated CPU + log-flood from a single response, repeatable on connect / gap-resync (30 s backoffs bound the cadence). Suggested tier: **Medium (2,500 XE)**, low end — Minor is defensible if the byte budget is weighed heavily.\n\n## Proof of concept\n\nVerified in `xe/statechain/poc_r3_pagecap_test.go` — `TestR3StatechainSyncFailedBlocksBypassMaxBlocks`. The PoC drives the **real** `requestSync` against a hostile libp2p server with an in-memory counting `StateChainStore` (exactly one `GetStateBlock` per `AddBlock` attempt on the fork-rejection path). Blocks are hash-valid, `Index 0`, with hashes differing from the stored genesis, so every one is rejected as a fork:\n\n```\ncontrol: 200-block page   -> exactly 200 GetStateBlock calls\nattack:  20,000-block single page (4 MB, inside the 10 MiB budget)\n         -> exactly 20,000 GetStateBlock calls (20,000 AddBlock attempts,\n            20,000 Warn log lines)\n--- PASS (0.50s)\n```\n\nThat is 2× the documented `syncMaxBlocks = 10000` ceiling in one response at PoC size, ~5× at the byte-budget limit.\n\nReproduce:\n\n```\ncd xe && go test ./statechain/ -run TestR3Statechain -v -count=1\n```\n\n## Suggested fix\n\nCount *attempted* blocks (or total decoded blocks) toward `syncMaxBlocks`, not just successes; cap `len(resp.Blocks)` per page; rate-limit/sample the per-block Warn (e.g. first N per round, as the ledger client does).\n\n## Relation to existing reports\n\nNot XE-4845 (nil block in a statechain-sync response — a crash; different mechanism), not XE-4827 (spin on *empty* `HasMore=true` pages — zero blocks per page; here pages are full), not XE-5233 (server-side zero-progress loop in `handleSyncStream` plus lock contention), not XE-2878 (the same invalid block re-verified *across* rounds for lack of a quarantine — this defect is within a single response and persists even with a quarantine, because the cap itself never counts failures), not XE-0120 (server response byte cap / page-size mismatch). Adjacencies flagged explicitly for triage.","patch_refs":[],"thread":[{"id":12831,"source":"desk","source_ref":"reply:10853","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-10574 and says what differs; it is read like any other.","created_at":"2026-11-20T00:04:40.171763+00:00"}]}