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_test.om

312 lines · 6744 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note core/sovereign-core/om/store/closure_test.om
3note Positive, negative, and mutant test suite for core/sovereign-core/om/store/closure.om.
4note Compose with:
5note si/directives/om2.om om/tls/sha2.om core/sovereign-core/om/store/closure.om
6note core/sovereign-core/om/store/closure_test.om
7
8text cls_t_pass "PASS "
9text cls_t_fail "FAIL "
10text cls_t_nl "\n"
11text cls_t_all_ok "CLOSURE TEST SUITE PASS\n"
12text cls_t_all_bad "CLOSURE TEST SUITE FAIL\n"
13
14text cls_t_n1 "cls_pos_verified_dag_and_deterministic_root"
15text cls_t_n2 "cls_neg_dirty_workspace_and_dirty_artifact"
16text cls_t_n3 "cls_neg_missing_unobserved_and_mismatched_digest"
17text cls_t_n4 "cls_neg_empty_missing_dep_and_cycle_detection"
18text cls_t_n5 "cls_mutant_pin_tamper_and_root_sensitivity"
19
20text cls_art_a "artifact:alpha:v1:seed-omc"
21text cls_art_b "artifact:beta:v1:runtime-core"
22text cls_art_c "artifact:gamma:v1:closure-leaf"
23text cls_art_b_bad "artifact:beta:v1:runtime-corX"
24
25global cls_t_fails ulong 1
26
27fn cls_t_w s view uchar * to void
28n = len s
29off = ulong 0
30while lt off n bound 256
31k = write 1 s off sub n off
32if le k 0
33break
34end
35off = add off ulong k
36end
37end
38
39fn cls_t_rep name view uchar * ok bool to void
40if ok
41cls_t_w cls_t_pass
42else
43cls_t_w cls_t_fail
44put cls_t_fails 0 add get cls_t_fails 0 1
45end
46cls_t_w name
47cls_t_w cls_t_nl
48end
49
50fn cls_t_sha msg view uchar * out_h edit uchar 32 to void
51ctx = new ulong 40 0
52sha256_init ctx
53sha256_update ctx msg
54sha256_final ctx out_h
55end
56
57note Test 1 (POSITIVE): 3-node DAG (10 -> 20 -> 30), clean tree, matching SHA-256 digests, deterministic root.
58fn test_cls_pos_dag to bool
59cls_init
60ha = new uchar 32 0
61hb = new uchar 32 0
62hc = new uchar 32 0
63cls_t_sha cls_art_a ha
64cls_t_sha cls_art_b hb
65cls_t_sha cls_art_c hc
66if ne cls_add_pin 10 ha 0 CLS_OK
67ret false
68end
69if ne cls_add_pin 20 hb 0 CLS_OK
70ret false
71end
72if ne cls_add_pin 30 hc 0 CLS_OK
73ret false
74end
75if ne cls_add_dep 10 20 CLS_OK
76ret false
77end
78if ne cls_add_dep 20 30 CLS_OK
79ret false
80end
81if ne cls_observe_payload 10 cls_art_a CLS_OK
82ret false
83end
84if ne cls_observe_payload 20 cls_art_b CLS_OK
85ret false
86end
87if ne cls_observe_payload 30 cls_art_c CLS_OK
88ret false
89end
90r1 = new uchar 32 0
91r2 = new uchar 32 0
92if ne cls_verify_closure r1 CLS_OK
93ret false
94end
95if cls_is_zero_hash r1
96ret false
97end
98if ne cls_verify_closure r2 CLS_OK
99ret false
100end
101if not cls_hash_eq r1 r2
102ret false
103end
104if ne cls_ok_count 2
105ret false
106end
107ret true
108end
109
110note Test 2 (NEGATIVE): Dirty workspace flag and per-artifact dirty flag both refused.
111fn test_cls_neg_dirty to bool
112cls_init
113ha = new uchar 32 0
114cls_t_sha cls_art_a ha
115if ne cls_add_pin 10 ha 0 CLS_OK
116ret false
117end
118if ne cls_observe_payload 10 cls_art_a CLS_OK
119ret false
120end
121cls_set_workspace_dirty 1
122root = new uchar 32 0
123if ne cls_verify_closure root CLS_ERR_DIRTY_TREE
124ret false
125end
126if not cls_is_zero_hash root
127ret false
128end
129note Clear workspace dirty, add a dirty artifact -> still refused
130cls_set_workspace_dirty 0
131hb = new uchar 32 0
132cls_t_sha cls_art_b hb
133if ne cls_add_pin 20 hb 1 CLS_OK
134ret false
135end
136if ne cls_observe_payload 20 cls_art_b CLS_OK
137ret false
138end
139if ne cls_verify_closure root CLS_ERR_DIRTY_TREE
140ret false
141end
142if ne cls_deny_count 2
143ret false
144end
145ret true
146end
147
148note Test 3 (NEGATIVE): Missing/zero digest, duplicate pin, unobserved pin, mismatched payload digest.
149fn test_cls_neg_digests to bool
150cls_init
151zero_h = new uchar 32 0
152if ne cls_add_pin 10 zero_h 0 CLS_ERR_MISSING_DIGEST
153ret false
154end
155ha = new uchar 32 0
156hb = new uchar 32 0
157cls_t_sha cls_art_a ha
158cls_t_sha cls_art_b hb
159if ne cls_add_pin 10 ha 0 CLS_OK
160ret false
161end
162if ne cls_add_pin 10 ha 0 CLS_ERR_DUP_PIN
163ret false
164end
165if ne cls_observe_digest 10 zero_h CLS_ERR_MISSING_DIGEST
166ret false
167end
168if ne cls_observe_digest 999 ha CLS_ERR_NOT_FOUND
169ret false
170end
171note Unobserved pin must fail verification
172root = new uchar 32 0
173if ne cls_verify_closure root CLS_ERR_UNOBSERVED
174ret false
175end
176note Observe tampered payload -> CLS_ERR_DIGEST_MISMATCH
177if ne cls_observe_payload 10 cls_art_b_bad CLS_OK
178ret false
179end
180if ne cls_verify_closure root CLS_ERR_DIGEST_MISMATCH
181ret false
182end
183if not cls_is_zero_hash root
184ret false
185end
186ret true
187end
188
189note Test 4 (NEGATIVE): Empty closure, missing dependency node, and 3-node cycle refusal.
190fn test_cls_neg_graph to bool
191cls_init
192root = new uchar 32 0
193if ne cls_verify_closure root CLS_ERR_EMPTY
194ret false
195end
196ha = new uchar 32 0
197hb = new uchar 32 0
198hc = new uchar 32 0
199cls_t_sha cls_art_a ha
200cls_t_sha cls_art_b hb
201cls_t_sha cls_art_c hc
202if ne cls_add_pin 1 ha 0 CLS_OK
203ret false
204end
205if ne cls_add_pin 2 hb 0 CLS_OK
206ret false
207end
208if ne cls_observe_payload 1 cls_art_a CLS_OK
209ret false
210end
211if ne cls_observe_payload 2 cls_art_b CLS_OK
212ret false
213end
214note Missing dep node 99
215if ne cls_add_dep 1 99 CLS_OK
216ret false
217end
218if ne cls_verify_closure root CLS_ERR_MISSING_DEP
219ret false
220end
221note Rebuild with 3-node cycle 1 -> 2 -> 3 -> 1
222cls_init
223if ne cls_add_pin 1 ha 0 CLS_OK
224ret false
225end
226if ne cls_add_pin 2 hb 0 CLS_OK
227ret false
228end
229if ne cls_add_pin 3 hc 0 CLS_OK
230ret false
231end
232if ne cls_observe_payload 1 cls_art_a CLS_OK
233ret false
234end
235if ne cls_observe_payload 2 cls_art_b CLS_OK
236ret false
237end
238if ne cls_observe_payload 3 cls_art_c CLS_OK
239ret false
240end
241if ne cls_add_dep 1 2 CLS_OK
242ret false
243end
244if ne cls_add_dep 2 3 CLS_OK
245ret false
246end
247if ne cls_add_dep 3 1 CLS_OK
248ret false
249end
250if ne cls_verify_closure root CLS_ERR_CYCLE
251ret false
252end
253ret true
254end
255
256note Test 5 (MUTANT CONTROLS): 1-bit tamper in pinned expected digest fails; changed artifact changes root.
257fn test_cls_mutant_controls to bool
258cls_init
259ha = new uchar 32 0
260hb = new uchar 32 0
261cls_t_sha cls_art_a ha
262cls_t_sha cls_art_b hb
263if ne cls_add_pin 10 ha 0 CLS_OK
264ret false
265end
266if ne cls_observe_payload 10 cls_art_a CLS_OK
267ret false
268end
269r1 = new uchar 32 0
270if ne cls_verify_closure r1 CLS_OK
271ret false
272end
273note Mutant A: flip 1 bit in stored expected hash of pin 0 -> mismatch
274orig = get cls_exp_hash 15
275put cls_exp_hash 15 xor orig uchar 1
276r_bad = new uchar 32 0
277if ne cls_verify_closure r_bad CLS_ERR_DIGEST_MISMATCH
278ret false
279end
280put cls_exp_hash 15 orig
281note Mutant B: replace artifact 10 with beta (matching pin & payload) -> root must differ
282cls_init
283if ne cls_add_pin 10 hb 0 CLS_OK
284ret false
285end
286if ne cls_observe_payload 10 cls_art_b CLS_OK
287ret false
288end
289r2 = new uchar 32 0
290if ne cls_verify_closure r2 CLS_OK
291ret false
292end
293if cls_hash_eq r1 r2
294ret false
295end
296ret true
297end
298
299fn main to int
300put cls_t_fails 0 0
301cls_t_rep cls_t_n1 test_cls_pos_dag
302cls_t_rep cls_t_n2 test_cls_neg_dirty
303cls_t_rep cls_t_n3 test_cls_neg_digests
304cls_t_rep cls_t_n4 test_cls_neg_graph
305cls_t_rep cls_t_n5 test_cls_mutant_controls
306if eq get cls_t_fails 0 0
307cls_t_w cls_t_all_ok
308ret 0
309end
310cls_t_w cls_t_all_bad
311ret 1
312end