Statechain genesis hash is line-ending sensitive — verify-genesis and node bootstrap fail on Windows (autocrlf)
Report
Summary
The statechain "canonical" block hash is not canonical: it depends on the file's
line endings (LF vs CRLF), not just the semantic JSON content. On a Windows
checkout with git's default core.autocrlf=true (the repo ships no
.gitattributes), the published genesis bundle is rewritten to CRLF on checkout,
and xe verify-genesis fails with hash mismatch, so a user cannot verify or
bootstrap a node by following the README.
Root cause
- statechain/types.go: Op.Value is json.RawMessage.
- encoding/json decodes each "value" field by capturing its raw bytes verbatim, including any CRLF inside the multi-line JSON value.
- statechain/encoding.go MarshalCanonical() writes []byte(op.Value) straight into the hash buffer; statechain/crypto.go HashBlock() = sha256 of that.
The committed genesis declares hash d01aabc1... (computed over LF bytes), but a CRLF checkout re-hashes the same logical genesis to f620d15b....
Reproduction (Windows, Go 1.25)
- git clone https://github.com/xeprotocol/xe.git (default autocrlf)
- go build ./cmd/xe
- ./xe verify-genesis --genesis-dir ./genesis/testnet-0005
Result:
error: genesis: genesis/testnet-0005/statechain-genesis.json: hash mismatch: got d01aabc1...c8f296d6, want f620d15b...0ac981
The same happens to the compiled-in embedded statechain/genesis.json.
- Fix to confirm: strip the carriage returns from the genesis file (sed or a text edit), the file re-hashes to the declared d01aabc1... and verify-genesis passes.
Impact
Any operator/researcher cloning on Windows (or any autocrlf=true checkout) and following the README cannot verify the bundle or bootstrap a node.
Suggested fix
Hash the decoded/typed value instead of the raw json.RawMessage bytes (or normalize op.Value before hashing). Also consider a .gitattributes forcing *.json to LF.
Related
XE-0038 covers the embedded BIP39 wordlist under autocrlf; this is the genesis-JSON surface (verify-genesis + node bootstrap), which is a distinct impact.
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-13384 and says what differs; it is read like any other.