omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / spec / canonical-encoding.md
| 1 | # SPECIFICATION: OMEGA Canonical Encoding and Identity Derivation |
| 2 | |
| 3 | ```text |
| 4 | Document ID: SPEC-OMEGA-CANON-M4 |
| 5 | Classification: Sovereign Semantic Specification |
| 6 | Target Substrate: Deterministic Byte Serialization & Cryptographic Identification |
| 7 | Status: RATIFIED FOR M4 (OMEGA_SEMANTICS) |
| 8 | ``` |
| 9 | |
| 10 | --- |
| 11 | |
| 12 | ## 1. The Canonical Identity Law |
| 13 | |
| 14 | $$\text{SEMANTIC\_ID} = \text{SHA256}(\text{CANONICAL\_SERIALIZATION}(\text{object}))$$ |
| 15 | |
| 16 | The canonical serialization is defined such that: |
| 17 | 1. Every semantic object has exactly one canonical binary encoding. |
| 18 | 2. Every semantically equivalent object produces the identical canonical binary encoding regardless of surface syntax, builder call order, or attribute insertion sequence. |
| 19 | 3. Any semantic difference produces a distinct canonical binary encoding, and by the collision-resistance of SHA-256, a distinct `SEMANTIC_ID`. |
| 20 | |
| 21 | --- |
| 22 | |
| 23 | ## 2. Binary Encoding Grammar |
| 24 | |
| 25 | An encoded OMEGA canonical chunk adheres strictly to this format: |
| 26 | |
| 27 | ```text |
| 28 | Offset Length Field Type / Description |
| 29 | --------------------------------------------------------------------------------- |
| 30 | +0x00 4 magic 0x4F, 0x4D, 0x47, 0x30 ("OMG0") |
| 31 | +0x04 1 version 0x01 |
| 32 | +0x05 1 kind Semantic category tag (0x01..0x0B) |
| 33 | +0x06 2 attr_count u16 big-endian, count of attributes |
| 34 | +0x08 ... attributes Sorted lexicographically by UTF-8 key |
| 35 | [ key_len: u8, key_bytes, val_len: u16, val_bytes ] |
| 36 | ... 2 rel_count u16 big-endian, count of relations |
| 37 | ... ... relations Sorted by (rel_type: u16, target_id: [u8; 32]) |
| 38 | ... 2 constraint_count u16 big-endian, count of constraints |
| 39 | ... ... constraints Sorted by (constraint_kind: u16, payload) |
| 40 | ... 4 payload_len u32 big-endian, length of kind-specific payload |
| 41 | ... ... payload Big-endian payload bytes |
| 42 | ``` |
| 43 | |
| 44 | ### Sorting & Normalization Rules |
| 45 | 1. **Attribute Keys**: Sorted strictly in ascending order using unsigned byte-wise comparison (`memcmp`). Duplicate keys are prohibited. |
| 46 | 2. **Relations**: Sorted primarily by relation kind (`u16`), secondarily by target `SemanticId` (`32-byte memcmp`). Duplicate edges are collapsed. |
| 47 | 3. **Constraints**: Sorted primarily by constraint kind (`u16`), secondarily by constraint parameter bytes. |
| 48 | 4. **Integers & Payload**: Always encoded in network byte order (big-endian), zero-padded to $\lceil \text{width} / 8 \rceil$. |
| 49 | |
| 50 | --- |
| 51 | |
| 52 | ## 3. Reference Resolution & Acyclicity |
| 53 | |
| 54 | In Milestone 4, expression graphs are directed acyclic graphs (DAGs). References point backward or horizontally to existing canonical objects by `SemanticId`. A graph containing an unresolved reference or a circular reference cycle fails validation and is rejected prior to canonical identity derivation. |
| 55 | |
| 56 | --- |
| 57 | |
| 58 | ## 4. Amendment: per-kind object encoding version (SPEC-OMEGA-EFFECT-CAP64) |
| 59 | |
| 60 | The `version` byte at +0x04 is the object encoding version of the object's |
| 61 | kind. `KIND_EFFECT` objects are version `0x02` and carry the explicit |
| 62 | 178-byte big-endian effect payload with a 64-bit capability generation; every |
| 63 | other kind is version `0x01`, unchanged. A decoder accepts only that pair: |
| 64 | a version `0x01` effect (legacy, truncated authority) and a version `0x02` |
| 65 | non-effect are refused. See `spec/effect-cap64-migration.md`. |