<!-- XE-10571 · Ledger sync client: maxTotalBlocks (10,000) checked only between pages — one in-budget page forces unbounded per-block processing · testnet -->
*Markdown view of <https://bounty.xe.network/XE-10571>. The page is the record; this is the same page for reading.*

XE-10571 · Bounty

# Ledger sync client: maxTotalBlocks (10,000) checked only between pages — one in-budget page forces unbounded per-block processing

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

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Medium

Area
:   P2P / sync

Duplicate of
:   [XE-0023](https://bounty.xe.network/XE-0023) awarded

Tracked
:   internally

Updated
:   2026-11-20 00:04 UTC

Told
:   2026-11-20 00:04 UTC

### Patches

None linked.

### History

- [543242](https://bounty.xe.network/log/543242) 2026-11-20 00:04 UTC proposal.adopted
- [543241](https://bounty.xe.network/log/543241) 2026-11-20 00:04 UTC reply.sent
- [543240](https://bounty.xe.network/log/543240) 2026-11-20 00:04 UTC ticket.status new → closed
- [541536](https://bounty.xe.network/log/541536) 2026-11-20 00:04 UTC proposal.adopted
- [541535](https://bounty.xe.network/log/541535) 2026-11-20 00:04 UTC proposal.adopted
- [541534](https://bounty.xe.network/log/541534) 2026-11-20 00:04 UTC ticket.facts
- [541533](https://bounty.xe.network/log/541533) 2026-11-20 00:04 UTC proposal.adopted
- [541532](https://bounty.xe.network/log/541532) 2026-11-20 00:04 UTC ticket.facts
- [541531](https://bounty.xe.network/log/541531) 2026-11-20 00:04 UTC proposal.adopted
- [541530](https://bounty.xe.network/log/541530) 2026-11-20 00:04 UTC ticket.facts
- [536338](https://bounty.xe.network/log/536338) 2026-11-19 23:41 UTC note.added
- [536336](https://bounty.xe.network/log/536336) 2026-11-19 23:41 UTC proposal.created

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

### Report

# Ledger sync client: `maxTotalBlocks` (10,000) is checked only between pages — one in-budget response page forces unbounded per-block processing

## Summary

The ledger sync client's documented block ceiling is never applied to the work a single hostile sync response can force (`xeprotocol/xe`, HEAD 89a542e, testnet-0005). In `requestSync` (`net/sync.go:563-585, 589-645`), a response page is decoded whole — bounded only by the 10 MiB per-page byte budget (`maxSyncResponseBytes`) — and every decoded block is appended and then pushed through `AddSyncedBlock` twice (the main processing pass plus a second full pass that logs rejection reasons). The `maxTotalBlocks = 10000` check at line 577 is consulted only *after* the whole page has been decoded and appended. A single page that is fully inside the byte budget can therefore carry \~3.4 million minimal blocks (340× the ceiling), and even hash-valid minimal blocks (\~380 bytes on the wire) allow \~22–27k blocks per page. The victim initiates this sync itself — on every new peer connection and in the periodic resync loop — so a malicious peer only has to stay connected and answer.

## Mechanism

```
lr := &io.LimitedReader{R: s, N: maxSyncResponseBytes}
dec := json.NewDecoder(lr)
for {
    lr.N = maxSyncResponseBytes              // byte budget is per page
    var resp SyncResponse
    if err := dec.Decode(&resp); err != nil { ... }
    allBlocks = append(allBlocks, resp.Blocks...)
    if len(allBlocks) >= maxTotalBlocks {     // line 577: checked only AFTER
        break                                 // the whole page is decoded
    }
    if !resp.HasMore { break }
}
// then: quarantine filter over allBlocks, then up to 10 retry passes of
// ledger.AddSyncedBlock over every block, plus a second full pass over
// the survivors just to log rejection reasons.
```

The block-count ceiling is never applied to `resp.Blocks` itself — not during decode, not before processing. The cheapest block encoding (`{}`) costs \~3 bytes, so one legal page can carry \~3.4M blocks; the decode alone allocates \~147× the page's byte size in `*core.Block` churn (measured below), i.e. \~1.4 GB of allocation churn for a full 10 MiB page of minimal blocks, before either `AddSyncedBlock` pass runs.

## Impact

Unauthenticated, repeatable CPU \+ memory amplification from a single sync response, re-triggered on every connect and every periodic resync round. No crash or corruption on its own; the harm is sustained resource exhaustion of any node connected to a hostile peer. Suggested tier: **Medium (2,500 XE)**.

## Proof of concept

Verified in `xe/net/poc_r3_pagecap_test.go` — `TestR3SyncSinglePageExceedsMaxTotalBlocks` \+ `TestR3SyncPageDecodeAmplification`. The PoC drives the **real** `requestSync` over a real libp2p stream against a hostile server and counts ledger-store `GetBlock` calls (exactly one per `AddSyncedBlock` attempt for the crafted hash-valid blocks, which fail only later at the credential check with a retryable error and are therefore attempted twice — main pass \+ reasons pass):

```
control: page: 2000 blocks, 758041 bytes   -> 4000 GetBlock calls
attack:  page: 22000 blocks, 8351041 bytes -> 44000 GetBlock calls
  (the log even prints "sync: hit maxTotalBlocks cap (10000), stopping" —
   the cap fires, and all 22,000 already-decoded blocks are processed anyway)
--- PASS

decode measurement: 1,500,029-byte page of 500,000 {} blocks
  -> TotalAlloc delta 221 MB in Decode alone (~147x byte amplification),
     before either AddSyncedBlock pass runs.
```

Reproduce:

```
cd xe && go test ./net/ -run TestR3Sync -v -count=1
```

## Suggested fix

Enforce the count during/right after decode, per page and cumulatively: if `len(resp.Blocks)` would push the total past `maxTotalBlocks`, truncate `resp.Blocks` (or abort the round) *before* appending/processing; also consider a streaming decoder that stops materialising blocks past the cap.

## Relation to existing reports

Not XE-6775 (nil-block panic in the same client) or XE-6778 (server-side page\_size\=1) — different code path and mechanism. Closest corpus ticket is XE-5289 (sync client counts its 10 MiB download budget per page, so cumulative download across pages is unbounded): that mechanism is the *byte* budget being reset per page. This defect is the *block-count* cap never being enforced within a page at all — a **single** page fully inside the byte budget defeats it, and the fix differs (truncate/reject on block count vs make the byte budget cumulative). Flagged explicitly in case triage reads XE-5289 broadly.

### Thread

**Joseph Denne**team2026-11-20 00:04 UTCdesk

Thanks. This is the same finding as https://bounty.xe.network/XE-0023, 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-10571 and says what differs; it is read like any other.
