{"id":"XE-13111","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":1930,"title":"statechain: canonical op encoding hashes raw value bytes, so a Windows autocrlf checkout changes the genesis hash and verify-genesis / bootstrap fail","area":"ops-testnet","claimed_tier":"minor","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0038","tracked":true,"internal_ref":"#1087","internal_url":"https://github.com/xeprotocol/core/issues/1087","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T16:50:16.538477+00:00","updated_at":"2026-11-20T19:45:49.549484+00:00","source_created_at":null,"told_at":"2026-11-20T19:45:49.596348+00:00","status_changed_at":"2026-11-20T19:45:49.563295+00:00","url":"https://bounty.xe.network/XE-13111","body":"# statechain: canonical op encoding hashes raw value bytes, so a Windows autocrlf checkout changes the genesis hash and verify-genesis / bootstrap fail\n\n## Summary\n\n`MarshalCanonical` in `statechain/encoding.go` hashes each op's `Value`\n(a `json.RawMessage`) byte-for-byte when computing the genesis block hash.\nThe published testnet-0005 genesis file\n(`genesis/testnet-0005/statechain-genesis.json`) contains multi-line op\nvalues stored with LF line endings. On a Windows checkout with git's\n`core.autocrlf=true` (the default for Git for Windows), those bytes are\nrewritten to CRLF on checkout. Every affected op value changes, so the\nrecomputed genesis hash no longer equals the published hash, and\n`ParseGenesis` → `ValidateGenesis` rejects the genesis\n(`b.Hash != expected`). As a result `verify-genesis` fails and a node\ncannot bootstrap from a default Windows checkout.\n\n## Affected code\n\n- `statechain/encoding.go` — `MarshalCanonical`: the canonical byte form of\n  an op embeds `op.Value` exactly as read from disk; the block hash\n  (`HashBlock`) is taken over those bytes with no line-ending\n  normalisation.\n- `genesis/testnet-0005/statechain-genesis.json` — the genesis artifact\n  whose hash is pinned.\n- Genesis loading/validation path (`ParseGenesis` → `ValidateGenesis`):\n  recomputes the hash from the on-disk bytes and compares it against the\n  expected published hash.\n\n## Root cause\n\nThe security-critical hash of the genesis block depends on the raw bytes\nof a text file whose line endings are not stable across platforms. Git's\nautocrlf translation is a checkout-time, per-user setting, so the same\ncommit yields different genesis bytes — and therefore a different genesis\nhash — on Windows than on Linux/macOS. A hash that is meant to pin the\ngenesis cannot depend on checkout settings.\n\n## Proof (executable)\n\nA faithful reimplementation of `MarshalCanonical` + `HashBlock` at HEAD\n`89a542e` was run over the published genesis file with each line-ending\nvariant. The reimplementation is validated by the LF case reproducing the\npublished hash exactly:\n\n- LF bytes → `d01aabc1a29dc64bc6bbc30031a716cd2e0ceb867e5479953cd5ad22c8f296d6`\n  (exactly the published testnet-0005 genesis hash)\n- CRLF bytes → `f620d15b4371961fe92a48720d47e7e84fc997c9ba038d226729d9b50b0ac981`\n- CR-only bytes → `7c61220d10ff432a546cfe2f01b84d4f4f774c4502401a2a334b1acdc0fab57a`\n\nBoth non-LF variants differ from the published hash, so\n`ValidateGenesis` rejects the genesis in those checkouts: the bug is live\nat HEAD.\n\n## Impact\n\nAny Windows user or operator with a default Git for Windows configuration\ncannot verify the genesis and cannot bootstrap a node from their checkout.\nThere is no remote trigger and no risk to funds or state — a node that\nfails validation simply does not start — but the reference verification\nand bootstrap workflow is broken on the most common Windows setup, and\nthe failure mode (hash mismatch) looks identical to a tampered genesis,\nwhich can send operators chasing a non-existent integrity problem.\n\n## Not a duplicate\n\nXE-0038 covers autocrlf rewriting the embedded BIP39 wordlist — a\ndifferent file, mechanism, and symptom. Other genesis tickets\n(ValidateGenesis coverage, verify-genesis flag handling, genesis halves\nbinding) are different bugs. No existing ticket covers the canonical\nencoding's line-ending sensitivity. Upstream this is issue #543 with fix\nPR 555 open (unmerged at the time of writing); the bug is live at HEAD\n`89a542e`, and the GitHub issue is not linked to any board ticket.\n\n## Suggested fix\n\nNormalise line endings before hashing (canonicalise `op.Value` the same\nway regardless of checkout bytes), or hash a canonicalised form of the\ngenesis rather than the raw file bytes; additionally enforce LF for\ngenesis artifacts via `.gitattributes` so checkouts are byte-stable.\n\n## Claimed tier\n\nMinor (availability of the verify/bootstrap workflow on Windows only; no\nfunds, no consensus or state impact). The XE-0038 Windows/CRLF precedent\nwas assessed Medium, so this is filed as Minor with that precedent noted.","patch_refs":[],"thread":[{"id":15199,"source":"desk","source_ref":"reply:13090","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0038, 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-13111 and says what differs; it is read like any other.","created_at":"2026-11-20T19:45:49.549484+00:00"}]}