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 / gpu / nvidia / native / abft / run.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note native/abft evaluator driver. Owns inputs, the ground-truth record gref, the nonce stream, the |
| 3 | note tolerances and admission. Each attempt forks a candidate child whose only channel back is a memfd |
| 4 | note plus its exit status; the evaluator kills it at the frozen deadline and always reaps it. |
| 5 | note Output columns are printed first (COLUMNS lines); docs/abft/CONTRACT.md section 8 decodes them. |
| 6 | text MFN "abftout" |
| 7 | text TCASE "CASE" |
| 8 | text TSCH "SCHED" |
| 9 | text TWIT "WITNESS" |
| 10 | text TTAL "TALLY" |
| 11 | text TRES "RESOURCES" |
| 12 | text TPLAN "PLAN" |
| 13 | text TGATE "GATE" |
| 14 | text THDR "COLUMNS PLAN version rows S deadline_ns retries first last\nCOLUMNS CASE row rep att dt m n k w pol tgt site fault sub p1 p2 seed nonce exit sig bytes corrupt struct dig full abft samp adm verdict t_cand t_ref t_full t_abft t_samp t_dig sched steps\nCOLUMNS SCHED row status reason pol tgt site control distinct reps round_robin\nCOLUMNS TALLY row cases corrupt full_tp full_fn full_fp full_tn abft_tp abft_fn abft_fp abft_tn samp_tp samp_fn samp_fp samp_tn dig_tp dig_fn dig_fp dig_tn struct_tp struct_fn struct_fp struct_tn adm_tp adm_fn adm_fp adm_tn accept recovered rejected sched_status timeouts reps\nCOLUMNS WITNESS row partner reps same orig_det red_det verdict\nCOLUMNS RESOURCES forks reaped timeouts kills fd_errors wait_errors fd_first fd_last\nCOLUMNS GATE id pass observed expected\n" |
| 15 | const CEXIT ulong 0 |
| 16 | const CSIG ulong 1 |
| 17 | const CBYT ulong 2 |
| 18 | const CCOR ulong 3 |
| 19 | const CSTR ulong 4 |
| 20 | const CDIG ulong 5 |
| 21 | const CFUL ulong 6 |
| 22 | const CABF ulong 7 |
| 23 | const CSAM ulong 8 |
| 24 | const CADM ulong 9 |
| 25 | const CTC ulong 10 |
| 26 | const CTR ulong 11 |
| 27 | const CTF ulong 12 |
| 28 | const CTA ulong 13 |
| 29 | const CTS ulong 14 |
| 30 | const CTD ulong 15 |
| 31 | const CSH ulong 16 |
| 32 | const CSTP ulong 17 |
| 33 | const CNON ulong 18 |
| 34 | const CVER ulong 19 |
| 35 | global gx uchar 262160 |
| 36 | global gst uchar 4 |
| 37 | global gnon uchar 8 |
| 38 | global gab uchar 32 |
| 39 | global gdig ulong 1 |
| 40 | global gcs ulong 32 |
| 41 | global gtl ulong 32 |
| 42 | global gtr ulong 2048 |
| 43 | global ghs ulong 256 |
| 44 | global gres ulong 8 |
| 45 | global kq ulong 16 |
| 46 | global gwp ulong 256 |
| 47 | global gwc ulong 256 |
| 48 | global gwn ulong 4 |
| 49 | global gexit ulong 64 |
| 50 | fn cs i ulong to ulong |
| 51 | ret get gcs i |
| 52 | end |
| 53 | fn css i ulong v ulong to void |
| 54 | put gcs i v |
| 55 | end |
| 56 | fn pget r ulong f ulong to ulong |
| 57 | ret get pl add mul r 16 f |
| 58 | end |
| 59 | fn rinc i ulong to void |
| 60 | put gres i add get gres i 1 |
| 61 | end |
| 62 | fn tinc i ulong to void |
| 63 | put gtl i add get gtl i 1 |
| 64 | end |
| 65 | fn bv b bool to ulong |
| 66 | if b |
| 67 | ret 1 |
| 68 | end |
| 69 | ret 0 |
| 70 | end |
| 71 | fn ptxt0 to void |
| 72 | for i ulong len TCASE |
| 73 | ochar get TCASE i |
| 74 | end |
| 75 | end |
| 76 | fn ptxt1 to void |
| 77 | for i ulong len TSCH |
| 78 | ochar get TSCH i |
| 79 | end |
| 80 | end |
| 81 | fn ptxt2 to void |
| 82 | for i ulong len TWIT |
| 83 | ochar get TWIT i |
| 84 | end |
| 85 | end |
| 86 | fn ptxt3 to void |
| 87 | for i ulong len TTAL |
| 88 | ochar get TTAL i |
| 89 | end |
| 90 | end |
| 91 | fn ptxt4 to void |
| 92 | for i ulong len TRES |
| 93 | ochar get TRES i |
| 94 | end |
| 95 | end |
| 96 | fn ptxt5 to void |
| 97 | for i ulong len TPLAN |
| 98 | ochar get TPLAN i |
| 99 | end |
| 100 | end |
| 101 | fn ptxt6 to void |
| 102 | for i ulong len TGATE |
| 103 | ochar get TGATE i |
| 104 | end |
| 105 | end |
| 106 | fn ptxth to void |
| 107 | for i ulong len THDR |
| 108 | ochar get THDR i |
| 109 | end |
| 110 | end |
| 111 | fn bfgen to ulong |
| 112 | s = and rnext 0 1 |
| 113 | e = add 120 rbelow 0 8 |
| 114 | m = rbelow 0 128 |
| 115 | ret or or shl s 15 shl e 7 m |
| 116 | end |
| 117 | fn gval to ulong |
| 118 | if eq get gd 0 0 |
| 119 | ret and rnext 0 MASK |
| 120 | end |
| 121 | ret bfgen |
| 122 | end |
| 123 | note Inputs from stream 0 seeded by (row seed, rep); evaluator-owned, never candidate-chosen. |
| 124 | fn gen rep ulong to void |
| 125 | rseed 0 add mul kf KSEED 1000003 rep |
| 126 | put gd 0 kf KDT |
| 127 | put gd 1 kf KM |
| 128 | put gd 2 kf KN |
| 129 | put gd 3 kf KK |
| 130 | for e ulong mul dm dk |
| 131 | put ga e gval |
| 132 | end |
| 133 | for e ulong mul dk dn |
| 134 | put gb e gval |
| 135 | end |
| 136 | end |
| 137 | note Ground-truth record: the same tiled algorithm, fault free, one worker, round robin, in the |
| 138 | note evaluator process. Used only to label corrupt/clean; no checker or admission reads it. |
| 139 | fn cref to void |
| 140 | for f ulong 16 |
| 141 | put kq f get kp f |
| 142 | end |
| 143 | put kp KFLT 0 |
| 144 | put kp KW 1 |
| 145 | put kp KPOL 0 |
| 146 | put kat 0 0 |
| 147 | s = crun |
| 148 | if eq s 0 |
| 149 | trap 11 |
| 150 | end |
| 151 | for e ulong mul dm dn |
| 152 | put gref e get cc e |
| 153 | end |
| 154 | for f ulong 16 |
| 155 | put kp f get kq f |
| 156 | end |
| 157 | end |
| 158 | fn cpack e ulong v ulong to void |
| 159 | for b ulong 4 |
| 160 | put gx add mul e 4 b uchar and shr v mul b 8 255 |
| 161 | end |
| 162 | end |
| 163 | fn cpack8 o ulong v ulong to void |
| 164 | for b ulong 8 |
| 165 | put gx add o b uchar and shr v mul b 8 255 |
| 166 | end |
| 167 | end |
| 168 | note Child: the candidate. Writes M*N little-endian u32 words, its schedule hash and step count. |
| 169 | fn cchild fd int to void |
| 170 | s = crun |
| 171 | mn = mul kf KM kf KN |
| 172 | for e ulong mn |
| 173 | cpack e get cc e |
| 174 | end |
| 175 | nb = mul mn 4 |
| 176 | cpack8 nb get csh 0 |
| 177 | cpack8 add nb 8 s |
| 178 | w = pwrite fd gx 0 add nb 16 0 |
| 179 | if ne w long add nb 16 |
| 180 | exit 70 |
| 181 | end |
| 182 | exit 0 |
| 183 | end |
| 184 | fn reap pid long to void |
| 185 | dl = add now get pcfg 1 |
| 186 | r = long 0 |
| 187 | while true bound 999999 |
| 188 | r = waitpid int pid gst 0 4 1 |
| 189 | if ne r 0 |
| 190 | break |
| 191 | end |
| 192 | if gt now dl |
| 193 | k = killpid int pid 9 |
| 194 | if ne k 0 |
| 195 | rinc 5 |
| 196 | end |
| 197 | rinc 2 |
| 198 | rinc 3 |
| 199 | tinc 30 |
| 200 | r = waitpid int pid gst 0 4 0 |
| 201 | break |
| 202 | end |
| 203 | z = sleepns 100000 |
| 204 | if lt z 0 |
| 205 | rinc 5 |
| 206 | end |
| 207 | end |
| 208 | if lt r 0 |
| 209 | rinc 5 |
| 210 | else |
| 211 | rinc 1 |
| 212 | end |
| 213 | css CSIG and ulong get gst 0 127 |
| 214 | css CEXIT ulong get gst 1 |
| 215 | end |
| 216 | fn word e ulong to ulong |
| 217 | v = ulong 0 |
| 218 | for b ulong 4 |
| 219 | v = or v shl ulong get gx add mul e 4 b mul b 8 |
| 220 | end |
| 221 | ret v |
| 222 | end |
| 223 | fn word8 o ulong to ulong |
| 224 | v = ulong 0 |
| 225 | for b ulong 8 |
| 226 | v = or v shl ulong get gx add o b mul b 8 |
| 227 | end |
| 228 | ret v |
| 229 | end |
| 230 | fn collect fd int to void |
| 231 | mn = mul dm dn |
| 232 | nb = mul mn 4 |
| 233 | for e ulong mn |
| 234 | put gobs e 0 |
| 235 | end |
| 236 | r = pread fd gx 0 add nb 16 0 |
| 237 | c = fclose fd |
| 238 | if ne c 0 |
| 239 | rinc 4 |
| 240 | end |
| 241 | if lt r 0 |
| 242 | css CBYT 0 |
| 243 | ret |
| 244 | end |
| 245 | css CBYT ulong r |
| 246 | if ne ulong r add nb 16 |
| 247 | ret |
| 248 | end |
| 249 | for e ulong mn |
| 250 | put gobs e word e |
| 251 | end |
| 252 | css CSH word8 nb |
| 253 | css CSTP word8 add nb 8 |
| 254 | end |
| 255 | fn okout to bool |
| 256 | if ne cs CEXIT 0 |
| 257 | ret false |
| 258 | end |
| 259 | if ne cs CSIG 0 |
| 260 | ret false |
| 261 | end |
| 262 | ret eq cs CBYT add mul mul dm dn 4 16 |
| 263 | end |
| 264 | fn truth to ulong |
| 265 | if not okout |
| 266 | ret 1 |
| 267 | end |
| 268 | for e ulong mul dm dn |
| 269 | if ne get gobs e get gref e |
| 270 | ret 1 |
| 271 | end |
| 272 | end |
| 273 | ret 0 |
| 274 | end |
| 275 | fn nonce to ulong |
| 276 | r = random gnon 0 8 0 |
| 277 | if ne r 8 |
| 278 | trap 12 |
| 279 | end |
| 280 | v = ulong 0 |
| 281 | for b ulong 8 |
| 282 | v = or v shl ulong get gnon b mul b 8 |
| 283 | end |
| 284 | ret v |
| 285 | end |
| 286 | note Detectors. Timed with now (monons); check time is reported separately, never inside t_cand. |
| 287 | fn detect to void |
| 288 | t = now |
| 289 | css CDIG bv ne cdig get gdig 0 |
| 290 | css CTD sub now t |
| 291 | css CSTR bv not okout |
| 292 | if not okout |
| 293 | css CFUL 2 |
| 294 | css CABF 2 |
| 295 | css CSAM 2 |
| 296 | ret |
| 297 | end |
| 298 | if gt cnonfin 0 |
| 299 | css CSTR 1 |
| 300 | end |
| 301 | n = nonce |
| 302 | css CNON n |
| 303 | rseed 1 n |
| 304 | t = now |
| 305 | css CFUL bv gt cfull 0 |
| 306 | css CTF sub now t |
| 307 | t = now |
| 308 | css CABF bv gt cabft 0 |
| 309 | css CTA sub now t |
| 310 | t = now |
| 311 | css CSAM bv gt csamp get pcfg 0 0 |
| 312 | css CTS sub now t |
| 313 | end |
| 314 | fn admit to ulong |
| 315 | if eq cs CSTR 1 |
| 316 | ret 1 |
| 317 | end |
| 318 | if eq cs CDIG 1 |
| 319 | ret 1 |
| 320 | end |
| 321 | if eq cs CFUL 1 |
| 322 | ret 1 |
| 323 | end |
| 324 | ret bv eq cs CABF 1 |
| 325 | end |
| 326 | fn attempt att ulong to void |
| 327 | for i ulong 32 |
| 328 | if ne i CTR |
| 329 | css i 0 |
| 330 | end |
| 331 | end |
| 332 | put kat 0 att |
| 333 | fd = memfd MFN 0 len MFN 0 |
| 334 | if lt fd 0 |
| 335 | trap 13 |
| 336 | end |
| 337 | t = now |
| 338 | pid = fork |
| 339 | if eq pid 0 |
| 340 | cchild int fd |
| 341 | end |
| 342 | if lt pid 0 |
| 343 | trap 14 |
| 344 | end |
| 345 | rinc 0 |
| 346 | reap pid |
| 347 | css CTC sub now t |
| 348 | collect int fd |
| 349 | css CCOR truth |
| 350 | detect |
| 351 | css CADM admit |
| 352 | end |
| 353 | fn tadd b ulong d ulong c ulong to void |
| 354 | if eq d 2 |
| 355 | ret |
| 356 | end |
| 357 | if eq c 1 |
| 358 | if eq d 1 |
| 359 | tinc b |
| 360 | else |
| 361 | tinc add b 1 |
| 362 | end |
| 363 | else |
| 364 | if eq d 1 |
| 365 | tinc add b 2 |
| 366 | else |
| 367 | tinc add b 3 |
| 368 | end |
| 369 | end |
| 370 | end |
| 371 | fn tcase to void |
| 372 | tinc 0 |
| 373 | c = cs CCOR |
| 374 | if eq c 1 |
| 375 | tinc 1 |
| 376 | end |
| 377 | if eq cs CEXIT 103 |
| 378 | put gexit kf 0 add get gexit kf 0 1 |
| 379 | end |
| 380 | tadd 2 cs CFUL c |
| 381 | tadd 6 cs CABF c |
| 382 | tadd 10 cs CSAM c |
| 383 | tadd 14 cs CDIG c |
| 384 | tadd 18 cs CSTR c |
| 385 | tadd 22 cs CADM c |
| 386 | end |
| 387 | fn pcase r ulong rep ulong att ulong to void |
| 388 | ptxt0 |
| 389 | onum add r 1 |
| 390 | onum rep |
| 391 | onum att |
| 392 | for f ulong 13 |
| 393 | onum kf add f 1 |
| 394 | end |
| 395 | onum cs CNON |
| 396 | for q ulong 10 |
| 397 | onum cs q |
| 398 | end |
| 399 | onum cs CVER |
| 400 | for q ulong 6 |
| 401 | onum cs add CTC q |
| 402 | end |
| 403 | onum cs CSH |
| 404 | onum cs CSTP |
| 405 | onl |
| 406 | end |
| 407 | fn hseen h ulong to void |
| 408 | n = get gwn 2 |
| 409 | for q ulong n |
| 410 | if eq get ghs q h |
| 411 | ret |
| 412 | end |
| 413 | end |
| 414 | if lt n 256 |
| 415 | put ghs n h |
| 416 | put gwn 2 add n 1 |
| 417 | end |
| 418 | end |
| 419 | fn odig2 to ulong |
| 420 | h = ulong 14695981039346656037 |
| 421 | for e ulong mul dm dn |
| 422 | h = fnvw h get gobs e |
| 423 | end |
| 424 | ret h |
| 425 | end |
| 426 | note One rep: fresh inputs, digest, ground truth, optional common-mode corruption, then up to |
| 427 | note 1 + retries attempts. Verdict 0 ACCEPT, 1 RECOVERED, 2 REJECTED, 4 retry follows. |
| 428 | fn runrep r ulong rep ulong to void |
| 429 | gen rep |
| 430 | put krep 0 rep |
| 431 | put gdig 0 cdig |
| 432 | t = now |
| 433 | cref |
| 434 | css CTR sub now t |
| 435 | if eq kf KFLT 7 |
| 436 | p = kf KP1 |
| 437 | put ga p xor get ga p shl ulong 1 kf KP2 |
| 438 | end |
| 439 | last = get pcfg 2 |
| 440 | for att ulong add last 1 |
| 441 | attempt att |
| 442 | if eq att 0 |
| 443 | hseen cs CSH |
| 444 | put gwc rep odig2 |
| 445 | if eq cs CADM 1 |
| 446 | put gwn 1 add get gwn 1 1 |
| 447 | end |
| 448 | end |
| 449 | if eq cs CADM 0 |
| 450 | css CVER bv gt att 0 |
| 451 | else |
| 452 | if eq att last |
| 453 | css CVER 2 |
| 454 | else |
| 455 | css CVER 4 |
| 456 | end |
| 457 | end |
| 458 | tcase |
| 459 | pcase r rep att |
| 460 | if ne cs CVER 4 |
| 461 | tinc add 26 cs CVER |
| 462 | break |
| 463 | end |
| 464 | end |
| 465 | for e ulong mul dm dn |
| 466 | put gprev e get gref e |
| 467 | end |
| 468 | end |
| 469 | fn psched r ulong st ulong rsn ulong to void |
| 470 | ptxt1 |
| 471 | onum add r 1 |
| 472 | onum st |
| 473 | onum rsn |
| 474 | onum kf KPOL |
| 475 | onum kf KTGT |
| 476 | onum kf KSITE |
| 477 | onum shr and kf KFLG 2 1 |
| 478 | onum get gwn 2 |
| 479 | onum get kp 14 |
| 480 | onum bv eq kf KPOL 0 |
| 481 | onl |
| 482 | end |
| 483 | fn ptally r ulong to void |
| 484 | ptxt3 |
| 485 | onum add r 1 |
| 486 | for q ulong 32 |
| 487 | onum get gtl q |
| 488 | end |
| 489 | onl |
| 490 | for q ulong 32 |
| 491 | put gtr add mul r 32 q get gtl q |
| 492 | end |
| 493 | end |
| 494 | note CUDApp#56: a row flagged bit3 is the reduced-concurrency partner of the row before it (same |
| 495 | note seed). OR-RR: fault-free output digests equal rep by rep. OC-RC: verdict 1 means the original |
| 496 | note concurrency detected a fault the reduced run never showed, a counterexample to using it as proof. |
| 497 | fn pwit r ulong to void |
| 498 | reps = get kp 14 |
| 499 | same = ulong 0 |
| 500 | for q ulong reps |
| 501 | if eq get gwp q get gwc q |
| 502 | same = add same 1 |
| 503 | end |
| 504 | end |
| 505 | od = get gwn 0 |
| 506 | rd = get gwn 1 |
| 507 | v = ulong 0 |
| 508 | if ne same reps |
| 509 | v = 2 |
| 510 | end |
| 511 | if and gt od 0 eq rd 0 |
| 512 | v = 1 |
| 513 | end |
| 514 | ptxt2 |
| 515 | onum add r 1 |
| 516 | onum r |
| 517 | onum reps |
| 518 | onum same |
| 519 | onum od |
| 520 | onum rd |
| 521 | onum v |
| 522 | onl |
| 523 | put gwn 3 add mul v 1000 same |
| 524 | end |
| 525 | fn runrow r ulong to void |
| 526 | for f ulong 16 |
| 527 | put kp f pget r f |
| 528 | end |
| 529 | put kat 0 0 |
| 530 | for q ulong 32 |
| 531 | put gtl q 0 |
| 532 | end |
| 533 | put gwn 2 0 |
| 534 | put gwn 1 0 |
| 535 | put gtl 31 get kp 14 |
| 536 | rsn = sreason |
| 537 | st = sstatus rsn |
| 538 | put gtl 29 st |
| 539 | if ne st 0 |
| 540 | psched r st rsn |
| 541 | ptally r |
| 542 | ret |
| 543 | end |
| 544 | gen 1000000 |
| 545 | cref |
| 546 | for e ulong mul dm dn |
| 547 | put gprev e get gref e |
| 548 | end |
| 549 | for rep ulong get kp 14 |
| 550 | runrep r rep |
| 551 | end |
| 552 | psched r st rsn |
| 553 | ptally r |
| 554 | if eq and kf KFLG 8 8 |
| 555 | pwit r |
| 556 | end |
| 557 | for q ulong 256 |
| 558 | put gwp q get gwc q |
| 559 | end |
| 560 | put gwn 0 get gwn 1 |
| 561 | oflush |
| 562 | end |
| 563 | fn tl id ulong i ulong to ulong |
| 564 | ret get gtr add mul sub id 1 32 i |
| 565 | end |
| 566 | fn pgate id ulong ok bool obs ulong exp ulong to bool |
| 567 | ptxt6 |
| 568 | onum id |
| 569 | onum bv ok |
| 570 | onum obs |
| 571 | onum exp |
| 572 | onl |
| 573 | ret ok |
| 574 | end |
| 575 | note Gates (docs/abft/CONTRACT.md section 9). Declared admission misses: rows 11 and 17 |
| 576 | note (f32 mantissa flips below the P1 rounding bound). Only meaningful over the full plan. |
| 577 | fn gfp to ulong |
| 578 | s = ulong 0 |
| 579 | for r ulong get pn 0 |
| 580 | for d ulong 6 |
| 581 | s = add s tl add r 1 add 4 mul d 4 |
| 582 | end |
| 583 | end |
| 584 | ret s |
| 585 | end |
| 586 | fn gfn to ulong |
| 587 | s = ulong 0 |
| 588 | for r ulong get pn 0 |
| 589 | id = add r 1 |
| 590 | if and ne id 11 ne id 17 |
| 591 | s = add s tl id 23 |
| 592 | end |
| 593 | end |
| 594 | ret s |
| 595 | end |
| 596 | fn gsched to ulong |
| 597 | bad = ulong 0 |
| 598 | for r ulong get pn 0 |
| 599 | id = add r 1 |
| 600 | e = ulong 0 |
| 601 | if eq id 37 |
| 602 | e = 65 |
| 603 | end |
| 604 | if or eq id 38 eq id 39 |
| 605 | e = 69 |
| 606 | end |
| 607 | if ne tl id 29 e |
| 608 | bad = add bad 1 |
| 609 | end |
| 610 | end |
| 611 | ret bad |
| 612 | end |
| 613 | fn gates to ulong |
| 614 | fail = ulong 0 |
| 615 | v = gfp |
| 616 | if not pgate 1 eq v 0 v 0 |
| 617 | fail = add fail 1 |
| 618 | end |
| 619 | v = gfn |
| 620 | if not pgate 2 eq v 0 v 0 |
| 621 | fail = add fail 1 |
| 622 | end |
| 623 | v = gsched |
| 624 | if not pgate 3 eq v 0 v 0 |
| 625 | fail = add fail 1 |
| 626 | end |
| 627 | v = add tl 43 27 tl 44 28 |
| 628 | if not pgate 4 eq v add tl 43 31 tl 44 31 v add tl 43 31 tl 44 31 |
| 629 | fail = add fail 1 |
| 630 | end |
| 631 | ret add fail gates2 |
| 632 | end |
| 633 | fn gates2 to ulong |
| 634 | fail = ulong 0 |
| 635 | ok = and eq get gres 0 get gres 1 eq get gres 6 get gres 7 |
| 636 | ok = and ok eq add get gres 4 get gres 5 0 |
| 637 | if not pgate 5 ok sub get gres 0 get gres 1 0 |
| 638 | fail = add fail 1 |
| 639 | end |
| 640 | v = tl 36 30 |
| 641 | if not pgate 6 eq v mul 2 tl 36 31 v mul 2 tl 36 31 |
| 642 | fail = add fail 1 |
| 643 | end |
| 644 | v = add tl 40 7 tl 40 2 |
| 645 | if not pgate 7 eq v mul 2 tl 40 1 v mul 2 tl 40 1 |
| 646 | fail = add fail 1 |
| 647 | end |
| 648 | note Gate 8 (revised after the first sandbox run, see CONTRACT.md section 9): the digest catches every |
| 649 | note corrupt case, and full/checksum detect only the cases the structural check flags as nonfinite. |
| 650 | s = tl 42 18 |
| 651 | c = tl 42 1 |
| 652 | ok = and eq tl 42 14 c and eq add tl 42 3 s c eq add tl 42 7 s c |
| 653 | v = add add tl 42 14 tl 42 3 tl 42 7 |
| 654 | if not pgate 8 ok v sub mul 3 c mul 2 s |
| 655 | fail = add fail 1 |
| 656 | end |
| 657 | v = get gwn 3 |
| 658 | if not pgate 9 eq v tl 51 31 v tl 51 31 |
| 659 | fail = add fail 1 |
| 660 | end |
| 661 | note Gate 10 (added after the first sandbox run): every row 26 attempt ends in Omega trap 3 (exit 103). |
| 662 | v = get gexit 26 |
| 663 | if not pgate 10 eq v tl 26 0 v tl 26 0 |
| 664 | fail = add fail 1 |
| 665 | end |
| 666 | ret fail |
| 667 | end |
| 668 | fn argnum i ulong d ulong to ulong |
| 669 | if le ulong argcnt i |
| 670 | ret d |
| 671 | end |
| 672 | n = argread i gab 0 32 |
| 673 | if le n 0 |
| 674 | ret d |
| 675 | end |
| 676 | v = ulong 0 |
| 677 | for q ulong ulong n |
| 678 | c = ulong get gab q |
| 679 | if or lt c 48 gt c 57 |
| 680 | exit 64 |
| 681 | end |
| 682 | v = add mul v 10 sub c 48 |
| 683 | end |
| 684 | ret v |
| 685 | end |
| 686 | fn fdprobe to ulong |
| 687 | fd = memfd MFN 0 len MFN 0 |
| 688 | if lt fd 0 |
| 689 | trap 13 |
| 690 | end |
| 691 | c = fclose int fd |
| 692 | if ne c 0 |
| 693 | rinc 4 |
| 694 | end |
| 695 | ret ulong fd |
| 696 | end |
| 697 | fn main to int |
| 698 | pfill |
| 699 | put gres 6 fdprobe |
| 700 | first = argnum 1 1 |
| 701 | last = argnum 2 get pn 0 |
| 702 | if or or eq first 0 gt first last gt last get pn 0 |
| 703 | exit 64 |
| 704 | end |
| 705 | ptxth |
| 706 | ptxt5 |
| 707 | onum get pcfg 3 |
| 708 | onum get pn 0 |
| 709 | onum get pcfg 0 |
| 710 | onum get pcfg 1 |
| 711 | onum get pcfg 2 |
| 712 | onum first |
| 713 | onum last |
| 714 | onl |
| 715 | oflush |
| 716 | for r ulong sub add last 1 first |
| 717 | runrow add sub first 1 r |
| 718 | end |
| 719 | put gres 7 fdprobe |
| 720 | ptxt4 |
| 721 | for q ulong 8 |
| 722 | onum get gres q |
| 723 | end |
| 724 | onl |
| 725 | fail = ulong 0 |
| 726 | if and eq first 1 eq last get pn 0 |
| 727 | fail = gates |
| 728 | end |
| 729 | oflush |
| 730 | ret int fail |
| 731 | end |