Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/spec/effect-cap64-migration.md # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / spec / effect-cap64-migration.md` 209 lines · 11201 bytes Raw Blame History Rendered 1 # Effect capability generations: 64-bit canonical migration 2 3 ```text 4 Document ID: SPEC-OMEGA-EFFECT-CAP64 5 Amends: SPEC-OMEGA-CANON-M4 (spec/canonical-encoding.md), spec/visor-authority.md 6 Gates: OMEGA_EFFECT_CAP64_ROUNDTRIP_PASS, OMEGA_EFFECT_CAP64_IDENTITY_PASS, 7 OMEGA_EFFECT_CAP64_STALE_REJECT_PASS, OMEGA_EFFECT_CAP64_AUTHORITY_PASS, 8 OMEGA_EFFECT_CAP64_REGRESSION_PASS 9 Authority: AIENOS `4c213863c840f77264e6851f5f6f393e80cfdb95` (aienos.lock; aienos#158) 10 ``` 11 12 ## 1. Problem 13 14 Aienux capability references are `(uint32 cap_id, uint64 generation)`. Since 15 aienos#158 a restarted table starts above every generation the old table used, 16 and every table seeds its generations from `CLOCK_BOOTTIME` ns << 8, so live 17 generations are normally above 2^32. Omega's runtime view (`aienos_cap.h`, 18 `RxCapRef`) is already 64-bit. 19 20 Omega's canonical effect object (`KIND_EFFECT`) was not. Its payload was the 21 host C struct `EffectPayload` copied byte for byte (`memcpy`, 176 bytes on 22 LP64: little-endian on the hosts I run, two bytes of tail padding), with 23 `uint32_t capability_generation`. `omega_build_effect` took a `uint32_t`, so a 24 live generation was cut to its low 32 bits before it was hashed. The authority 25 refused every such reference as `STALE_GEN`: fail closed, but an honest effect 26 could never be expressed, and the object's identity bound only half of the 27 generation. The same struct layout also contradicted SPEC-OMEGA-CANON-M4 §2 28 rule 4 ("payload big-endian"). 29 30 ## 2. Decision 31 32 Effect objects move to **object encoding version 0x02** with an explicit, 33 fixed, big-endian payload that carries the whole 64-bit generation. Every 34 other kind stays at version 0x01 and keeps its bytes and its SemanticIds. 35 36 ### 2.1 Canonical header version rule 37 38 The header byte at offset +0x04 of every canonical object encoding is the 39 object encoding version of that object's kind: 40 41 | kind | version written | version accepted by the decoder | 42 |---|---|---| 43 | `KIND_EFFECT` (0x08) | 0x02 | 0x02 only | 44 | every other kind | 0x01 | 0x01 only | 45 46 The decoder (`omega_graph_deserialize_binary`) calls 47 `omega_canonical_check_header(version, kind)` for each object and refuses the 48 whole graph on any mismatch: 49 50 - `(0x01, KIND_EFFECT)` -> `OMEGA_CANON_ERR_EFFECT_V1` (legacy effect, refused); 51 - `(0x02, other kind)` and any other version -> `OMEGA_CANON_ERR_VERSION`. 52 53 `(0x02, other kind)` is refused so that nobody can mint a second identity for 54 an unchanged object by writing a new version byte in front of old bytes. 55 56 ### 2.2 Effect payload v2 (178 bytes, big-endian) 57 58 ```text 59 Offset Len Field Encoding / rule 60 ------------------------------------------------------------------------------ 61 +0x00 2 resource_class u16 BE; must be != 0 62 +0x02 2 operation_code u16 BE 63 +0x04 4 capability_slot u32 BE (AIENOS cap_id) 64 +0x08 8 capability_generation u64 BE; all 64 bits significant, no reserved bits 65 +0x10 32 capability_ref SemanticId bytes; all-zero = unused 66 +0x30 2 param_len u16 BE; must be <= 128 67 +0x32 128 param_bytes bytes [0, param_len) meaningful; bytes 68 [param_len, 128) must be 0x00 69 ------------------------------------------------------------------------------ 70 total 0xB2 = 178 bytes (OMEGA_EFFECT_PAYLOAD_LEN); payload_len must equal it 71 ``` 72 73 - `omega_effect_payload_encode` writes this layout from the in-memory 74 `EffectPayload` (whose `capability_generation` is now `uint64_t`). It is a 75 plain serializer: it writes every field as given, so a test can still build 76 a malformed object on purpose. 77 - `omega_effect_payload_decode` is strict: exact length 178, resource != 0, 78 param_len <= 128, zero padding after the parameters. Anything else is 79 refused with a specific code. A 176-byte payload (the size of the old host 80 struct) is reported separately as `OMEGA_EFFECT_ERR_LEGACY_V1`. 81 - `omega_validate_object`, the codec decoder, the Visor effect request, and 82 the Visor verifier read effects only through the decoder. Nothing casts 83 payload bytes to `EffectPayload` any more. 84 - The encoding is canonical: one meaning has one byte string (fixed length, 85 fixed byte order, no padding bytes, zero fill required), so one meaning has 86 one SemanticId. 87 88 ### 2.3 Old bytes: refused, not reinterpreted 89 90 Old (version 0x01) effect bytes are **refused explicitly**; they are not 91 decoded with their old meaning and not accepted for inspection. 92 93 Why refuse rather than "decode with the original meaning and refuse for 94 authority use": 95 96 1. The only thing the old format could say about a live Aienux reference was 97 a truncated generation. There is no correct authority representation to 98 preserve, and the brief forbids keeping a wrong one alive. 99 2. Old bytes were a host-struct image (host byte order, padding). Their 100 meaning depended on the machine that wrote them, so there is no single 101 "original meaning" to decode on another host. 102 3. No old effect object is stored anywhere in this repository (evidence, 103 test vectors, corpora, session goldens): effects were only built in 104 memory by tests. Refusal costs nothing real. 105 4. Refusal is at the version byte, so no old byte string can ever be read as a 106 new one, whatever its payload looks like. (A length-only boundary would not 107 be enough: the old validator accepted any payload of at least 176 bytes, so 108 a 178-byte old payload was "valid" too.) 109 110 Old SemanticIds cannot collide with new ones: the header byte differs, so the 111 hashed byte strings differ. 112 113 ### 2.4 Identity binds the whole generation 114 115 `SemanticId = SHA256(canonical encoding)` and all eight generation bytes are 116 in the encoding, so two effects that differ in any generation bit (including 117 only above bit 31) have different ids. Changing the generation of a named 118 object without renaming it makes `visor_effect_request_build` refuse it 119 (digest != stored id). 120 121 ### 2.5 No truncation anywhere 122 123 The generation is `uint64_t` in: `omega_build_effect(..., uint64_t cap_gen)`, 124 `EffectPayload`, the wire payload, `VisorEffectRequest`, the Visor text and 125 JSON output (`PRIu64`), and the authority side (`AienosCapRef`, `RxCapRef`). 126 Checked by `grep` (recorded in the receipt): no `(uint32_t)` cast, `uint32_t` 127 parameter or `%u` format is applied to an effect capability generation in 128 `src/` or `tests/`. The console wiring that `tools/omega.c` held is now pure 129 OM-2 (`tools/omega*.om`, `src/visor/*.om`, retired C deleted), so its half of 130 the grep is `tools/effect_cap64_om_trunc.sh`: no OM-2 code line names a 131 generation together with a sub-64-bit type, a 16/32-bit codec helper or an 132 encode width below 8 bytes, with planted bite controls that must be caught. The only other `(uint32_t)` casts of a 133 capability generation are the low halves of split lo/hi stores in 134 `src/runtime/rx_coherent.c` and `src/runtime/rx_generation.c` (the high word 135 is stored next to them) and a deliberate truncation probe in 136 `tests/runtime/rx_r7_native.c`. 137 138 ### 2.6 Incidental decoder hardening 139 140 `omega_graph_deserialize_binary` copied counts and lengths from the stream 141 into fixed arrays without bounds. Since this change feeds it hostile bytes, it 142 now refuses (returns -1) an object count above `OMEGA_MAX_GRAPH_OBJECTS`, and 143 attribute, relation and constraint counts, key, value, constraint-payload and 144 object-payload lengths above their array sizes. No well-formed stream is 145 affected. 146 147 ## 3. Changed identities 148 149 Every `KIND_EFFECT` SemanticId changes (new header byte, new payload bytes). 150 No SemanticId of any other kind changes. No effect id was pinned in a golden 151 vector, receipt or corpus. The two effects built in-tree: 152 153 | Where | Builder call | Old id (`193a7e7`) | New id | 154 |---|---|---|---| 155 | `tools/omegatool.c` gate 10 (validate only) | `omega_build_effect(g, 1, 1, 0, 1)` | ``ff7aa9701f39e226ac7a8babaafd74c052b169e986f03bac8555d4d6bf4fc46e`` | ``13f2c858be4dd0dcde1f458cf6e87d468a4d2bac2f8355254c32a977bc4692eb`` | 156 | `tests/visor/test_visor_verify.c` case 11 | `omega_build_effect(fg, 1, 1, 3, 1)` | ``94d5b66158ff57354be51e44b3867b810c7a2afde8749a95722877ed01195bfb`` | ``d3873a85a31eaa1b33018edebbf7e6dfce8a36a49703217505555a884fde7988`` | 157 158 Why: version byte 0x01 -> 0x02, payload 176-byte LE host struct -> 178-byte 159 big-endian layout with a 64-bit generation. Neither test compares the id to a 160 constant; both still pass. The new ids are pinned by `test-effect-cap64` 161 (golden check). 162 163 ### 3.1 How the new ids were checked 164 165 The new ids above were computed twice: by `omega_build_effect` and, 166 independently, by hashing the §2.2 byte layout written out by hand 167 (``4f4d4730` 02 08 0000 0000 0000 `000000b2`` + payload). The test pins both new 168 ids and also checks that the hand-built v1 byte strings hash to the old ids, 169 so the refusal tests refuse the real old format. 170 171 ## 4. Tests (`make test-effect-cap64`) 172 173 `tests/effect/test_effect_cap64.c`, linked with the pinned Aienux 174 `libaienos_capability.a` (`4c21386`; `EFFECT_CAP64_CAP_LIB`, default 175 `$(AIENOS_CAP_LIB)`). Physics-free. Prints one line per gate: 176 177 - **ROUNDTRIP**: generations 0, 1, UINT32_MAX, UINT32_MAX+1, 1<<63, 178 0xFFFFFFFFFFFFFFFE, UINT64_MAX, and live Aienux generations, survive 179 build -> canonical encode -> OMGG serialize -> decode -> validate -> Visor 180 request (text and JSON print the exact decimal) with every field equal. 181 - **IDENTITY**: ids differ for generations that differ only in the high word 182 or only in the low word; changing the generation after naming makes the 183 Visor refuse; re-naming yields a new id; golden ids (§3.1). 184 - **STALE_REJECT**: hand-crafted bytes: v1 header on an effect, v2 header on 185 a non-effect, old 176-byte struct payload, generation with the high 32 bits 186 cut, non-zero padding, resource 0, param_len > 128, wrong length. All 187 refused with the specific code; a v1 non-effect object in the same stream 188 still decodes (control). 189 - **AUTHORITY** (real Aienux `4c21386`): live references forced to 190 UINT32_MAX, UINT32_MAX+1 and 1<<63 validate after the round trip; the 191 same reference with the high 32 bits cut is `STALE_GEN`; revoke -> 192 `REVOKED`; reclaim -> `STALE_GEN`; wrong slot -> refused; wrong right -> 193 `RIGHTS`; wrong resource -> `RESOURCE`; restart -> every pre-restart 194 reference (carried in an effect object) is `STALE_GEN` against the new 195 table while a newly minted one validates; 0xFFFFFFFFFFFFFFFE makes 196 restart `EXHAUSTED` (by design of aienos#158, recorded, not a failure). 197 - `test-visor-authority`: the GEN_FITS / CHECK_IF_REPR gating that existed 198 only because of this defect is removed; every Visor-path check is counted. 199 200 ## 5. Non-claims 201 202 - The accelerator `OmegaEffectIntent` / `OmegaEffectReceipt` 203 (`src/omega_accelerator.h`) still carry a 32-bit `capability_generation`. 204 They belong to the physics accelerator port model (its own capability 205 table), not to Aienux, and are not changed here. 206 - The Visor JSON prints the generation as an exact decimal integer. JSON 207 consumers that parse numbers as IEEE doubles lose precision above 2^53. 208 - No effect is executed; the mapping from `operation_code` / `resource_class` 209 to Aienux rights / resources is still a test convention.