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 / core / sovereign-core / om / runtime / membrane.om

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