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