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 / aienux / atlas / test.om

464 lines · 12199 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/atlas/test.om: Comprehensive pure-Omega test suite for Atlas stage-0 boot verifier.
3note Covers NIST FIPS 180-4 SHA-256 KATs, canonical 256-byte PHYSICS-0 staging payload,
4note exhaustive 256-offset 1-bit payload mutation sweep, bad magic/version/alignment,
5note entry_off bounds, stage_len overflow, epoch rollback, truncation, memmap disjointness,
6note and fail-closed descriptor emitter refusal.
7note Compose with: si/directives/om2.om aienux/atlas/lib.om aienux/atlas/test.om
8
9text t_abc "abc"
10text t_56 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
11text t_112 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
12
13text h_empty "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
14text h_abc "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
15text h_56 "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
16text h_112 "59f109d9533b2b70e7c3b814a2bd218f78ea5d3714455bc67987cf0d664399cf"
17text h_phys0 "e1d89bb1e0854ebaccd2be5c756c8a2ff8c5ecc8c0f90b4abd461fb7bf98374c"
18
19note First 160 non-zero bytes of canonical upstream physics-0.bin (remaining 96 bytes are 0x00)
20text p0_hex0 "430400585f0003eb81010054240400581f0004eb210100543f0004f1e1000054"
21text p0_hex1 "050840f9a6010010c714403827010034a70000b9fdffff170503005886010070"
22text p0_hex2 "c714403867000034a70000b9fdffff175f2003d5ffffff17504859534943532d"
23text p0_hex3 "303a20415554484f52495a45440a00504859534943532d303a2044454e494544"
24text p0_hex4 "0a00000000000000305343495359485000e01f40000000000000000900000000"
25
26text s_pass "PASS "
27text s_fail "FAIL "
28text s_nl "\n"
29text s_k1 "kat_sha256_empty"
30text s_k2 "kat_sha256_abc"
31text s_k3 "kat_sha256_56bytes"
32text s_k4 "kat_sha256_112bytes"
33text s_k5 "kat_sha256_physics0_256bytes"
34text s_t1 "verify_valid_physics0_handoff"
35text s_t2 "verify_valid_nonzero_entry_off"
36text s_t3 "refuse_256_single_bit_payload_flips"
37text s_t4 "refuse_1bit_flipped_header_digest"
38text s_t5 "refuse_bad_magic"
39text s_t6 "refuse_bad_version"
40text s_t7 "refuse_bad_alignment"
41text s_t8 "refuse_entry_out_of_bounds"
42text s_t9 "refuse_invalid_stage_len_and_overflow"
43text s_t10 "refuse_epoch_rollback"
44text s_t11 "refuse_short_header_and_truncated_payload"
45text s_t12 "refuse_memmap_disjointness_violations"
46text s_t13 "refuse_halted_descriptor_emit"
47text s_sum "ATLAS_TEST_PASS total=18 failed=0\n"
48text s_fsum "ATLAS_TEST_FAIL\n"
49
50fn report name view uchar * ok bool to uint
51if ok
52w1 = atlas_write_all 1 s_pass
53w2 = atlas_write_all 1 name
54w3 = atlas_write_all 1 s_nl
55if and w1 and w2 w3
56ret 0
57end
58ret 1
59end
60w1 = atlas_write_all 1 s_fail
61w2 = atlas_write_all 1 name
62w3 = atlas_write_all 1 s_nl
63if and w1 and w2 w3
64ret 1
65end
66ret 1
67end
68
69fn load_physics0 dst edit uchar 256 to bool
70for i ulong 256
71put dst i 0
72end
73if not atlas_parse_hex_bytes p0_hex0 part dst 0 32
74ret false
75end
76if not atlas_parse_hex_bytes p0_hex1 part dst 32 32
77ret false
78end
79if not atlas_parse_hex_bytes p0_hex2 part dst 64 32
80ret false
81end
82if not atlas_parse_hex_bytes p0_hex3 part dst 96 32
83ret false
84end
85ret atlas_parse_hex_bytes p0_hex4 part dst 128 32
86end
87
88fn build_valid_img img edit uchar * pay view uchar 256 epoch ulong eoff ulong to bool
89exp = new uchar 32 0
90hdr = new AtlasHeader ATLAS_MAGIC_LE ATLAS_HDR_VER 256 eoff epoch
91if lt len img 320
92ret false
93end
94atlas_sha256_compute pay exp
95if not atlas_header_encode img hdr exp
96ret false
97end
98for i ulong 256
99put img add 64 i get pay i
100end
101ret true
102end
103
104fn check_kat msg view uchar * exp_hex view uchar * to bool
105got = new uchar 32 0
106exp = new uchar 32 0
107if not atlas_parse_hex_bytes exp_hex exp
108ret false
109end
110atlas_sha256_compute msg got
111ret atlas_ct_eq32 got exp
112end
113
114fn check_fail_closed desc view AtlasBootDesc code uint to bool
115if ne get desc verdict code
116ret false
117end
118if ne get desc halted 1
119ret false
120end
121if ne get desc cookie 0
122ret false
123end
124ret eq get desc entry_addr 0
125end
126
127fn test_valid_physics0 pay view uchar 256 to bool
128img = new uchar 320 0
129hdr = new AtlasHeader 0 0 0 0 0
130desc = new AtlasBootDesc 0 0 0 0 0 0 0 0 0 0 0 1
131comp = new uchar 32 0
132wire = new uchar 64 0
133if not build_valid_img img pay 1 0
134ret false
135end
136rc = atlas_verify_image img 1 hdr desc comp
137if ne rc ATLAS_OK
138ret false
139end
140if ne get desc halted 0
141ret false
142end
143if ne get desc cookie ATLAS_COOKIE
144ret false
145end
146if ne get desc entry_addr ATLAS_PAYLOAD_BASE
147ret false
148end
149if ne get desc payload_size 256
150ret false
151end
152if ne get desc epoch 1
153ret false
154end
155if not atlas_emit_desc_bytes desc wire
156ret false
157end
158if ne atlas_le64 wire 0 ATLAS_RAM_BASE
159ret false
160end
161if ne atlas_le64 wire 8 ATLAS_RAM_SIZE
162ret false
163end
164if ne atlas_le64 wire 16 ATLAS_UART_BASE
165ret false
166end
167if ne atlas_le64 wire 24 ATLAS_PAYLOAD_BASE
168ret false
169end
170if ne atlas_le64 wire 32 256
171ret false
172end
173if ne atlas_le64 wire 40 ATLAS_PAYLOAD_BASE
174ret false
175end
176if ne atlas_le64 wire 48 1
177ret false
178end
179ret eq atlas_le64 wire 56 ATLAS_COOKIE
180end
181
182fn test_valid_nonzero_entry pay view uchar 256 to bool
183img = new uchar 320 0
184hdr = new AtlasHeader 0 0 0 0 0
185desc = new AtlasBootDesc 0 0 0 0 0 0 0 0 0 0 0 1
186comp = new uchar 32 0
187if not build_valid_img img pay 7 16
188ret false
189end
190rc = atlas_verify_image img 5 hdr desc comp
191if ne rc ATLAS_OK
192ret false
193end
194if ne get desc entry_addr add ATLAS_PAYLOAD_BASE 16
195ret false
196end
197ret eq get desc epoch 7
198end
199
200fn test_256_bit_flips pay view uchar 256 to bool
201img = new uchar 320 0
202hdr = new AtlasHeader 0 0 0 0 0
203desc = new AtlasBootDesc 0 0 0 0 0 0 0 0 0 0 0 1
204comp = new uchar 32 0
205if not build_valid_img img pay 1 0
206ret false
207end
208for i ulong 256
209pos = add 64 i
210orig = get img pos
211put img pos xor orig uchar 1
212rc = atlas_verify_image img 1 hdr desc comp
213put img pos orig
214if ne rc ATLAS_ERR_DIGEST
215ret false
216end
217if not check_fail_closed desc ATLAS_ERR_DIGEST
218ret false
219end
220end
221ret true
222end
223
224fn test_flipped_header_digest pay view uchar 256 to bool
225img = new uchar 320 0
226hdr = new AtlasHeader 0 0 0 0 0
227desc = new AtlasBootDesc 0 0 0 0 0 0 0 0 0 0 0 1
228comp = new uchar 32 0
229if not build_valid_img img pay 1 0
230ret false
231end
232put img 63 xor get img 63 uchar 1
233rc = atlas_verify_image img 1 hdr desc comp
234if ne rc ATLAS_ERR_DIGEST
235ret false
236end
237ret check_fail_closed desc ATLAS_ERR_DIGEST
238end
239
240fn test_bad_magic pay view uchar 256 to bool
241img = new uchar 320 0
242hdr = new AtlasHeader 0 0 0 0 0
243desc = new AtlasBootDesc 0 0 0 0 0 0 0 0 0 0 0 1
244comp = new uchar 32 0
245if not build_valid_img img pay 1 0
246ret false
247end
248put img 0 uchar 0x58
249rc = atlas_verify_image img 1 hdr desc comp
250if ne rc ATLAS_ERR_MAGIC
251ret false
252end
253ret check_fail_closed desc ATLAS_ERR_MAGIC
254end
255
256fn test_bad_version pay view uchar 256 to bool
257img = new uchar 320 0
258hdr = new AtlasHeader 0 0 0 0 0
259desc = new AtlasBootDesc 0 0 0 0 0 0 0 0 0 0 0 1
260comp = new uchar 32 0
261if not build_valid_img img pay 1 0
262ret false
263end
264atlas_put_le32 img 4 uint 0
265rc0 = atlas_verify_image img 1 hdr desc comp
266if ne rc0 ATLAS_ERR_VERSION
267ret false
268end
269if not check_fail_closed desc ATLAS_ERR_VERSION
270ret false
271end
272atlas_put_le32 img 4 uint 2
273rc2 = atlas_verify_image img 1 hdr desc comp
274if ne rc2 ATLAS_ERR_VERSION
275ret false
276end
277ret check_fail_closed desc ATLAS_ERR_VERSION
278end
279
280fn test_bad_alignment pay view uchar 256 to bool
281img = new uchar 324 0
282hdr = new AtlasHeader 0 0 0 0 0
283desc = new AtlasBootDesc 0 0 0 0 0 0 0 0 0 0 0 1
284comp = new uchar 32 0
285if not build_valid_img part img 0 320 pay 1 0
286ret false
287end
288note Unaligned stage_len = 257
289atlas_put_le64 img 8 257
290rc1 = atlas_verify_image img 1 hdr desc comp
291if ne rc1 ATLAS_ERR_ALIGN
292ret false
293end
294if not check_fail_closed desc ATLAS_ERR_ALIGN
295ret false
296end
297note Restore stage_len = 256, set unaligned entry_off = 2
298atlas_put_le64 img 8 256
299atlas_put_le64 img 16 2
300rc2 = atlas_verify_image img 1 hdr desc comp
301if ne rc2 ATLAS_ERR_ALIGN
302ret false
303end
304ret check_fail_closed desc ATLAS_ERR_ALIGN
305end
306
307fn test_entry_oob pay view uchar 256 to bool
308img = new uchar 320 0
309hdr = new AtlasHeader 0 0 0 0 0
310desc = new AtlasBootDesc 0 0 0 0 0 0 0 0 0 0 0 1
311comp = new uchar 32 0
312if not build_valid_img img pay 1 0
313ret false
314end
315atlas_put_le64 img 16 256
316rc1 = atlas_verify_image img 1 hdr desc comp
317if ne rc1 ATLAS_ERR_ENTRY_OOB
318ret false
319end
320if not check_fail_closed desc ATLAS_ERR_ENTRY_OOB
321ret false
322end
323atlas_put_le64 img 16 512
324rc2 = atlas_verify_image img 1 hdr desc comp
325if ne rc2 ATLAS_ERR_ENTRY_OOB
326ret false
327end
328ret check_fail_closed desc ATLAS_ERR_ENTRY_OOB
329end
330
331fn test_invalid_stage_len pay view uchar 256 to bool
332img = new uchar 320 0
333hdr = new AtlasHeader 0 0 0 0 0
334desc = new AtlasBootDesc 0 0 0 0 0 0 0 0 0 0 0 1
335comp = new uchar 32 0
336if not build_valid_img img pay 1 0
337ret false
338end
339atlas_put_le64 img 8 0
340rc0 = atlas_verify_image img 1 hdr desc comp
341if ne rc0 ATLAS_ERR_STAGE_LEN
342ret false
343end
344atlas_put_le64 img 8 0xfffffffffffffffc
345rc1 = atlas_verify_image img 1 hdr desc comp
346if ne rc1 ATLAS_ERR_STAGE_LEN
347ret false
348end
349ret check_fail_closed desc ATLAS_ERR_STAGE_LEN
350end
351
352fn test_epoch_rollback pay view uchar 256 to bool
353img = new uchar 320 0
354hdr = new AtlasHeader 0 0 0 0 0
355desc = new AtlasBootDesc 0 0 0 0 0 0 0 0 0 0 0 1
356comp = new uchar 32 0
357if not build_valid_img img pay 4 0
358ret false
359end
360rc = atlas_verify_image img 5 hdr desc comp
361if ne rc ATLAS_ERR_ROLLBACK
362ret false
363end
364ret check_fail_closed desc ATLAS_ERR_ROLLBACK
365end
366
367fn test_truncation pay view uchar 256 to bool
368img = new uchar 320 0
369hdr = new AtlasHeader 0 0 0 0 0
370desc = new AtlasBootDesc 0 0 0 0 0 0 0 0 0 0 0 1
371comp = new uchar 32 0
372if not build_valid_img img pay 1 0
373ret false
374end
375rc_hdr = atlas_verify_image part img 0 63 1 hdr desc comp
376if ne rc_hdr ATLAS_ERR_SHORT_HDR
377ret false
378end
379if not check_fail_closed desc ATLAS_ERR_SHORT_HDR
380ret false
381end
382rc_tr = atlas_verify_image part img 0 319 1 hdr desc comp
383if ne rc_tr ATLAS_ERR_TRUNCATED
384ret false
385end
386ret check_fail_closed desc ATLAS_ERR_TRUNCATED
387end
388
389fn test_memmap_violations to bool
390note Valid M1 contract must pass
391if not atlas_check_memmap ATLAS_STACK_BASE ATLAS_STACK_TOP ATLAS_DESC_ADDR ATLAS_PAYLOAD_BASE 256
392ret false
393end
394note Insufficient guard gap (stack_top touches descriptor)
395if atlas_check_memmap ATLAS_STACK_BASE ATLAS_DESC_ADDR ATLAS_DESC_ADDR ATLAS_PAYLOAD_BASE 256
396ret false
397end
398note Unaligned stack_top
399if atlas_check_memmap ATLAS_STACK_BASE add ATLAS_STACK_TOP 4 ATLAS_DESC_ADDR ATLAS_PAYLOAD_BASE 256
400ret false
401end
402note Descriptor overlaps payload
403if atlas_check_memmap ATLAS_STACK_BASE ATLAS_STACK_TOP ATLAS_PAYLOAD_BASE ATLAS_PAYLOAD_BASE 256
404ret false
405end
406note Stage overflows RAM top
407if atlas_check_memmap ATLAS_STACK_BASE ATLAS_STACK_TOP ATLAS_DESC_ADDR ATLAS_PAYLOAD_BASE ATLAS_RAM_SIZE
408ret false
409end
410ret true
411end
412
413fn test_halted_desc_emit to bool
414desc = new AtlasBootDesc ATLAS_RAM_BASE ATLAS_RAM_SIZE ATLAS_UART_BASE ATLAS_PAYLOAD_BASE 256 ATLAS_PAYLOAD_BASE ATLAS_DESC_ADDR ATLAS_STACK_TOP ATLAS_COOKIE 1 ATLAS_ERR_DIGEST 1
415wire = new uchar 64 0xff
416if atlas_emit_desc_bytes desc wire
417ret false
418end
419for i ulong 64
420if ne get wire i 0
421ret false
422end
423end
424ret true
425end
426
427fn main to int
428empty_buf = new uchar 1 0
429pay = new uchar 256 0
430if not load_physics0 pay
431ret 1
432end
433fails = uint 0
434fails = add fails report s_k1 check_kat part empty_buf 0 0 h_empty
435fails = add fails report s_k2 check_kat t_abc h_abc
436fails = add fails report s_k3 check_kat t_56 h_56
437fails = add fails report s_k4 check_kat t_112 h_112
438fails = add fails report s_k5 check_kat pay h_phys0
439fails = add fails report s_t1 test_valid_physics0 pay
440fails = add fails report s_t2 test_valid_nonzero_entry pay
441fails = add fails report s_t3 test_256_bit_flips pay
442fails = add fails report s_t4 test_flipped_header_digest pay
443fails = add fails report s_t5 test_bad_magic pay
444fails = add fails report s_t6 test_bad_version pay
445fails = add fails report s_t7 test_bad_alignment pay
446fails = add fails report s_t8 test_entry_oob pay
447fails = add fails report s_t9 test_invalid_stage_len pay
448fails = add fails report s_t10 test_epoch_rollback pay
449fails = add fails report s_t11 test_truncation pay
450fails = add fails report s_t12 test_memmap_violations
451fails = add fails report s_t13 test_halted_desc_emit
452if eq fails 0
453ok = atlas_write_all 1 s_sum
454if ok
455ret 0
456end
457ret 2
458end
459ok = atlas_write_all 1 s_fsum
460if ok
461ret 1
462end
463ret 1
464end