Bounty
XE-10574 · Bounty

Statechain sync client: syncMaxBlocks (10,000) counts only successful adds — failing blocks processed in full, one uncapped Warn per block

Closed · duplicate —claimed Medium web filed 2026-11-12 14:52 UTC by xe:9ad024a8

Report

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

Summary

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

Mechanism

dec := json.NewDecoder(io.LimitReader(s, syncMaxResponseSize)) // 10 MiB total
for {
    var resp syncResponse
    if err := dec.Decode(&resp); err != nil { ... }
    for _, b := range resp.Blocks {
        if err := chain.AddBlock(b); err != nil {
            logging.Warnf("statechain sync: block %d: %v", b.Index, err) // per block, no cap
        } else {
            added++
        }
    }
    if !resp.HasMore { break }
    if added >= syncMaxBlocks { break }   // failures never increment `added`
}

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

Impact

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

Proof of concept

Verified 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:

control: 200-block page   -> exactly 200 GetStateBlock calls
attack:  20,000-block single page (4 MB, inside the 10 MiB budget)
         -> exactly 20,000 GetStateBlock calls (20,000 AddBlock attempts,
            20,000 Warn log lines)
--- PASS (0.50s)

That is 2× the documented syncMaxBlocks = 10000 ceiling in one response at PoC size, ~5× at the byte-budget limit.

Reproduce:

cd xe && go test ./statechain/ -run TestR3Statechain -v -count=1

Suggested fix

Count 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).

Relation to existing reports

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

Thread

Joseph Denneteam2026-11-20 00:04 UTCdesk

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-10574 and says what differs; it is read like any other.