{"id":"XE-11788","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":2166,"title":"[statechain,net] Remote unauthenticated node-crash: statechain sync dereferences a JSON null block with no nil check and no recover","area":"p2p-sync","claimed_tier":"high","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0002","tracked":true,"internal_ref":"#1064","internal_url":"https://github.com/xeprotocol/core/issues/1064","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-13T08:53:59.765269+00:00","updated_at":"2026-11-20T00:33:21.549244+00:00","source_created_at":null,"told_at":"2026-11-20T00:33:21.568675+00:00","status_changed_at":"2026-11-20T00:33:21.555020+00:00","url":"https://bounty.xe.network/XE-11788","body":"# XE Bug Bounty — Statechain sync null-block remote node-crash\n\n**Title:** [statechain,net] Remote unauthenticated node-crash: statechain sync dereferences a JSON `null` block\n**Reporter:** @bobskey\n**Severity:** High\n**Tier:** High\n**Asset/Target:** xeprotocol/xe — `statechain` package (testnet-0005)\n**Duplicate check:** Related in *shape* to XE-11679 (ledger sync null-block), but this is a **separate, independently-reachable crash** in the **statechain (DAO/activation) subsystem** with its own sync protocol, stream handler, and production call path (`statechain.SetupSync` / `requestSync`). Different code, different wire protocol, different subsystem. Not a duplicate.\n\n---\n\n## Summary\n\nThe statechain (DAO/activation) block-sync puller decodes a peer-supplied JSON\nresponse and then dereferences every element of its `blocks` array without a\nnil check. Because the element type is `[]*Block`, a malicious peer can put a\nsingle JSON `null` in the array, which Go's `encoding/json` decodes into a nil\npointer **with no error**. That nil is passed into `Chain.AddBlock`, which\ndereferences it in the hash-verification path and panics. The sync runs on a\ngoroutine with no `recover()`, so the panic **terminates the whole node\nprocess**.\n\n## Vulnerable path\n\n```\nstatechain/sync.go:178   for _, b := range resp.Blocks {\nstatechain/sync.go:179       if err := chain.AddBlock(b); err != nil {   // b may be nil\nstatechain/chain.go:106  func (c *Chain) AddBlock(b *Block) error {\nstatechain/chain.go:109      if err := VerifyBlockHash(b); err != nil {  // no nil guard\nstatechain/crypto.go:42  func VerifyBlockHash(b *Block) error {\nstatechain/crypto.go:43      expected, err := HashBlock(b)\nstatechain/crypto.go:12  func HashBlock(b *Block) (string, error) {\nstatechain/encoding.go:14    binary.BigEndian.PutUint64(idx[:], b.Index)  // NIL DEREF\n```\n\n`VerifyBlockHash` → `HashBlock` → `MarshalCanonical` reads `b.Index` and other\nfields with **no nil guard**, and none of the three functions contains a\n`recover()`. `statechain/sync.go:82` (inside `SetupSync`) and\n`statechain/sync.go:220` (inside `ResyncOnGap`, wired at `node/node.go:2243`)\nboth call `requestSync` on bare goroutines, so the panic is fatal.\n\n## Why it's reachable remotely and without auth\n\n- `statechain.SetupSync(h, sc)` is called at node startup (`node/node.go:329`)\n  and `statechain.ResyncOnGap(...)` periodically (`node/node.go:2243`), so the\n  sync puller is always active.\n- `requestSync` accepts an inbound statechain-sync stream from any connected\n  peer and JSON-decodes the response with `json.NewDecoder` (`sync.go:168-172`).\n  `encoding/json` turns a `null` array element into a nil `*Block` silently —\n  unlike the gossip path, there is **no** explicit nil rejection and **no**\n  `DisallowUnknownFields`-style hardening on this stream.\n- An attacker only needs to be a libp2p peer the victim syncs from (any node\n  the victim connects to, or that appears in its routing table) and write one\n  crafted page.\n\n## Impact\n\n- **Full remote node crash (DoS)** of any XE node that syncs statechain blocks\n  from the attacker. One inbound stream, one line of JSON → process exits.\n- Because it hits the **statechain (DAO/activation) subsystem**, a sustained\n  attack can starve activation/policy propagation network-wide, degrading\n  consensus participation across the mesh.\n- No authentication, no stake, no rate-limit gate on the malicious response\n  content itself.\n\n## Proof of Concept\n\nRun: `cd xe && go test -run TestPoc_StatechainSyncNullBlock ./statechain/`\n\n```go\npackage statechain_test\n\nimport (\n\t\"testing\"\n\t\"github.com/xeprotocol/xe/statechain\"\n)\n\nfunc TestPoc_StatechainSyncNullBlock(t *testing.T) {\n\t// A malicious peer's sync-response page {\"blocks\":[null],\"has_more\":false}\n\t// decodes resp.Blocks[0] to a nil *Block with NO error. AddBlock passes it\n\t// straight into VerifyBlockHash, which dereferences it.\n\tvar nilBlock *statechain.Block\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\tt.Fatalf(\"PANIC CONFIRMED — remote nil-block crashes node: %v\", r)\n\t\t}\n\t}()\n\t_ = statechain.VerifyBlockHash(nilBlock)\n\tt.Log(\"VerifyBlockHash(nil) returned with no crash\")\n}\n```\n\n**Observed output (real run):**\n\n```\n--- FAIL: TestPoc_StatechainSyncNullBlock (0.00s)\n    poc_sync_nullblock_test.go:29: PANIC CONFIRMED — remote nil-block crashes node:\n    runtime error: invalid memory address or nil pointer dereference\n```\n\n## Recommended fix\n\nAdd a nil guard at the top of `Chain.AddBlock` (or before the loop at\n`statechain/sync.go:178`):\n\n```go\nfunc (c *Chain) AddBlock(b *Block) error {\n    if b == nil {\n        return fmt.Errorf(\"AddBlock: nil block\")\n    }\n    ...\n}\n```\n\nAnd/or guard the consumer loop so a nil element is skipped/countered rather\nthan passed down. For defense-in-depth, add a `recover()` around the sync\ngoroutine body so a decode/validation panic can never terminate the process.\n\n## Reporter\n\n- Handle: @bobskey\n- Bounty wallet: `0x1d1FEe3A35d30E3f4fc3BCC49DbDe2028A7027C3`","patch_refs":[],"thread":[{"id":13267,"source":"desk","source_ref":"reply:11289","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0002, 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-11788 and says what differs; it is read like any other.","created_at":"2026-11-20T00:33:21.549244+00:00"}]}