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 / protocol / aien-protocols / ext / test.om

485 lines · 14288 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/aien-protocols/ext/test.om: positive, negative & mutant control test suite
3note for aien-protocols-mv extended crates (microjob, probe, evaluation-protocol, discovery-capsule).
4note Compose with:
5note si/directives/om2.om om/tls/sha2.om protocol/aien-protocols/core/types.om
6note protocol/aien-protocols/ext/microjob.om protocol/aien-protocols/ext/probe.om
7note protocol/aien-protocols/ext/evaluation.om protocol/aien-protocols/ext/discovery_capsule.om
8note protocol/aien-protocols/ext/test.om
9
10text tx_pass "PASS "
11text tx_fail "FAIL "
12text tx_nl "\n"
13
14text tx_c1 "microjob_lifecycle_envelope_payout_and_receipt"
15text tx_c2 "microjob_mutant_controls_flip_and_perturbation"
16text tx_c3 "probe_request_attestation_and_sla_verdicts"
17text tx_c4 "probe_mutant_controls_nonce_target_and_rtt"
18text tx_c5 "evaluation_binding_scores_adaptive_and_replay"
19text tx_c6 "evaluation_mutant_controls_seed_and_digest"
20text tx_c7 "discovery_capsule_lifecycle_recipient_routing_and_digest"
21text tx_c8 "discovery_capsule_mutant_controls_recip_and_ttl"
22text tx_done "PASS aien-protocols-ext all 8 test suites passed (pos+neg+mutant)\n"
23
24text tx_target_ok "spark-node-01.aien.internal:8443"
25text tx_target_sp "spark node 01"
26text tx_target_mut "spark-node-02.aien.internal:8443"
27
28text tx_recip_did "did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH"
29text tx_recip_rad "rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5"
30text tx_recip_node "node:spark-gb10-primary"
31text tx_recip_bad "http://evil.example/cap"
32text tx_recip_short "did:1"
33text tx_recip_sp "did:key:bad space"
34text tx_recip_mut "did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktI"
35
36fn tx_report name view uchar * ok bool to int
37if ok
38w1 = pt_write_all int 1 tx_pass
39w2 = pt_write_all int 1 name
40w3 = pt_write_all int 1 tx_nl
41if and w1 and w2 w3
42ret int 0
43end
44ret int 1
45end
46w4 = pt_write_all int 1 tx_fail
47w5 = pt_write_all int 1 name
48w6 = pt_write_all int 1 tx_nl
49if and w4 and w5 w6
50ret int 1
51end
52ret int 1
53end
54
55fn tx_fill_id dst edit uchar 16 v uchar to void
56for i ulong 16
57put dst i v
58end
59end
60
61fn tx_fill_dig dst edit uchar 32 v uchar to void
62for i ulong 32
63put dst i v
64end
65end
66
67fn test_microjob to bool
68note Positive transitions
69if ne mj_transition_check MJ_STAT_OPEN MJ_STAT_CLAIMED MJ_OK
70ret false
71end
72if ne mj_transition_check MJ_STAT_CLAIMED MJ_STAT_SUBMITTED MJ_OK
73ret false
74end
75if ne mj_transition_check MJ_STAT_SUBMITTED MJ_STAT_VERIFIED MJ_OK
76ret false
77end
78if ne mj_transition_check MJ_STAT_VERIFIED MJ_STAT_SETTLED MJ_OK
79ret false
80end
81note Negative transitions (skip state, backward, from terminal)
82if ne mj_transition_check MJ_STAT_OPEN MJ_STAT_SETTLED MJ_ERR_BAD_STATE
83ret false
84end
85if ne mj_transition_check MJ_STAT_SETTLED MJ_STAT_OPEN MJ_ERR_BAD_STATE
86ret false
87end
88if ne mj_transition_check MJ_STAT_EXPIRED MJ_STAT_CLAIMED MJ_ERR_BAD_STATE
89ret false
90end
91if ne mj_transition_check ulong 99 MJ_STAT_OPEN MJ_ERR_BAD_STATE
92ret false
93end
94note Envelope + deadline + payout positive/negative
95jid = new uchar 16 0
96nil_id = new uchar 16 0
97indig = new uchar 32 0
98outdig = new uchar 32 0
99zdig = new uchar 32 0
100tx_fill_id jid uchar 0x11
101tx_fill_dig indig uchar 0x22
102tx_fill_dig outdig uchar 0x33
103if ne mj_validate_envelope jid indig ulong 5000 ulong 60000 MJ_OK
104ret false
105end
106if ne mj_validate_envelope nil_id indig ulong 5000 ulong 60000 MJ_ERR_BAD_ID
107ret false
108end
109if ne mj_validate_envelope jid zdig ulong 5000 ulong 60000 MJ_ERR_DIGEST
110ret false
111end
112if ne mj_validate_envelope jid indig ulong 0 ulong 60000 MJ_ERR_BUDGET
113ret false
114end
115if ne mj_validate_envelope jid indig ulong 5000 ulong 0 MJ_ERR_TIMEOUT
116ret false
117end
118if ne mj_check_deadline ulong 1000 ulong 5000 ulong 5000 MJ_OK
119ret false
120end
121if ne mj_check_deadline ulong 1000 ulong 5000 ulong 5001 MJ_ERR_DEADLINE
122ret false
123end
124if ne mj_check_deadline ulong 5000 ulong 5000 ulong 5000 MJ_ERR_DEADLINE
125ret false
126end
127if ne mj_check_payout ulong 1000 ulong 850 ulong 50 ulong 100 MJ_OK
128ret false
129end
130if ne mj_check_payout ulong 1000 ulong 850 ulong 50 ulong 101 MJ_ERR_PAYOUT
131ret false
132end
133if ne mj_check_payout ulong 1000 ulong 1001 ulong 0 ulong 0 MJ_ERR_PAYOUT
134ret false
135end
136note Deterministic job and receipt digests
137d1 = new uchar 32 0
138d2 = new uchar 32 0
139mj_compute_digest jid indig ulong 5000 ulong 9000 d1
140mj_compute_digest jid indig ulong 5000 ulong 9000 d2
141if not digest_eq d1 d2
142ret false
143end
144rcpt = new uchar 32 0
145mj_compute_receipt_digest jid indig outdig rcpt
146if ne mj_verify_receipt jid indig outdig rcpt MJ_OK
147ret false
148end
149if ne mj_verify_receipt jid indig zdig rcpt MJ_ERR_DIGEST
150ret false
151end
152ret true
153end
154
155fn test_microjob_mutants to bool
156jid = new uchar 16 0
157indig = new uchar 32 0
158outdig = new uchar 32 0
159rcpt = new uchar 32 0
160tx_fill_id jid uchar 0x11
161tx_fill_dig indig uchar 0x22
162tx_fill_dig outdig uchar 0x33
163mj_compute_receipt_digest jid indig outdig rcpt
164note Mutant 1: flip 1 bit in receipt digest -> MUST fail
165put rcpt 31 xor get rcpt 31 uchar 1
166if ne mj_verify_receipt jid indig outdig rcpt MJ_ERR_DIGEST
167ret false
168end
169put rcpt 31 xor get rcpt 31 uchar 1
170note Mutant 2: flip 1 bit in output digest -> MUST fail
171put outdig 0 xor get outdig 0 uchar 1
172if ne mj_verify_receipt jid indig outdig rcpt MJ_ERR_DIGEST
173ret false
174end
175note Mutant 3: perturb payout conservation by +1 -> MUST fail
176if ne mj_check_payout ulong 10000 ulong 9000 ulong 501 ulong 500 MJ_ERR_PAYOUT
177ret false
178end
179note Mutant 4: perturb job digest reward by +1 -> MUST change digest
180d1 = new uchar 32 0
181d2 = new uchar 32 0
182mj_compute_digest jid indig ulong 5000 ulong 9000 d1
183mj_compute_digest jid indig ulong 5001 ulong 9000 d2
184if digest_eq d1 d2
185ret false
186end
187ret true
188end
189
190fn test_probe to bool
191nonce = new uchar 16 0
192nil_n = new uchar 16 0
193tx_fill_id nonce uchar 0x44
194if ne prb_validate_request PRB_KIND_LATENCY tx_target_ok nonce ulong 5000 PRB_OK
195ret false
196end
197if ne prb_validate_request ulong 0 tx_target_ok nonce ulong 5000 PRB_ERR_KIND
198ret false
199end
200if ne prb_validate_request PRB_KIND_LATENCY tx_target_sp nonce ulong 5000 PRB_ERR_TARGET
201ret false
202end
203if ne prb_validate_request PRB_KIND_LATENCY tx_target_ok nil_n ulong 5000 PRB_ERR_NONCE
204ret false
205end
206if ne prb_validate_request PRB_KIND_LATENCY tx_target_ok nonce ulong 300001 PRB_ERR_TIMEOUT
207ret false
208end
209note Attestation compute & verify
210ctx1 = new ulong 40 0
211ctx2 = new ulong 40 0
212att = new uchar 32 0
213prb_attest_head ctx1 PRB_KIND_INTEGRITY tx_target_ok nonce
214prb_attest_finish ctx1 ulong 0 ulong 1200 att
215prb_attest_head ctx2 PRB_KIND_INTEGRITY tx_target_ok nonce
216if ne prb_verify_attestation ctx2 ulong 0 ulong 1200 att PRB_OK
217ret false
218end
219note SLA verdicts
220if ne prb_classify_verdict ulong 0 ulong 1000 ulong 5000 ulong 10000 PRB_VERDICT_PASS
221ret false
222end
223if ne prb_classify_verdict ulong 0 ulong 6000 ulong 5000 ulong 10000 PRB_VERDICT_DEGRADED
224ret false
225end
226if ne prb_classify_verdict ulong 0 ulong 10001 ulong 5000 ulong 10000 PRB_VERDICT_TIMEOUT
227ret false
228end
229if ne prb_classify_verdict ulong 500 ulong 1000 ulong 5000 ulong 10000 PRB_VERDICT_FAIL
230ret false
231end
232if ne prb_classify_verdict ulong 0 ulong 1000 ulong 12000 ulong 10000 PRB_VERDICT_FAIL
233ret false
234end
235ret true
236end
237
238fn test_probe_mutants to bool
239nonce = new uchar 16 0
240tx_fill_id nonce uchar 0x55
241ctx1 = new ulong 40 0
242att = new uchar 32 0
243prb_attest_head ctx1 PRB_KIND_INTEGRITY tx_target_ok nonce
244prb_attest_finish ctx1 ulong 0 ulong 1200 att
245note Mutant 1: mutated RTT (+1us) -> MUST reject attestation
246ctx2 = new ulong 40 0
247prb_attest_head ctx2 PRB_KIND_INTEGRITY tx_target_ok nonce
248if ne prb_verify_attestation ctx2 ulong 0 ulong 1201 att PRB_ERR_ATTEST
249ret false
250end
251note Mutant 2: mutated target string -> MUST reject attestation
252ctx3 = new ulong 40 0
253prb_attest_head ctx3 PRB_KIND_INTEGRITY tx_target_mut nonce
254if ne prb_verify_attestation ctx3 ulong 0 ulong 1200 att PRB_ERR_ATTEST
255ret false
256end
257note Mutant 3: flipped 1 bit in nonce -> MUST reject attestation
258put nonce 0 xor get nonce 0 uchar 1
259ctx4 = new ulong 40 0
260prb_attest_head ctx4 PRB_KIND_INTEGRITY tx_target_ok nonce
261if ne prb_verify_attestation ctx4 ulong 0 ulong 1200 att PRB_ERR_ATTEST
262ret false
263end
264ret true
265end
266
267fn test_evaluation to bool
268eid = new uchar 16 0
269nil_id = new uchar 16 0
270mdig = new uchar 32 0
271ddig = new uchar 32 0
272zdig = new uchar 32 0
273bdig = new uchar 32 0
274tx_fill_id eid uchar 0x66
275tx_fill_dig mdig uchar 0x77
276tx_fill_dig ddig uchar 0x88
277ev_compute_binding eid mdig ddig ulong 42 bdig
278if ne ev_verify_binding eid mdig ddig ulong 42 bdig EV_OK
279ret false
280end
281if ne ev_verify_binding nil_id mdig ddig ulong 42 bdig EV_ERR_BINDING
282ret false
283end
284if ne ev_verify_binding eid zdig ddig ulong 42 bdig EV_ERR_DIGEST
285ret false
286end
287note Score validation
288if ne ev_score_validate ulong 85 ulong 100 ulong 8500 EV_OK
289ret false
290end
291if ne ev_score_validate ulong 85 ulong 100 ulong 8501 EV_ERR_SCORE_RANGE
292ret false
293end
294if ne ev_score_validate ulong 101 ulong 100 ulong 10000 EV_ERR_SCORE_RANGE
295ret false
296end
297if ne ev_score_validate ulong 0 ulong 0 ulong 0 EV_ERR_SAMPLE_COUNT
298ret false
299end
300note Adaptive decisions: min=20 max=100 accept=9000 reject=5000
301if ne ev_adaptive_decide ulong 10 ulong 10 ulong 20 ulong 100 ulong 9000 ulong 5000 EV_DEC_CONTINUE
302ret false
303end
304if ne ev_adaptive_decide ulong 19 ulong 20 ulong 20 ulong 100 ulong 9000 ulong 5000 EV_DEC_ACCEPT
305ret false
306end
307if ne ev_adaptive_decide ulong 10 ulong 20 ulong 20 ulong 100 ulong 9000 ulong 5000 EV_DEC_REJECT
308ret false
309end
310if ne ev_adaptive_decide ulong 75 ulong 100 ulong 20 ulong 100 ulong 9000 ulong 5000 EV_DEC_REJECT
311ret false
312end
313if ne ev_adaptive_decide ulong 40 ulong 50 ulong 20 ulong 100 ulong 9000 ulong 5000 EV_DEC_CONTINUE
314ret false
315end
316note Negative adaptive params: reject >= accept
317if ne ev_adaptive_decide ulong 10 ulong 20 ulong 20 ulong 100 ulong 5000 ulong 5000 EV_DEC_INVALID
318ret false
319end
320note Monotonic round replay guard
321if ne ev_check_monotonic_round ulong 7 ulong 8 EV_OK
322ret false
323end
324if ne ev_check_monotonic_round ulong 7 ulong 7 EV_ERR_REPLAY
325ret false
326end
327if ne ev_check_monotonic_round ulong 7 ulong 9 EV_ERR_REPLAY
328ret false
329end
330ret true
331end
332
333fn test_evaluation_mutants to bool
334eid = new uchar 16 0
335mdig = new uchar 32 0
336ddig = new uchar 32 0
337bdig = new uchar 32 0
338tx_fill_id eid uchar 0x66
339tx_fill_dig mdig uchar 0x77
340tx_fill_dig ddig uchar 0x88
341ev_compute_binding eid mdig ddig ulong 42 bdig
342note Mutant 1: seed mutated 42 -> 43 -> MUST reject
343if ne ev_verify_binding eid mdig ddig ulong 43 bdig EV_ERR_BINDING
344ret false
345end
346note Mutant 2: model digest bit-flipped -> MUST reject
347put mdig 15 xor get mdig 15 uchar 0x80
348if ne ev_verify_binding eid mdig ddig ulong 42 bdig EV_ERR_BINDING
349ret false
350end
351put mdig 15 xor get mdig 15 uchar 0x80
352note Mutant 3: claimed binding bit-flipped -> MUST reject
353put bdig 0 xor get bdig 0 uchar 1
354if ne ev_verify_binding eid mdig ddig ulong 42 bdig EV_ERR_BINDING
355ret false
356end
357ret true
358end
359
360fn test_discovery_capsule to bool
361note Lifecycle state machine
362if ne dc_transition_check DC_STATE_DRAFT DC_STATE_SEALED DC_OK
363ret false
364end
365if ne dc_transition_check DC_STATE_SEALED DC_STATE_ROUTED DC_OK
366ret false
367end
368if ne dc_transition_check DC_STATE_ROUTED DC_STATE_ROUTED DC_OK
369ret false
370end
371if ne dc_transition_check DC_STATE_ROUTED DC_STATE_DELIVERED DC_OK
372ret false
373end
374if ne dc_transition_check DC_STATE_DRAFT DC_STATE_DELIVERED DC_ERR_STATE
375ret false
376end
377if ne dc_transition_check DC_STATE_DELIVERED DC_STATE_ROUTED DC_ERR_STATE
378ret false
379end
380if ne dc_transition_check DC_STATE_REVOKED DC_STATE_SEALED DC_ERR_STATE
381ret false
382end
383note Recipient validation
384if ne dc_validate_recipient tx_recip_did DC_OK
385ret false
386end
387if ne dc_validate_recipient tx_recip_rad DC_OK
388ret false
389end
390if ne dc_validate_recipient tx_recip_node DC_OK
391ret false
392end
393if ne dc_validate_recipient tx_recip_bad DC_ERR_RECIPIENT
394ret false
395end
396if ne dc_validate_recipient tx_recip_short DC_ERR_RECIPIENT
397ret false
398end
399if ne dc_validate_recipient tx_recip_sp DC_ERR_RECIPIENT
400ret false
401end
402note Routing hops & TTL
403if ne dc_check_routing ulong 3 ulong 8 ulong 1000 ulong 600 ulong 1500 DC_OK
404ret false
405end
406if ne dc_check_routing ulong 9 ulong 8 ulong 1000 ulong 600 ulong 1500 DC_ERR_HOPS
407ret false
408end
409if ne dc_check_routing ulong 1 ulong 17 ulong 1000 ulong 600 ulong 1500 DC_ERR_HOPS
410ret false
411end
412if ne dc_check_routing ulong 1 ulong 8 ulong 1000 ulong 600 ulong 1601 DC_ERR_TTL
413ret false
414end
415if ne dc_check_routing ulong 1 ulong 8 ulong 1000 ulong 600 ulong 999 DC_ERR_TTL
416ret false
417end
418note Capsule validation & digest
419cid = new uchar 16 0
420pdig = new uchar 32 0
421cdig = new uchar 32 0
422tx_fill_id cid uchar 0x99
423tx_fill_dig pdig uchar 0xaa
424if ne dc_verify_capsule cid tx_recip_did pdig ulong 600 ulong 8 DC_OK
425ret false
426end
427ctx1 = new ulong 40 0
428ctx2 = new ulong 40 0
429dc_hash_head ctx1 cid tx_recip_did pdig
430dc_hash_finish ctx1 ulong 600 ulong 8 cdig
431dc_hash_head ctx2 cid tx_recip_did pdig
432if ne dc_verify_digest ctx2 ulong 600 ulong 8 cdig DC_OK
433ret false
434end
435ret true
436end
437
438fn test_discovery_capsule_mutants to bool
439cid = new uchar 16 0
440pdig = new uchar 32 0
441cdig = new uchar 32 0
442tx_fill_id cid uchar 0x99
443tx_fill_dig pdig uchar 0xaa
444ctx1 = new ulong 40 0
445dc_hash_head ctx1 cid tx_recip_did pdig
446dc_hash_finish ctx1 ulong 600 ulong 8 cdig
447note Mutant 1: recipient last char mutated H -> I -> MUST reject
448ctx2 = new ulong 40 0
449dc_hash_head ctx2 cid tx_recip_mut pdig
450if ne dc_verify_digest ctx2 ulong 600 ulong 8 cdig DC_ERR_DIGEST
451ret false
452end
453note Mutant 2: TTL mutated 600 -> 601 -> MUST reject
454ctx3 = new ulong 40 0
455dc_hash_head ctx3 cid tx_recip_did pdig
456if ne dc_verify_digest ctx3 ulong 601 ulong 8 cdig DC_ERR_DIGEST
457ret false
458end
459note Mutant 3: max_hops mutated 8 -> 9 -> MUST reject
460ctx4 = new ulong 40 0
461dc_hash_head ctx4 cid tx_recip_did pdig
462if ne dc_verify_digest ctx4 ulong 600 ulong 9 cdig DC_ERR_DIGEST
463ret false
464end
465ret true
466end
467
468fn main to int
469fails = int 0
470fails = add fails tx_report tx_c1 test_microjob
471fails = add fails tx_report tx_c2 test_microjob_mutants
472fails = add fails tx_report tx_c3 test_probe
473fails = add fails tx_report tx_c4 test_probe_mutants
474fails = add fails tx_report tx_c5 test_evaluation
475fails = add fails tx_report tx_c6 test_evaluation_mutants
476fails = add fails tx_report tx_c7 test_discovery_capsule
477fails = add fails tx_report tx_c8 test_discovery_capsule_mutants
478if ne fails int 0
479ret int 1
480end
481if not pt_write_all int 1 tx_done
482ret int 1
483end
484ret int 0
485end