loom_snapshot - deterministic, cross-language world-state snapshot hash (Rust core).
The native sibling of the TS world-state-snapshot.ts. v3.0 Phase 1 of the
Living Persistent World: a world state reduces to a state_hash that is
BYTE-IDENTICAL across TypeScript, Python, and Rust, so a snapshot at a known
event index can be persisted compactly, verified against the HMAC event chain
on resume, and compared across languages to prove no surface diverged.
REUSE, not re-implementation. The hash rides loom_events' audited,
golden-vector-pinned primitives:
state_hash = hmac_sha256_hex(key, field(SNAPSHOT_DOMAIN) + field(canonical_json(state)))
so it inherits cross-language byte-parity for free and adds no new canonical
or crypto surface. Parity is proven by the shared golden vector
(test_vectors/v3_0_snapshot_canonical.json), which is generated by the real
TS and asserted here byte-for-byte.
DESIGN (reconciled with the Pantheon, matches the TS module):
- The state_hash is a PURE content hash; the event index is version metadata
stored alongside in
WorldStateSnapshot, never folded into the hash. - ONE sort rule everywhere: UTF-16 code units. Object keys are sorted by
canonical_json(UTF-16);normalize_tagssorts tags by the SAME comparator (encode_utf16), NOT Rust's nativestrOrd (UTF-8 bytes). - Fail-closed:
canonical_jsonreturnsErr(CanonError)on any non-canonical value (non-integer / -0 / unsafe-int /__proto__/ over-depth) before a hash is produced.
Domain separation: SNAPSHOT_DOMAIN is distinct from the event-chain record
("loom.chain.rec/1") and seal ("loom.chain.seal/1") domains, so a snapshot
hash can never be reinterpreted as a chain-record signature.