[Minor] Cert sync can never succeed once a node retains ~65 certificates — the 64 KiB response cap truncates the reply and the pull retries forever
Report
H5 — MINOR — Cert sync can never succeed once a node retains ≥65 certs
Title: [Minor] Cert sync can never succeed once a node retains ~65 certificates — the 64 KiB response cap truncates the reply and the pull retries forever
Summary
A cert-sync response is capped at 256 certs and at 64 KiB on the wire. A single certificate is ~1,012 bytes of JSON, so ~65 of them already fill the 64 KiB cap — but a node retains up to 256 certs per provider. Once a node holds ~65 certs, a full cert sync can never complete: the response is truncated mid-JSON, decoding fails, zero certs are ingested (all-or-nothing unmarshal), and the pull retries 3 times per invocation and re-invokes on every connect plus every 2-minute sweep, forever. A fresh node can never bootstrap certificates from an established provider. I measured the exact threshold with a program that builds realistic certificates and replays the wire behaviour: 64 certs fit (64,867 bytes, 669 to spare), 65 certs exceed 64 KiB (~65,880 bytes) and fail to decode.
Suggested tier: Minor (650 XE).
My XE address for payout: d0a60d324b5f1d72fa06e79b92f0253241b85438a10c0ccac76c5f9b8135d8d4
How I found it
I was reading the cert-sync path to understand how a new node bootstraps provider certificates. The request in net/certsync.go is msg.Request(ctx, pid, CertRequestMsgType, nil) — no filter, no "what I have" list. The responder ignores the payload and returns provide() = all retained certs, capped at 256 (certPullMaxResponse, certsync.go:26). node/perf.go:406 collectCertificates() returns n.certs().all() (every retained cert) plus the node's own current cert. Then I saw the receiver side in net/msg.go:172: the response is decoded through io.LimitReader(s, MsgMaxResponseSize) where MsgMaxResponseSize = 65536 (net/msg.go:24). A response over 64 KiB is truncated mid-JSON and Decode fails. Retention is 256 certs per provider (node/certset.go:10, certRetentionPerProvider = 256), and certs are valid 7 days and issued per benchmark run — so a provider will cross the threshold over time, and once it does, no peer can ever pull certs from it again.
I did not want to assert the threshold from the constants alone, because the actual byte size depends on the real certificate shape. So I wrote a program that builds realistic perf.Certificate values (Provider/PubKey/Seed/WorkProof/CPUHash/attestation roots 64-hex each, Signature 128-hex, Hash 64-hex, PoWPuzzles = 1024, WorkloadVersion = 4, CertificateValidity = 7d) and measures the marshalled response size plus the LimitReader truncation behaviour. One cert is 1,012 bytes. The byte table from two identical runs:
- n=1: 1,048 B — fits. n=10: 10,165 B — fits. n=30: 30,425 B — fits.
- n=60: 60,815 B — fits. n=61: 61,828 B — fits. n=62: 62,841 B — fits.
- n=63: 63,854 B — fits (after LimitReader: 63,854 B, decode err=nil).
- n=64: 64,867 B — fits.
- n=100: 101,335 B — EXCEEDS 64 KiB → truncated → Decode fails.
- n=256: 259,363 B — EXCEEDS 64 KiB → truncated → Decode fails.
Threshold: ≥65 certs (n=64 fits with 669 bytes to spare; n=65 ≈ 65,880 B exceeds). My Phase 1 estimate was ~62 (assuming 1,041 B/cert); the measured cert is 1,012 B, so the threshold is ~62–65 depending on real cert size. I am stating the range, not a single magic number.
Steps to reproduce
Run the proof program (proof-h5/main.go, 100 lines) with go run ., twice. It builds realistic certificates, marshals the cert-sync response for n = 1, 10, 30, 60–64, 100, 256, and reports which sizes fit inside MsgMaxResponseSize (65,536) and which exceed it. It also runs the requester's io.LimitReader(65536) + json.Decode path on a 63-cert response to show the boundary: 63 certs (63,854 B) decode fine, while 100 and 256 certs exceed the cap and would be truncated mid-JSON. Both runs produced identical byte tables.
// proof-h5: measure the exact JSON size of a realistic perf.Certificate and
// find the count at which a cert-sync response exceeds MsgMaxResponseSize
// (65536 bytes), proving the wire-level truncation threshold.
package main
import (
"encoding/hex"
"encoding/json"
"fmt"
"strings"
"github.com/xeprotocol/xe/net"
"github.com/xeprotocol/xe/perf"
)
func hexStr(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = byte(0xab)
}
return hex.EncodeToString(b)
}
func main() {
// Realistic cert: mirror node/perf.go certificate construction.
c := &perf.Certificate{
Provider: hexStr(32),
ProviderPubKey: hexStr(32),
Seed: hexStr(32),
WorkloadVersion: perf.WorkloadVersion,
Puzzles: perf.PoWPuzzles,
WorkProof: hexStr(32),
CPUHash: hexStr(32),
Score: 1.234567,
StartAttestationRoot: hexStr(32),
EndAttestationRoot: hexStr(32),
StartMedian: 1794381719983147784,
EndMedian: 1794381729983147784,
IssuedAt: 1794381719983147784,
ExpiresAt: 1794381719983147784 + int64(perf.CertificateValidity),
PriceMultiplierMilli: 1000,
Signature: hexStr(64),
Hash: hexStr(32),
}
one, err := json.Marshal(c)
if err != nil {
panic(err)
}
fmt.Printf("one cert JSON: %d bytes\n", len(one))
fmt.Printf("MsgMaxResponseSize: %d\n", net.MsgMaxResponseSize)
// Full cert-sync response = MsgResponse envelope {"type":"cert_request","payload":[...]}
type msgResp struct {
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
}
for _, n := range []int{1, 10, 30, 60, 61, 62, 63, 64, 100, 256} {
certs := make([]*perf.Certificate, n)
for i := range certs {
certs[i] = c
}
payload, _ := json.Marshal(certs)
resp, _ := json.Marshal(msgResp{Type: "cert_request", Payload: payload})
status := "OK (fits)"
if len(resp) > net.MsgMaxResponseSize {
status = "EXCEEDS 64KiB -> truncated by LimitReader -> Decode fails"
}
fmt.Printf("n=%3d certs: response %6d bytes %s\n", n, len(resp), status)
}
// Confirm the truncation actually breaks decoding: simulate the
// requester's io.LimitReader(65536) + json.Decode on a 63-cert response.
certs := make([]*perf.Certificate, 63)
for i := range certs {
certs[i] = c
}
payload, _ := json.Marshal(certs)
full, _ := json.Marshal(msgResp{Type: "cert_request", Payload: payload})
truncated := full
if len(truncated) > net.MsgMaxResponseSize {
truncated = full[:net.MsgMaxResponseSize]
}
var decoded msgResp
err = json.Unmarshal(truncated, &decoded)
fmt.Printf("\n63-cert response: full=%d bytes, after 64KiB LimitReader=%d bytes, decode err=%v\n",
len(full), len(truncated), err)
if err != nil {
fmt.Println("CONFIRMED: a 63-cert response is truncated mid-JSON and fails to decode.")
}
// And a 60-cert response decodes fine.
certs = make([]*perf.Certificate, 60)
for i := range certs {
certs[i] = c
}
payload, _ = json.Marshal(certs)
full, _ = json.Marshal(msgResp{Type: "cert_request", Payload: payload})
err = json.Unmarshal(full, &decoded)
fmt.Printf("60-cert response: %d bytes, decode err=%v (fits, decodes fine)\n", len(full), err)
_ = strings.Repeat
}
Impact
Once a provider holds ~65 certs, no peer can ever pull certificates from it again — the pull fails, zero certs are ingested, and it retries forever (3x per invocation, re-invoked on every connect and every 2-minute sweep). A fresh node can never bootstrap certs from an established provider. I am calling this Minor: it is a liveness/robustness issue in certificate sync, not a funds or consensus issue, and it only bites once a provider accumulates enough certificates — but retention is 256 per provider and certs are issued per benchmark run, so crossing the threshold is a matter of time, not a freak condition.
Root cause
The cert-sync request carries no filter and the responder returns everything it holds (provide() = all retained certs, cap 256), while the receiver decodes through a 64 KiB LimitReader. The two caps disagree by a factor of four: 256 certs at ~1,012 bytes each is ~259 KiB, but the wire only allows 64 KiB. The response is truncated mid-JSON, decoding fails, and the all-or-nothing unmarshal means zero certs are ingested even though most of the payload arrived intact.
Why this is not a duplicate
I read all 189 issues (open and closed) before filing. Zero hits for cert + 65536, cert + sync + truncat, certsync, or MsgMaxResponseSize. Distinct from #259 (gossip validator accepts long-expired certs — an expiry check, not a size cap) and #350 (PullVotes/PullBlocks pre-checks — a different sync path entirely).
Suggested fix
Either paginate the cert-sync response (request with a cursor/offset and a per-page cap that fits comfortably inside 64 KiB, e.g. 32 certs per page), or have the requester send the set of cert hashes it already holds so the responder only returns the delta. Either way, the response must be bounded below MsgMaxResponseSize by construction, not by hoping retention stays low.
What I deliberately did not test
I did not run a live two-node proof (generating 65+ real certificates via perf benchmarks is impractical on my VM). The mechanism is proven by code (nil request, all-certs response, 64 KiB LimitReader, all-or-nothing decode, 3x retry + 2-minute sweep) plus the exact measured byte threshold. Real-world cert sizes vary slightly, so the threshold is ~62–65, not a single magic number — I am stating the range. I also did not test whether other sync responses hit the same 64 KiB cap; that is a separate audit.
Thread
Thanks. This is the same finding as https://bounty.xe.network/XE-0436, 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-13238 and says what differs; it is read like any other.