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/aien-sovereign-core-mv/blob/main/om/runtime/membrane.om # aien-sovereign-core-mv AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-sovereign-core-mv / om / runtime / membrane.om` 375 lines ยท 8596 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note core/sovereign-core/om/runtime/membrane.om 3 note Pure OM-2 conversion of aien-runtime/src/{world,control,spine}.rs. 4 note Persistent WorldStore with monotonic capability attenuation on fork, idempotent 5 note RuntimeController, fail-closed capability membrane with containment freeze, 6 note and SHA-256 hash-chained execution journal / receipt emitter. 7 note Compose after si/directives/om2.om, inference_abi.om, and om/tls/sha2.om. 8 9 const RT_MAX_WORLDS ulong 64 10 const RT_MAX_OPS ulong 64 11 const RT_MAX_JOURNAL ulong 64 12 const RT_JOURNAL_HASH_TOTAL ulong 2048 13 const RT_CTRL_PROTO_VER ulong 1 14 15 note Capability bitmask 16 const RT_CAP_NONE ulong 0 17 const RT_CAP_INFER ulong 1 18 const RT_CAP_FORK_WORLD ulong 2 19 const RT_CAP_READ_FS ulong 4 20 const RT_CAP_WRITE_FS ulong 8 21 const RT_CAP_EXEC_CMD ulong 16 22 const RT_CAP_SEND_MSG ulong 32 23 const RT_CAP_ADMIN ulong 64 24 25 note Effect intent kinds 26 const RT_EFF_INFER ulong 1 27 const RT_EFF_WRITE_FS ulong 2 28 const RT_EFF_EXEC_CMD ulong 3 29 const RT_EFF_SEND_MSG ulong 4 30 const RT_EFF_ADMIN ulong 5 31 32 note Status / refusal codes 33 const RT_OK ulong 0 34 const RT_ERR_FULL ulong 1 35 const RT_ERR_NOT_FOUND ulong 2 36 const RT_ERR_CAP_ESCALATION ulong 3 37 const RT_ERR_UNAUTHORIZED ulong 4 38 const RT_ERR_CONTAINED ulong 5 39 const RT_ERR_DUPLICATE_OP ulong 6 40 const RT_ERR_BAD_PROTO ulong 7 41 const RT_ERR_JRN_SEQ ulong 8 42 const RT_ERR_JRN_PREV ulong 9 43 const RT_ERR_JRN_HASH ulong 10 44 45 text rt_jrn_dom "AIEN-RT-RECEIPT-V1" 46 47 note WorldStore metadata: [0]=world_cnt, [1]=next_world_id, [2]=contained_freeze(0/1), [3]=op_cnt, [4]=jrn_cnt, [5]=jrn_seq 48 global rt_meta ulong 8 49 50 note WorldManifest slots (0..63) 51 global rt_w_used ulong 64 52 global rt_w_id ulong 64 53 global rt_w_parent ulong 64 54 global rt_w_caps ulong 64 55 global rt_w_tok_root ulong 64 56 global rt_w_created ulong 64 57 58 note RuntimeController processed operation_id set (0..63) 59 global rt_ops_seen ulong 64 60 61 note SHA-256 hash-chained execution journal / receipts (0..63) 62 global rt_j_seq ulong 64 63 global rt_j_world ulong 64 64 global rt_j_op ulong 64 65 global rt_j_eff ulong 64 66 global rt_j_status ulong 64 67 global rt_j_prev uchar 2048 68 global rt_j_hash uchar 2048 69 70 fn rt_init to void 71 for i ulong 8 72 put rt_meta i 0 73 end 74 put rt_meta 1 1 75 for i ulong 64 76 put rt_w_used i 0 77 put rt_w_id i 0 78 put rt_w_parent i 0 79 put rt_w_caps i 0 80 put rt_w_tok_root i 0 81 put rt_w_created i 0 82 put rt_ops_seen i 0 83 put rt_j_seq i 0 84 put rt_j_world i 0 85 put rt_j_op i 0 86 put rt_j_eff i 0 87 put rt_j_status i 0 88 end 89 for i ulong RT_JOURNAL_HASH_TOTAL 90 put rt_j_prev i uchar 0 91 put rt_j_hash i uchar 0 92 end 93 end 94 95 fn rt_set_freeze frozen ulong to void 96 put rt_meta 2 frozen 97 end 98 99 fn rt_is_frozen to bool 100 ret ne get rt_meta 2 0 101 end 102 103 fn rt_world_count to ulong 104 ret get rt_meta 0 105 end 106 107 fn rt_journal_count to ulong 108 ret get rt_meta 4 109 end 110 111 fn rt_find_world wid ulong to ulong 112 for i ulong RT_MAX_WORLDS 113 if ne get rt_w_used i 0 114 if eq get rt_w_id i wid 115 ret i 116 end 117 end 118 end 119 ret `18446744073709551615` 120 end 121 122 fn rt_world_caps wid ulong to ulong 123 slot = rt_find_world wid 124 if eq slot `18446744073709551615` 125 ret 0 126 end 127 ret get rt_w_caps slot 128 end 129 130 fn rt_world_parent wid ulong to ulong 131 slot = rt_find_world wid 132 if eq slot `18446744073709551615` 133 ret 0 134 end 135 ret get rt_w_parent slot 136 end 137 138 note Create a root world manifest; returns world_id or 0 on full. 139 fn rt_world_create_root tok_root ulong caps ulong ts ulong to ulong 140 cnt = get rt_meta 0 141 if ge cnt RT_MAX_WORLDS 142 ret 0 143 end 144 wid = get rt_meta 1 145 put rt_meta 1 add wid 1 146 put rt_w_used cnt 1 147 put rt_w_id cnt wid 148 put rt_w_parent cnt 0 149 put rt_w_caps cnt caps 150 put rt_w_tok_root cnt tok_root 151 put rt_w_created cnt ts 152 put rt_meta 0 add cnt 1 153 ret wid 154 end 155 156 note Fork a child world from parent_id. 157 note Enforces strict capability non-escalation: child req_caps must be a subset of parent caps, 158 note and parent must hold RT_CAP_FORK_WORLD. Returns child world_id or 0 on refusal. 159 fn rt_world_fork parent_id ulong req_caps ulong ts ulong to ulong 160 pslot = rt_find_world parent_id 161 if eq pslot `18446744073709551615` 162 ret 0 163 end 164 pcaps = get rt_w_caps pslot 165 if eq and pcaps RT_CAP_FORK_WORLD 0 166 ret 0 167 end 168 note Refuse any requested bit not present in parent caps (fail-closed anti-escalation) 169 if ne and req_caps pcaps req_caps 170 ret 0 171 end 172 cnt = get rt_meta 0 173 if ge cnt RT_MAX_WORLDS 174 ret 0 175 end 176 wid = get rt_meta 1 177 put rt_meta 1 add wid 1 178 put rt_w_used cnt 1 179 put rt_w_id cnt wid 180 put rt_w_parent cnt parent_id 181 put rt_w_caps cnt req_caps 182 put rt_w_tok_root cnt get rt_w_tok_root pslot 183 put rt_w_created cnt ts 184 put rt_meta 0 add cnt 1 185 ret wid 186 end 187 188 note ---- RuntimeController idempotent operation_id tracking ---- 189 190 fn rt_ctrl_is_processed op_id ulong to bool 191 cnt = get rt_meta 3 192 for i ulong cnt bound 64 193 if eq get rt_ops_seen i op_id 194 ret true 195 end 196 end 197 ret false 198 end 199 200 fn rt_ctrl_begin_op proto_ver ulong op_id ulong to ulong 201 if ne proto_ver RT_CTRL_PROTO_VER 202 ret RT_ERR_BAD_PROTO 203 end 204 if eq op_id 0 205 ret RT_ERR_BAD_PROTO 206 end 207 if rt_ctrl_is_processed op_id 208 ret RT_ERR_DUPLICATE_OP 209 end 210 cnt = get rt_meta 3 211 if ge cnt RT_MAX_OPS 212 ret RT_ERR_FULL 213 end 214 put rt_ops_seen cnt op_id 215 put rt_meta 3 add cnt 1 216 ret RT_OK 217 end 218 219 note ---- SHA-256 hash-chained Execution Journal / Receipt Emitter ---- 220 221 fn rt_jrn_compute_hash idx ulong out_h edit uchar 32 to void 222 ctx = new ulong 40 0 223 sha256_init ctx 224 sha256_update ctx rt_jrn_dom 225 hdr = new uchar 40 0 226 abi_put_u64 hdr 0 get rt_j_seq idx 227 abi_put_u64 hdr 8 get rt_j_world idx 228 abi_put_u64 hdr 16 get rt_j_op idx 229 abi_put_u64 hdr 24 get rt_j_eff idx 230 abi_put_u64 hdr 32 get rt_j_status idx 231 sha256_update ctx hdr 232 prev = new uchar 32 0 233 pbase = mul idx 32 234 for i ulong 32 235 put prev i get rt_j_prev add pbase i 236 end 237 sha256_update ctx prev 238 sha256_final ctx out_h 239 end 240 241 fn rt_jrn_hash_eq a view uchar 32 b view uchar 32 to bool 242 diff = uchar 0 243 for i ulong 32 244 diff = or diff xor get a i get b i 245 end 246 ret eq diff uchar 0 247 end 248 249 fn rt_jrn_append wid ulong op_id ulong eff ulong status ulong to ulong 250 cnt = get rt_meta 4 251 if ge cnt RT_MAX_JOURNAL 252 ret RT_ERR_FULL 253 end 254 nseq = add get rt_meta 5 1 255 put rt_j_seq cnt nseq 256 put rt_j_world cnt wid 257 put rt_j_op cnt op_id 258 put rt_j_eff cnt eff 259 put rt_j_status cnt status 260 pbase = mul cnt 32 261 if eq cnt 0 262 for i ulong 32 263 put rt_j_prev add pbase i uchar 0 264 end 265 else 266 lbase = mul sub cnt 1 32 267 for i ulong 32 268 put rt_j_prev add pbase i get rt_j_hash add lbase i 269 end 270 end 271 h = new uchar 32 0 272 rt_jrn_compute_hash cnt h 273 for i ulong 32 274 put rt_j_hash add pbase i get h i 275 end 276 put rt_meta 4 add cnt 1 277 put rt_meta 5 nseq 278 ret RT_OK 279 end 280 281 note Verify entire execution journal chain from genesis (constant-time hash checks). 282 fn rt_journal_verify_chain to ulong 283 cnt = get rt_meta 4 284 exp_prev = new uchar 32 0 285 cur_prev = new uchar 32 0 286 stored_h = new uchar 32 0 287 comp_h = new uchar 32 0 288 for i ulong cnt bound 64 289 if ne get rt_j_seq i add i 1 290 ret RT_ERR_JRN_SEQ 291 end 292 pbase = mul i 32 293 for j ulong 32 294 put cur_prev j get rt_j_prev add pbase j 295 put stored_h j get rt_j_hash add pbase j 296 end 297 if not rt_jrn_hash_eq cur_prev exp_prev 298 ret RT_ERR_JRN_PREV 299 end 300 rt_jrn_compute_hash i comp_h 301 if not rt_jrn_hash_eq stored_h comp_h 302 ret RT_ERR_JRN_HASH 303 end 304 for j ulong 32 305 put exp_prev j get stored_h j 306 end 307 end 308 ret RT_OK 309 end 310 311 note Map effect intent kind to required capability bit (0 if unknown -> fail-closed). 312 fn rt_required_cap eff ulong to ulong 313 if eq eff RT_EFF_INFER 314 ret RT_CAP_INFER 315 end 316 if eq eff RT_EFF_WRITE_FS 317 ret RT_CAP_WRITE_FS 318 end 319 if eq eff RT_EFF_EXEC_CMD 320 ret RT_CAP_EXEC_CMD 321 end 322 if eq eff RT_EFF_SEND_MSG 323 ret RT_CAP_SEND_MSG 324 end 325 if eq eff RT_EFF_ADMIN 326 ret RT_CAP_ADMIN 327 end 328 ret 0 329 end 330 331 note Authorize and journal an effect intent for (world_id, op_id, eff) fail-closed. 332 fn rt_authorize_effect proto_ver ulong op_id ulong wid ulong eff ulong to ulong 333 cst = rt_ctrl_begin_op proto_ver op_id 334 if ne cst RT_OK 335 ret cst 336 end 337 slot = rt_find_world wid 338 if eq slot `18446744073709551615` 339 jst = rt_jrn_append wid op_id eff RT_ERR_NOT_FOUND 340 ret RT_ERR_NOT_FOUND 341 end 342 req_cap = rt_required_cap eff 343 if eq req_cap 0 344 jst = rt_jrn_append wid op_id eff RT_ERR_UNAUTHORIZED 345 ret RT_ERR_UNAUTHORIZED 346 end 347 if and rt_is_frozen ne eff RT_EFF_ADMIN 348 jst = rt_jrn_append wid op_id eff RT_ERR_CONTAINED 349 ret RT_ERR_CONTAINED 350 end 351 wcaps = get rt_w_caps slot 352 if eq and wcaps req_cap 0 353 jst = rt_jrn_append wid op_id eff RT_ERR_UNAUTHORIZED 354 ret RT_ERR_UNAUTHORIZED 355 end 356 jst = rt_jrn_append wid op_id eff RT_OK 357 if ne jst RT_OK 358 ret jst 359 end 360 ret RT_OK 361 end 362 363 note Test-only tamper helpers for negative chain-integrity controls. 364 fn rt_jrn_tamper_status idx ulong bad_st ulong to void 365 if lt idx get rt_meta 4 366 put rt_j_status idx bad_st 367 end 368 end 369 370 fn rt_jrn_tamper_prev idx ulong b_idx ulong mask uchar to void 371 if and lt idx get rt_meta 4 lt b_idx 32 372 off = add mul idx 32 b_idx 373 put rt_j_prev off xor get rt_j_prev off mask 374 end 375 end