interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-sovereign-core-mv / om / store / closure.om

322 lines · 7353 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note core/sovereign-core/om/store/closure.om
3note Pure OM-2 conversion of aien-closure (manifest, digest, graph, declare, verify).
4note Verified closure and artifact pin checker refusing missing/mismatched SHA-256
5note digests, dirty workspace or artifact flags, missing dependencies, and cycles.
6note Compose after si/directives/om2.om and om/tls/sha2.om.
7
8const CLS_MAX_PINS ulong 32
9const CLS_MAX_EDGES ulong 64
10const CLS_HASH_BYTES ulong 32
11const CLS_HASH_TOTAL ulong 1024
12const CLS_NONE ulong 18446744073709551615
13
14note Status and refusal codes
15const CLS_OK ulong 0
16const CLS_ERR_FULL ulong 1
17const CLS_ERR_DUP_PIN ulong 2
18const CLS_ERR_NOT_FOUND ulong 3
19const CLS_ERR_DIRTY_TREE ulong 4
20const CLS_ERR_MISSING_DIGEST ulong 5
21const CLS_ERR_DIGEST_MISMATCH ulong 6
22const CLS_ERR_MISSING_DEP ulong 7
23const CLS_ERR_CYCLE ulong 8
24const CLS_ERR_EMPTY ulong 9
25const CLS_ERR_UNOBSERVED ulong 10
26
27text cls_root_dom "AIEN-CLOSURE-V1"
28
29note Metadata: [0]=pin_cnt, [1]=edge_cnt, [2]=workspace_dirty(0/1), [3]=ok_cnt, [4]=deny_cnt
30global cls_meta ulong 8
31
32note Pinned artifact table (0..31)
33global cls_pin_id ulong 32
34global cls_pin_dirty ulong 32
35global cls_pin_obs ulong 32
36global cls_exp_hash uchar 1024
37global cls_obs_hash uchar 1024
38
39note Dependency graph edges (0..63)
40global cls_edge_from ulong 64
41global cls_edge_to ulong 64
42
43note Scratch arrays for Kahn's cycle detection
44global cls_indeg ulong 32
45global cls_done ulong 32
46
47fn cls_init to void
48for i ulong 8
49put cls_meta i 0
50end
51for i ulong CLS_MAX_PINS
52put cls_pin_id i 0
53put cls_pin_dirty i 0
54put cls_pin_obs i 0
55put cls_indeg i 0
56put cls_done i 0
57end
58for i ulong CLS_HASH_TOTAL
59put cls_exp_hash i uchar 0
60put cls_obs_hash i uchar 0
61end
62for i ulong CLS_MAX_EDGES
63put cls_edge_from i 0
64put cls_edge_to i 0
65end
66end
67
68fn cls_set_workspace_dirty dirty ulong to void
69put cls_meta 2 dirty
70end
71
72fn cls_pin_count to ulong
73ret get cls_meta 0
74end
75
76fn cls_edge_count to ulong
77ret get cls_meta 1
78end
79
80fn cls_ok_count to ulong
81ret get cls_meta 3
82end
83
84fn cls_deny_count to ulong
85ret get cls_meta 4
86end
87
88fn cls_is_zero_hash h view uchar 32 to bool
89acc = uchar 0
90for i ulong 32
91acc = or acc get h i
92end
93ret eq acc uchar 0
94end
95
96fn cls_hash_eq a view uchar 32 b view uchar 32 to bool
97diff = uchar 0
98for i ulong 32
99diff = or diff xor get a i get b i
100end
101ret eq diff uchar 0
102end
103
104fn cls_put_u64 buf edit uchar * off ulong v ulong to void
105for i ulong 8
106sh = mul i 8
107put buf add off i uchar and shr v sh ulong 255
108end
109end
110
111fn cls_find_pin art_id ulong to ulong
112cnt = get cls_meta 0
113for i ulong cnt bound 32
114if eq get cls_pin_id i art_id
115ret i
116end
117end
118ret CLS_NONE
119end
120
121note Register a pinned artifact with its expected SHA-256 digest and per-artifact dirty flag.
122fn cls_add_pin art_id ulong exp_hash view uchar 32 dirty ulong to ulong
123if cls_is_zero_hash exp_hash
124ret CLS_ERR_MISSING_DIGEST
125end
126if ne cls_find_pin art_id CLS_NONE
127ret CLS_ERR_DUP_PIN
128end
129cnt = get cls_meta 0
130if ge cnt CLS_MAX_PINS
131ret CLS_ERR_FULL
132end
133put cls_pin_id cnt art_id
134put cls_pin_dirty cnt dirty
135put cls_pin_obs cnt 0
136hbase = mul cnt CLS_HASH_BYTES
137for i ulong 32
138put cls_exp_hash add hbase i get exp_hash i
139put cls_obs_hash add hbase i uchar 0
140end
141put cls_meta 0 add cnt 1
142ret CLS_OK
143end
144
145note Register a directed dependency edge from_id -> to_id.
146fn cls_add_dep from_id ulong to_id ulong to ulong
147ecnt = get cls_meta 1
148if ge ecnt CLS_MAX_EDGES
149ret CLS_ERR_FULL
150end
151put cls_edge_from ecnt from_id
152put cls_edge_to ecnt to_id
153put cls_meta 1 add ecnt 1
154ret CLS_OK
155end
156
157note Record an observed 32-byte SHA-256 digest for a pinned artifact.
158fn cls_observe_digest art_id ulong obs_hash view uchar 32 to ulong
159idx = cls_find_pin art_id
160if eq idx CLS_NONE
161ret CLS_ERR_NOT_FOUND
162end
163if cls_is_zero_hash obs_hash
164ret CLS_ERR_MISSING_DIGEST
165end
166hbase = mul idx CLS_HASH_BYTES
167for i ulong 32
168put cls_obs_hash add hbase i get obs_hash i
169end
170put cls_pin_obs idx 1
171ret CLS_OK
172end
173
174note Hash payload bytes with SHA-256 and record as the observed digest for art_id.
175fn cls_observe_payload art_id ulong payload view uchar * to ulong
176idx = cls_find_pin art_id
177if eq idx CLS_NONE
178ret CLS_ERR_NOT_FOUND
179end
180dig = new uchar 32 0
181ctx = new ulong 40 0
182sha256_init ctx
183sha256_update ctx payload
184sha256_final ctx dig
185ret cls_observe_digest art_id dig
186end
187
188note Verify one pinned artifact slot: clean flag, observed, non-zero, constant-time digest match.
189fn cls_check_pin idx ulong to ulong
190if ne get cls_pin_dirty idx 0
191ret CLS_ERR_DIRTY_TREE
192end
193if eq get cls_pin_obs idx 0
194ret CLS_ERR_UNOBSERVED
195end
196exp_h = new uchar 32 0
197obs_h = new uchar 32 0
198hbase = mul idx CLS_HASH_BYTES
199for i ulong 32
200put exp_h i get cls_exp_hash add hbase i
201put obs_h i get cls_obs_hash add hbase i
202end
203if or cls_is_zero_hash exp_h cls_is_zero_hash obs_h
204ret CLS_ERR_MISSING_DIGEST
205end
206if not cls_hash_eq exp_h obs_h
207ret CLS_ERR_DIGEST_MISMATCH
208end
209ret CLS_OK
210end
211
212note Decrement in-degrees of all targets reachable from node u_idx.
213fn cls_peel_node u_idx ulong ecnt ulong to void
214uid = get cls_pin_id u_idx
215for e ulong ecnt bound 64
216if eq get cls_edge_from e uid
217v_idx = cls_find_pin get cls_edge_to e
218if ne v_idx CLS_NONE
219deg = get cls_indeg v_idx
220if gt deg 0
221put cls_indeg v_idx sub deg 1
222end
223end
224end
225end
226end
227
228note Verify dependency graph: every edge endpoint exists and the graph is acyclic (Kahn's sort).
229fn cls_check_graph to ulong
230cnt = get cls_meta 0
231ecnt = get cls_meta 1
232for i ulong cnt bound 32
233put cls_indeg i 0
234put cls_done i 0
235end
236for e ulong ecnt bound 64
237u_idx = cls_find_pin get cls_edge_from e
238v_idx = cls_find_pin get cls_edge_to e
239if or eq u_idx CLS_NONE eq v_idx CLS_NONE
240ret CLS_ERR_MISSING_DEP
241end
242put cls_indeg v_idx add get cls_indeg v_idx 1
243end
244removed = ulong 0
245for step ulong cnt bound 32
246found = CLS_NONE
247for i ulong cnt bound 32
248if and eq get cls_done i 0 eq get cls_indeg i 0
249found = i
250break
251end
252end
253if eq found CLS_NONE
254ret CLS_ERR_CYCLE
255end
256put cls_done found 1
257removed = add removed 1
258cls_peel_node found ecnt
259end
260if ne removed cnt
261ret CLS_ERR_CYCLE
262end
263ret CLS_OK
264end
265
266note Compute deterministic SHA-256 closure root over all verified pins.
267fn cls_compute_root out_root edit uchar 32 to void
268ctx = new ulong 40 0
269sha256_init ctx
270sha256_update ctx cls_root_dom
271cnt = get cls_meta 0
272hdr = new uchar 8 0
273cls_put_u64 hdr 0 cnt
274sha256_update ctx hdr
275hbuf = new uchar 32 0
276for i ulong cnt bound 32
277cls_put_u64 hdr 0 get cls_pin_id i
278sha256_update ctx hdr
279hbase = mul i CLS_HASH_BYTES
280for j ulong 32
281put hbuf j get cls_exp_hash add hbase j
282end
283sha256_update ctx hbuf
284end
285sha256_final ctx out_root
286end
287
288fn cls_record_verdict st ulong to ulong
289if eq st CLS_OK
290put cls_meta 3 add get cls_meta 3 1
291else
292put cls_meta 4 add get cls_meta 4 1
293end
294ret st
295end
296
297note Fail-closed closure verification: checks emptiness, dirty flags, all pin digests, and DAG acyclicity.
298note Writes 32-byte canonical closure root into out_root only on CLS_OK (zeroes out_root on failure).
299fn cls_verify_closure out_root edit uchar 32 to ulong
300for i ulong 32
301put out_root i uchar 0
302end
303cnt = get cls_meta 0
304if eq cnt 0
305ret cls_record_verdict CLS_ERR_EMPTY
306end
307if ne get cls_meta 2 0
308ret cls_record_verdict CLS_ERR_DIRTY_TREE
309end
310for i ulong cnt bound 32
311st = cls_check_pin i
312if ne st CLS_OK
313ret cls_record_verdict st
314end
315end
316gst = cls_check_graph
317if ne gst CLS_OK
318ret cls_record_verdict gst
319end
320cls_compute_root out_root
321ret cls_record_verdict CLS_OK
322end