statechain: canonical op encoding hashes raw value bytes, so a Windows autocrlf checkout changes the genesis hash and verify-genesis / bootstrap fail
Report
statechain: canonical op encoding hashes raw value bytes, so a Windows autocrlf checkout changes the genesis hash and verify-genesis / bootstrap fail
Summary
MarshalCanonical in statechain/encoding.go hashes each op's Value
(a json.RawMessage) byte-for-byte when computing the genesis block hash.
The published testnet-0005 genesis file
(genesis/testnet-0005/statechain-genesis.json) contains multi-line op
values stored with LF line endings. On a Windows checkout with git's
core.autocrlf=true (the default for Git for Windows), those bytes are
rewritten to CRLF on checkout. Every affected op value changes, so the
recomputed genesis hash no longer equals the published hash, and
ParseGenesis → ValidateGenesis rejects the genesis
(b.Hash != expected). As a result verify-genesis fails and a node
cannot bootstrap from a default Windows checkout.
Affected code
statechain/encoding.go—MarshalCanonical: the canonical byte form of an op embedsop.Valueexactly as read from disk; the block hash (HashBlock) is taken over those bytes with no line-ending normalisation.genesis/testnet-0005/statechain-genesis.json— the genesis artifact whose hash is pinned.- Genesis loading/validation path (
ParseGenesis→ValidateGenesis): recomputes the hash from the on-disk bytes and compares it against the expected published hash.
Root cause
The security-critical hash of the genesis block depends on the raw bytes of a text file whose line endings are not stable across platforms. Git's autocrlf translation is a checkout-time, per-user setting, so the same commit yields different genesis bytes — and therefore a different genesis hash — on Windows than on Linux/macOS. A hash that is meant to pin the genesis cannot depend on checkout settings.
Proof (executable)
A faithful reimplementation of MarshalCanonical + HashBlock at HEAD
89a542e was run over the published genesis file with each line-ending
variant. The reimplementation is validated by the LF case reproducing the
published hash exactly:
- LF bytes →
d01aabc1a29dc64bc6bbc30031a716cd2e0ceb867e5479953cd5ad22c8f296d6(exactly the published testnet-0005 genesis hash) - CRLF bytes →
f620d15b4371961fe92a48720d47e7e84fc997c9ba038d226729d9b50b0ac981 - CR-only bytes →
7c61220d10ff432a546cfe2f01b84d4f4f774c4502401a2a334b1acdc0fab57a
Both non-LF variants differ from the published hash, so
ValidateGenesis rejects the genesis in those checkouts: the bug is live
at HEAD.
Impact
Any Windows user or operator with a default Git for Windows configuration cannot verify the genesis and cannot bootstrap a node from their checkout. There is no remote trigger and no risk to funds or state — a node that fails validation simply does not start — but the reference verification and bootstrap workflow is broken on the most common Windows setup, and the failure mode (hash mismatch) looks identical to a tampered genesis, which can send operators chasing a non-existent integrity problem.
Not a duplicate
XE-0038 covers autocrlf rewriting the embedded BIP39 wordlist — a
different file, mechanism, and symptom. Other genesis tickets
(ValidateGenesis coverage, verify-genesis flag handling, genesis halves
binding) are different bugs. No existing ticket covers the canonical
encoding's line-ending sensitivity. Upstream this is issue #543 with fix
PR 555 open (unmerged at the time of writing); the bug is live at HEAD
89a542e, and the GitHub issue is not linked to any board ticket.
Suggested fix
Normalise line endings before hashing (canonicalise op.Value the same
way regardless of checkout bytes), or hash a canonicalised form of the
genesis rather than the raw file bytes; additionally enforce LF for
genesis artifacts via .gitattributes so checkouts are byte-stable.
Claimed tier
Minor (availability of the verify/bootstrap workflow on Windows only; no funds, no consensus or state impact). The XE-0038 Windows/CRLF precedent was assessed Medium, so this is filed as Minor with that precedent noted.
Thread
Thanks. This is the same finding as https://bounty.xe.network/XE-0038, 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-13111 and says what differs; it is read like any other.