<!-- XE-13111 · statechain: canonical op encoding hashes raw value bytes, so a Windows autocrlf checkout changes the genesis hash and verify-genesis / bootstrap fail · testnet -->
*Markdown view of <https://bounty.xe.network/XE-13111>. The page is the record; this is the same page for reading.*

XE-13111 · Bounty

# statechain: canonical op encoding hashes raw value bytes, so a Windows autocrlf checkout changes the genesis hash and verify-genesis / bootstrap fail

Closed · duplicate
—claimed Minor
web
filed 2026-11-14 16:50 UTC
by xe:8d50b3a1

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Minor

Area
:   Ops / testnet

Duplicate of
:   [XE-0038](https://bounty.xe.network/XE-0038) accepted

Tracked
:   internally

Updated
:   2026-11-20 19:45 UTC

Told
:   2026-11-20 19:45 UTC

### Patches

None linked.

### History

- [625881](https://bounty.xe.network/log/625881) 2026-11-20 19:45 UTC proposal.adopted
- [625880](https://bounty.xe.network/log/625880) 2026-11-20 19:45 UTC reply.sent
- [625879](https://bounty.xe.network/log/625879) 2026-11-20 19:45 UTC ticket.status new → closed
- [621483](https://bounty.xe.network/log/621483) 2026-11-20 19:44 UTC proposal.adopted
- [621482](https://bounty.xe.network/log/621482) 2026-11-20 19:44 UTC ticket.facts area
- [621481](https://bounty.xe.network/log/621481) 2026-11-20 19:44 UTC proposal.adopted
- [621480](https://bounty.xe.network/log/621480) 2026-11-20 19:44 UTC ticket.facts
- [621479](https://bounty.xe.network/log/621479) 2026-11-20 19:44 UTC proposal.adopted
- [621478](https://bounty.xe.network/log/621478) 2026-11-20 19:44 UTC ticket.facts
- [621477](https://bounty.xe.network/log/621477) 2026-11-20 19:44 UTC proposal.adopted
- [621476](https://bounty.xe.network/log/621476) 2026-11-20 19:44 UTC ticket.facts
- [614815](https://bounty.xe.network/log/614815) 2026-11-20 15:45 UTC note.added

[Full history](https://bounty.xe.network/log?ref=XE-13111) · [JSON](https://bounty.xe.network/v1/tickets/XE-13111) · [markdown](https://bounty.xe.network/XE-13111.md)

### 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 embeds `op.Value` exactly 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

**Joseph Denne**team2026-11-20 19:45 UTCdesk

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.
