interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / spec / universal / source-aware-v2.md

195 lines · 12836 bytes Raw Blame History Rendered
1# Source-aware upper layer v2
2
3Issue #621, source-aware v2 (ledger L832). Additive to `source-aware-v1.md`, which is not edited and
4stays normative for every rule this file does not change. Every v1 unit, byte, identity, verdict and
5status is unchanged: a v1 unit decodes, encodes, identifies, replays and gets legality exactly as under
6v1. v2 adds three source languages and three profiles for restricted pure-u64 C++, Zig and Go units
7(issues #739, #740, #741). Independent review is pending (#623 writes an independent v2 reference
8decoder from this file alone). No importer, exporter, lowering, converter or proof claim.
9
10## 1. What changes on the wire
11
12Exactly one byte gains a value: the semantic header version (OMSA offset 4, envelope offset 17) may be
131 or 2. Everything else in the canonical wire format of `source-aware-v1.md` is unchanged:
14
15| field | v1 | v2 |
16|---|---|---|
17| OMSB envelope version (envelope offset 4) | 1 | 1 |
18| OMSA semantic header version (OMSA offset 4) | 1 | 1 or 2 |
19| dialect version (OMSA offset 7) | 1 | 1 |
20| operation version (operation offset 1) | 1 | 1 |
21| OMSP sidecar version (OMSP offset 4) | 1 | 1 |
22
23Any other value of any of these bytes refuses 66 (UNKNOWN_VERSION), as in v1. Record sizes (13-byte
24envelope prefix, 44-byte semantic header, 20-byte operations, 74-byte sidecar header, 8-byte spans),
25bounds (1..64 operations, source at most 4096 bytes, input at most 8192 bytes, semantic length at most
261324, sidecar length at most 4682), magic numbers, the parent `spec/universal/semantics.md` hash, the
27sidecar rules and the command interface are those of v1.
28
29## 2. Registry additions
30
31Languages / dialects (OMSA offset 5; operation offset 0 must equal it, as in v1):
32
33| code | language | pin |
34|---|---|---|
35| 5 | C++17 | ISO/IEC 14882:2017 |
36| 6 | Zig 0.17 | Zig 0.17 language release |
37| 7 | Go 1.27 | Go 1.27 language version (`go 1.27`) |
38
39Profiles (OMSA offset 6):
40
41| code | name | language | semantic header version |
42|---|---|---|---|
43| 7 | cpp17-uint64-pure-v1 | 5 | 2 |
44| 8 | zig-u64-wrapping-pure-v1 | 6 | 2 |
45| 9 | go-u64-pure-v1 | 7 | 2 |
46
47Each of profiles 7, 8 and 9 has exactly the typed-registry row of profile 1 (c17-uint64-pure-v1):
48
49- runtime 0 and ABI 1 only;
50- type 1 (u64) only; every other type refuses 68 (PROFILE_MISMATCH);
51- operations 1, 2, 3, 4, 5 and 9 only; operations 6, 7 and 8 refuse 68;
52- operation fields exactly as profile 1: constant (op 1) attribute 1, effects 0, alias 0, obligations
53 0, operands unused (65535); add/sub/mul/div (ops 2/3/4/5) attribute 1 (modulo 2^64), effects 0,
54 alias 0, immediate 0, both operands earlier type-1 results, obligations 1 for ops 2/3/4 and 3
55 (input-domain + nonzero-divisor) for op 5; input (op 9) attribute 0, effects 0, alias 0, obligations
56 1, no operands, unique slot immediate 0..5. Obligation 4 (source-explicit-masking) is never part of
57 these profiles; a unit carrying it refuses 72 (OBLIGATION_MISMATCH).
58- legality is computed exactly as for profile 1 (v1 "Native core API and commands"): profiles 7/8/9 are
59 neither profile 3 nor profile 6, so for target 2 u64 inputs, constants and modulo arithmetic return
60 3 (LOWERABLE_WITH_OBLIGATIONS) with their exact obligations when ABI and effects are allowed.
61
62Meaning of the u64 operations for each source language (what an importer must establish before it may
63emit the record; the codec checks only the record shape):
64
65- C++17 (7): `std::uint64_t` / `uint64_t` values; `+ - *` on two `uint64_t` operands are modulo 2^64
66 ([basic.fundamental] unsigned arithmetic). The profile assumes an implementation whose `int` is at
67 most 64 bits wide, so integral promotion never applies to `std::uint64_t`; the importer refuses any
68 expression whose operand types are not exactly `std::uint64_t`.
69- Zig 0.17 (8): `u64` values with the wrapping operators `+%`, `-%`, `*%`, which are modulo 2^64. The
70 plain operators `+`, `-`, `*` have checked illegal behavior on overflow and are not modulo 2^64; an
71 importer must not map them to ops 2/3/4.
72- Go 1.27 (9): `uint64` values; `+ - *` on unsigned integers are modulo 2^64 by the language
73 specification.
74
75Division (op 5) stays representable exactly as in profile 1 (nonzero-divisor obligation). Like the C
76importer, an importer for these profiles refuses division at the source level; in all three languages
77division by zero is not a value (C++ undefined behavior, Zig illegal behavior, Go run-time panic).
78
79## 3. The profile fixes the version
80
81The semantic header version is a function of the profile:
82
83- profiles 1..6 are valid only with semantic header version 1;
84- profiles 7..9 are valid only with semantic header version 2.
85
86(version 2, profile 1..6) and (version 1, profile 7..9) refuse 68 (PROFILE_MISMATCH). Profile 0 and
87profiles above 9 refuse 68 under either version. Consequence: every valid unit has exactly one
88admissible semantic header version byte, so no unit has two canonical encodings and therefore two
89identities.
90
91A v1 profile 7..9 unit already refused 68 under v1 (profiles above 6 were unknown), so this rule does
92not change any v1 verdict.
93
94## 4. Identities
95
96The domain strings are unchanged for both versions: semantic identity = SHA256(
97`omega.source.semantic.v1` || canonical semantic bytes); provenance identity = SHA256(
98`omega.source.provenance.v1` || complete canonical envelope). The `.v1` suffix names the hashing
99construction, not the semantic header version.
100
101No v2 identity can equal a v1 identity unless SHA256 collides: the hashed semantic bytes start with
102`OMSA` followed by the semantic header version byte, which is 1 for every v1 unit and 2 for every v2
103unit. Two preimages with the same domain prefix and different bytes at that fixed offset are different
104byte strings. The provenance preimage contains the semantic bytes at fixed envelope offset 13, so the
105same argument holds there (envelope offset 17). Section 3 makes the version byte a function of the
106other header fields, so the identity of a given unit is unique as well.
107
108Changing the meaning of profiles 1..6 is still not allowed; v2 adds codes only.
109
110## 5. Decode order (normative for v1 and v2)
111
112Statuses are those of v1 (64..78). A decoder checks in this order and returns the first failure; the
113same order gave every v1 verdict, and v2 adds only the version and profile cases marked "v2".
114`b` is the envelope, `s` = semantic bytes starting at envelope offset 13, `p` = sidecar bytes.
115
1161. total length > 8192: 67; total length < 13: 65; `b[0..4]` != `OMSB`: 65; `b[4]` != 1: 66.
1172. semantic length > 1324 or sidecar length > 4682: 67; total != 13 + both lengths: 65;
118 semantic length < 44: 65; `s[0..4]` != `OMSA`: 65.
1193. v2: `s[4]` not in {1, 2}: 66. `s[7]` (dialect version) != 1: 66.
1204. operation count 0 or > 64: 67; semantic length != 44 + 20 x count: 65; parent hash
121 `s[12..44]` != SHA256(`spec/universal/semantics.md`): 78.
1225. Profile row (all 68): profile 0 or > 9; language != the profile's language; v2: (version,
123 profile) pairing of section 3; runtime/ABI not allowed for the profile.
1246. For each operation i in record order: dialect byte != header language: 68; operation version != 1:
125 66; type 0 or > 4: 70; type not allowed by the profile (profile 3: type != 2; profile 6: any of
126 1..4; every other profile, including 7/8/9: type != 1): 68; opcode 0 or > 9: 69; then the
127 operation row below. This documents the order and rules the v1 core (`core.om` `checkop`,
128 `arith`, `memop`, `pureop`) already enforces for profiles 1..6; v2 adds no rule and changes no
129 v1 verdict. Profiles 7/8/9 follow exactly the profile 1 path. "Earlier result of type t" means an
130 operand index < i whose record has type t (65535 is never one). Within a row the first failing
131 check decides:
132 - op 1 (constant): type > 2: 70; attribute != type: 70; A != 65535: 70; B != 65535: 70;
133 obligations != 0: 72; effects != 0: 71; alias != 0: 71. The immediate is the constant (any u64).
134 - ops 2/3/4/5 (arithmetic): type > 2: 70; attribute != type: 70; A not an earlier result of the
135 same type: 70; same for B: 70; immediate != 0: 65; then for type 1: effects != 0: 71; alias != 0:
136 71; for type 2: effects != 20: 71; alias != 255: 71; finally obligations != required: 72, where
137 required is 1 for type 1 (plus 4 under profiles 4 and 6) and 8 for type 2, plus 2 for op 5.
138 Profiles 7/8/9 therefore require 1 for ops 2/3/4 and 3 for op 5.
139 - op 6 (dynamic call): profile != 6: 68; type != 3: 70; attribute != 3: 70; A not an earlier result
140 of type 3: 70; B != 65535: 70; immediate != 0: 65; effects != 63: 71; alias != 255: 71;
141 obligations != 8: 72.
142 - ops 7/8 (symbolic byte read/write): profile != 6: 68; type != 1: 70; attribute != 4: 70; A not an
143 earlier result of type 4 (the view): 70; B not an earlier result of type 1: 70; alias not in
144 1..8 and not 255: 71; alias != the alias byte of the view record A: 71 (alias equality: a byte
145 access carries exactly its view's alias set, so 255 on a view with alias 1 refuses 71, and 1 on a
146 view with alias 255 refuses 71); then op 8: immediate not an earlier result of type 1 (the value
147 stored): 70; op 7: immediate != 0: 65; then effects != 17 (op 7) or 19 (op 8): 71; obligations
148 != 24: 72.
149 - op 9 (input): attribute != 0: 70; A != 65535: 70; B != 65535: 70; immediate > 5: 67; immediate
150 equal to the immediate of an earlier op 9: 70; obligations != 1: 72; effects != 0: 71; then type
151 4: alias not in 1..8 and not 255: 71; any other type: alias != 0: 71.
152 Under profiles 1..5 and 7..9, ops 6/7/8 reach their row only with an allowed type and refuse 68 at
153 its first check (profile != 6).
1547. If the sidecar length is nonzero (`p` at envelope offset 13 + semantic length): sidecar length
155 < 74: 65; `p[0..4]` != `OMSP`: 65; `p[4]` != 1: 66; encoding > 1: 76; source length > 4096: 67;
156 sidecar length != 74 + 8 x count + source length: 65; `p[10..42]` != SHA256(s): 74;
157 `p[42..74]` != SHA256(source): 74; encoding 1 and source not strict UTF-8: 76; then for each span
158 in order: start > end or end > source length: 75; encoding 1 and start or end not on a codepoint
159 boundary (a boundary is the source length or a byte outside 0x80..0xBF): 75.
160
161`perform mode n` checks first: n > 8192: 67; mode 0 or > 6: 64. For `legality` (mode 6) the four
162capability bytes are checked next exactly as in v1 (fewer than 4 bytes: 65; target 0 or above 2,
163runtime above 2, ABI 0 or above 2, or effects above 63: 68), then the envelope after them.
164
165`encode` and `decode` emit the canonical envelope with the decoded semantic header version: decode
166followed by encode returns the input bytes exactly for v1 and for v2 units.
167
168## 6. Compatibility with v1 consumers
169
170The frozen #621 codec and `tests/universal/source-aware/reference.mjs` refuse every v2 unit with 66
171(UNKNOWN_VERSION) at step 3, before reading any v2 field, and write no output. The consumers built on
172the v1 core decode with it and report their own refusal: the lowering (`tools/adapters/lower`) and
173the C exporter (`tools/adapters/c-export`) exit 65 (`LOWER_MALFORMED`, `C_EXPORT_MALFORMED`) with no
174stdout, exactly as for a v1 envelope with an unknown semantic header version. The C importer reads C
175source, not envelopes, and emits only v1 profile 1 units. Adopting v2 in a consumer is a separate,
176coordinator-planned change; this file does not change any consumer.
177
178## 7. Implementation and build
179
180`src/source-aware/core.om` (the v1 core, sha256 `24c0837d05990fcb1daaafec13d2408d4359ae4fa6c9866307b73c5132c8b7eb`)
181stays byte-identical, because the lowering (`build/L831`) and C exporter (`build/L622`) builds prepend
182that path and their dispatchers pin its bytes. The v2 codec is the single handwritten seeded Omega file
183`src/source-aware/core-v2.om` with the same non-reentrant fixed-buffer API (`decode n`, `encode`,
184`perform mode n`); it accepts semantic header versions 1 and 2. After a successful `decode n` the global
185`M 8` holds the decoded semantic header version, next to the v1 fields `M 0..7`; consumers that
186prepend `core-v2.om` read the version there. `tools/source-aware/build-v2` compiles
187`src/source-aware/vendor/sha256.om`, `core-v2.om` and the unchanged `src/source-aware/main.om` with
188the same pinned bridge seed compiler as v1 (`191b776e…98e9`) into `build/L832/sa`; the commands are
189`SA_BUILD=build/L832 tools/source-aware/sa encode|decode|identity|provenance|replay|legality`.
190
191`make -f mk/source-aware-v2.mk test-source-aware-v2` runs the compatibility gate
192`tests/universal/source-aware/v2_compat.mjs`: frozen-v1 equivalence for every input whose envelope
193byte 17 is not 2, frozen-codec refusal of v2, the profile-1 corpus retargeted to profiles 7/8/9, stale
194state across interleaved requests, and the unchanged v1 gates. Receipts are unsigned development
195evidence only.