<!-- XE-0120 · statechain sync: server enforces no byte cap and the client's 10 MiB cap is below the maximum legal page (64 × 256 KiB = 16 MiB) — permanent sync failure and unbounded encoding work per request · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0120>. The page is the record; this is the same page for reading.*

XE-0120 · Bounty

# statechain sync: server enforces no byte cap and the client's 10 MiB cap is below the maximum legal page (64 × 256 KiB \= 16 MiB) — permanent sync failure and unbounded encoding work per request

Triaging
claimed Minor
[xe#196](https://github.com/xeprotocol/xe/issues/196)
filed 2026-10-29 16:32 UTC
by hayokakoweda75

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   Minor

Area
:   P2P / sync

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-08 20:17 UTC

Told
:   2026-11-08 20:18 UTC

### Patches

- [xe#204](https://github.com/xeprotocol/xe/pull/204) open by NePreby
  fix(statechain): enforce server byte budget and align client sync decode cap (fixes #196)

### History

- [43822](https://bounty.xe.network/log/43822) 2026-11-08 20:19 UTC reply.mirror\_failed
- [43785](https://bounty.xe.network/log/43785) 2026-11-08 20:18 UTC proposal.adopted
- [43784](https://bounty.xe.network/log/43784) 2026-11-08 20:18 UTC reply.sent
- [43263](https://bounty.xe.network/log/43263) 2026-11-08 20:18 UTC proposal.adopted
- [43262](https://bounty.xe.network/log/43262) 2026-11-08 20:18 UTC ticket.facts area
- [43261](https://bounty.xe.network/log/43261) 2026-11-08 20:18 UTC proposal.adopted
- [43260](https://bounty.xe.network/log/43260) 2026-11-08 20:18 UTC ticket.facts
- [43259](https://bounty.xe.network/log/43259) 2026-11-08 20:18 UTC proposal.adopted
- [43258](https://bounty.xe.network/log/43258) 2026-11-08 20:18 UTC ticket.facts
- [43257](https://bounty.xe.network/log/43257) 2026-11-08 20:18 UTC proposal.adopted
- [43256](https://bounty.xe.network/log/43256) 2026-11-08 20:18 UTC ticket.facts
- [43255](https://bounty.xe.network/log/43255) 2026-11-08 20:18 UTC proposal.adopted

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

### Report

**Suggested severity: Low (liveness \+ amplification; no funds at risk)**
**Area:** statechain sync (`statechain/sync.go`, `statechain/types.go`)
**Repo pin:** 9787859 (testnet-0005)

## Summary

The statechain sync handler bounds the response by block count (`syncMaxBlocks = 10000`) and by a 60 s stream deadline, but **never by bytes**. `syncMaxResponseSize = 10 << 20` is referenced exactly once, on the client side (`statechain/sync.go:168`).

Consensus allows a state block up to `MaxBlockSize = 262144` (`statechain/types.go:102`), and the page size is fixed at 64 (`sync.go:20`). So one *legal* page can be `64 × 262144 = 16,777,216` bytes, i.e. **1.6× the client's decode cap**. When that happens the client's `LimitReader` truncates mid-JSON, `json.Decoder.Decode` returns `unexpected EOF`, `requestSync` returns an error, and the node retries the identical request every 30 s forever — there is no smaller-page fallback and no server-side notion of a byte budget.

## Code

```
// statechain/sync.go:20-25
syncPageSize        = 64
syncMaxBlocks       = 10000
syncMaxResponseSize = 10 << 20   // used only by the client, line 168
```

```
// statechain/sync.go:120-141 — server: bounded by count, never by bytes
for idx := startIndex; idx <= tip.Index && totalSent < syncMaxBlocks; {
	pageCount := uint64(syncPageSize)
	...
	blocks, err := chain.GetBlocks(idx, pageCount)
	...
	totalSent += len(blocks)
	hasMore := idx+uint64(len(blocks)) <= tip.Index && totalSent < syncMaxBlocks
	if err := enc.Encode(syncResponse{Blocks: blocks, HasMore: hasMore}); err != nil {
		return
	}
	idx += uint64(len(blocks))
}
```

```
// statechain/sync.go:168 — client: the only place the cap exists
dec := json.NewDecoder(io.LimitReader(s, syncMaxResponseSize))
```

```
// statechain/types.go:102
MaxBlockSize = 262144
```

## Consequences

1. **Permanent sync failure (liveness).** A node whose tip is just before a window of 64 large-but-legal blocks can never advance: every attempt decodes the same over-cap page and fails at the same byte. A fresh node hits it on its very first request (`1..64`), so it can never bootstrap. Because `sys.*` keys (phase, activations, oracle keyset, min\_protocol\_version) are frozen, that node keeps applying stale gating policy while the ledger advances — rejecting newly activated block types or accepting ones that should be gated.
2. **Encoding work with no byte ceiling.** A single request with `tip_index = -1` makes the node walk up to 10,000 blocks and JSON-encode them to a peer that may read slowly or not at all; the only stop conditions are the count cap and the 60 s deadline. The inbound limiter is per peer ID at 1 request / 30 s, and peer IDs are cheap to mint (cf. #47: one IP can run several full-rate hosts), so many identities can keep a node encoding back-to-back.

Honest limits: today's testnet blocks are small, so (1) is latent — the trigger is governance/oracle signers producing a run of large blocks, not an outside attacker. (2) is available now but bounded by the real chain size.

## Suggested fix

- Give `handleSyncStream` a byte budget (marshal each page, stop when the accumulated size would exceed `syncMaxResponseSize`, and set `has_more` accordingly).
- Make the constants consistent: either `syncPageSize × MaxBlockSize <= syncMaxResponseSize`, or raise the client cap above the maximum legal page.
- On a decode failure, retry with a smaller requested page instead of repeating the identical request forever.
- Add a test that builds a maximum-size legal page and asserts both that the server stops before the client cap and that a client with the shipped limits can ingest it.

### Thread

**Joseph Denne**team2026-11-08 20:17 UTCdesk

Thanks for the report. We have confirmed the behaviour you describe in the statechain sync path and it is being handled; we will update this ticket when there is a fix to point at.
