aien-train
AIEN training programme: language-model history, GB10 constraints and the route to training on the project engine. Plans and runnable checks are distinguished.
Brought by drakestapleton
aien-train / tools / omegallm / wpatch / wpcheck.om
| 1 | note SPDX-License-Identifier: AGPL-3.0-only |
| 2 | note wpcheck: the Omega test driver for wpatch (replaces check.py). CPU only. Built by wpbuild as |
| 3 | note wpcheck-all.om = om2, the vendored SHA-256 layout and functions, this file. |
| 4 | note Usage: wpcheck small BUILD WORK ORACLE own-model fixtures made here with BUILD/ollm |
| 5 | note wpcheck real BUILD WORK ORACLE CK the read-only round40 checkpoint CK |
| 6 | note wpcheck sum FILE print the Omega SHA-256 of FILE (used by wpbuild) |
| 7 | note BUILD holds wpatch and ollm. WORK must not exist; it is created 0700 and holds every fixture. |
| 8 | note ORACLE is wporacle.py, run as /usr/bin/python3 ORACLE REQUEST. It only computes hashlib |
| 9 | note SHA-256 and IEEE f32 cast digests of files named in REQUEST; every comparison, exit code, fixture, |
| 10 | note refusal and the PASS/FAIL verdict is decided here. Fixture rehashes (FNV, manifest and binding |
| 11 | note digests) use the vendored Omega SHA-256, not the oracle. |
| 12 | note Output is plain text: RUN argv, the child's stdout as `| ` lines (its stderr passes through), |
| 13 | note EXIT got want elapsed_ns, then PASS or FAIL lines. The last line is |
| 14 | note `WPCHECK PASS checks=N commands=M` (exit 0) or `WPCHECK FAIL ...` (exit 1); 2 is usage. |
| 15 | |
| 16 | global sb uchar 131072 |
| 17 | global sl ulong 256 |
| 18 | global pb uchar 4096 |
| 19 | global pn ulong 1 |
| 20 | global av uchar 8192 |
| 21 | global ap ulong 2 |
| 22 | global stb uchar 4 |
| 23 | global ob uchar 4194304 |
| 24 | global obn ulong 1 |
| 25 | global oo uchar 65536 |
| 26 | global ol ulong 1024 |
| 27 | global oln ulong 1 |
| 28 | global rq uchar 65536 |
| 29 | global rqn ulong 2 |
| 30 | global dig uchar 32 |
| 31 | global dg uchar 32 |
| 32 | global cnt ulong 4 |
| 33 | global tt ulong 1536 |
| 34 | global tn ulong 2 |
| 35 | global rix ulong 64 |
| 36 | global rbt ulong 64 |
| 37 | global rcn ulong 1 |
| 38 | global hh ulong 8 |
| 39 | global mf ulong 16 |
| 40 | global ca uchar 65536 |
| 41 | global cb uchar 65536 |
| 42 | const SWP ulong 0 |
| 43 | const SOLLM ulong 1 |
| 44 | const SWORK ulong 2 |
| 45 | const SORC ulong 3 |
| 46 | const SBASE ulong 4 |
| 47 | const SEDIT ulong 5 |
| 48 | const SPF ulong 6 |
| 49 | const SRF ulong 7 |
| 50 | const STRAIN ulong 8 |
| 51 | const SP0 ulong 9 |
| 52 | const SREQ ulong 12 |
| 53 | const SMEX ulong 13 |
| 54 | const SOUT ulong 14 |
| 55 | const SREV ulong 15 |
| 56 | const SBIND ulong 16 |
| 57 | const SRT ulong 17 |
| 58 | const SBADB ulong 18 |
| 59 | const SOD ulong 19 |
| 60 | const SX0 ulong 20 |
| 61 | const SX1 ulong 21 |
| 62 | const SX2 ulong 22 |
| 63 | const SX3 ulong 23 |
| 64 | const SX4 ulong 24 |
| 65 | const SX5 ulong 25 |
| 66 | const SSNAP ulong 30 |
| 67 | const SBUILD ulong 31 |
| 68 | const SRQ ulong 32 |
| 69 | const SMODE ulong 33 |
| 70 | const ALL ulong 18446744073709551615 |
| 71 | const DLT f64 0.001 |
| 72 | const QTR f64 0.25 |
| 73 | const BIGM f64 1000001.0 |
| 74 | const OVER ulong 16777217 |
| 75 | const BASEOFF ulong 8162304 |
| 76 | text PY "/usr/bin/python3" |
| 77 | text SUMT "/usr/bin/sha256sum" |
| 78 | text BSHA "7c7b5b5260f2d9453b6076b64e7f23e88341d96498584f2dfaa229c31ad2e346" |
| 79 | text HEXD "0123456789abcdef" |
| 80 | text CK02 "OLLMCK02" |
| 81 | text WP01 "OLLMWP01" |
| 82 | text WB01 "OLLMWB01" |
| 83 | text PARS "{\"delta\":0.001,\"name\":\"Ω patch\"}\n" |
| 84 | text RATS "Own-model fixture. Preserve exact rollback.\n" |
| 85 | text PARR "{\"kind\":\"w2\",\"layer\":3,\"entries\":10,\"delta\":0.001}\n" |
| 86 | text RATR "Read-only round40 baseline. Checked patch integration fixture, not a quality claim.\n" |
| 87 | text SHOWA "{\"patch_sha256\":\"" |
| 88 | text SHOWZ "\"params\":\"{\\\"delta\\\":0.001,\\\"name\\\":\\\"Ω patch\\\"}\\u000a\",\"rationale\":\"Own-model fixture. Preserve exact rollback.\\u000a\"}\n" |
| 89 | text TRAINW "abc abcd abcde" |
| 90 | text INITA "256 8 16 2 32 2 2 1 10 3000 1" |
| 91 | text MUTN "wrong-base-sha geometry shape oob nan inf magnitude unsorted duplicate old-bits old-moment entries-hash tensor-count tensor-base-sha tensor-out-sha output-sha output-f32-sha " |
| 92 | text CINSP "inspect" |
| 93 | text CDIFF "diff" |
| 94 | text CSHOW "show" |
| 95 | text CVAL "validate" |
| 96 | text CAPP "apply" |
| 97 | text CVER "verify" |
| 98 | text CREV "revert" |
| 99 | text CBIND "bind" |
| 100 | text CCB "checkbind" |
| 101 | text CINIT "init" |
| 102 | text CTRAIN "train" |
| 103 | text WTE "wte" |
| 104 | text SLICEA "0 0 1 0 2" |
| 105 | text OOBA "0 0 99999 0 1" |
| 106 | text MSMALL "small" |
| 107 | text MREAL "real" |
| 108 | text MSUM "sum" |
| 109 | text FTRAIN "train.bin" |
| 110 | text FBASE "base.ck" |
| 111 | text FSNAP "base-snapshot.ck" |
| 112 | text FEDIT "edited.ck" |
| 113 | text FPF "params.txt" |
| 114 | text FRF "rationale.txt" |
| 115 | text FPAT "patches-" |
| 116 | text FPATS "patches" |
| 117 | text FEXP "expected-" |
| 118 | text FMEX "manifest-expected-" |
| 119 | text FAPP "applied-" |
| 120 | text FREV "reverted-" |
| 121 | text FBND "binding-" |
| 122 | text FRT "runtime-" |
| 123 | text FBADB "wrong-f32-binding-" |
| 124 | text FCK ".ck" |
| 125 | text FWP ".wp" |
| 126 | text FREQ ".req" |
| 127 | text FORQ "oracle-" |
| 128 | text FMUTE "oracle-mutant-edited.ck" |
| 129 | text FMUTD "oracle-mutant-patches" |
| 130 | text FMUTO "oracle-mutant.ck" |
| 131 | text FMUTR "oracle-mutant-requested.ck" |
| 132 | text FOVP "oversized-params" |
| 133 | text FOVR "oversized-rationale" |
| 134 | text FUTF "invalid-utf8.wp" |
| 135 | text FFLIP "flipped" |
| 136 | text FBAPP "bad-apply.ck" |
| 137 | text FBREV "bad-revert.ck" |
| 138 | text FBBND "bad-bind" |
| 139 | text FTRUNC "truncated.wp" |
| 140 | text FWRM "wrong-m.ck" |
| 141 | text FEXO "exotic.ck" |
| 142 | text FEXE "exotic-edited.ck" |
| 143 | text FEXD "exotic-patches" |
| 144 | text FR40E "round40-edited.ck" |
| 145 | text FR40X "round40-expected.ck" |
| 146 | text FR40A "round40-applied.ck" |
| 147 | text FR40R "round40-reverted.ck" |
| 148 | text SLWP "/wpatch" |
| 149 | text SLOLLM "/ollm" |
| 150 | text QSHA "sha " |
| 151 | text QF32 "f32 " |
| 152 | text QNE "f32ne " |
| 153 | text SURV "f32_surviving=" |
| 154 | text CHGD " changed=" |
| 155 | text RMSK "rms=" |
| 156 | text NONF3 "nonfinite=3" |
| 157 | text WTEL "wte " |
| 158 | text PASST "PASS " |
| 159 | text FAILT "FAIL " |
| 160 | text RUNT "RUN" |
| 161 | text BART "| " |
| 162 | text EXITT "EXIT got=" |
| 163 | text WANTT " want=" |
| 164 | text ELAPT " elapsed_ns=" |
| 165 | text HEADT "WPCHECK " |
| 166 | text WPSHT " wpatch_sha256=" |
| 167 | text WPPT "WPCHECK PASS checks=" |
| 168 | text WPFT "WPCHECK FAIL checks=" |
| 169 | text CMDT " commands=" |
| 170 | text USAGE "usage: wpcheck small BUILD WORK ORACLE | wpcheck real BUILD WORK ORACLE CK | wpcheck sum FILE\n" |
| 171 | text SP " " |
| 172 | text NL "\n" |
| 173 | text LIO ": I/O failure" |
| 174 | text LCAP "driver capacity" |
| 175 | text LCHILD "could not start a child process" |
| 176 | text LEXIT "exit" |
| 177 | text LORL "oracle answered every request" |
| 178 | text LMAG "oracle CK02 magic" |
| 179 | text LCKL "oracle checkpoint length" |
| 180 | text LFNV "oracle checkpoint FNV" |
| 181 | text LGEOP "oracle checkpoint geometry P" |
| 182 | text LWMAG "oracle manifest magic" |
| 183 | text LNAME "oracle canonical manifest name" |
| 184 | text LMLEN "oracle manifest length" |
| 185 | text LPOL "oracle policy" |
| 186 | text LEID "oracle edit identity" |
| 187 | text LMETA "oracle metadata lengths" |
| 188 | text LPROV "oracle UTF8 provenance" |
| 189 | text LORD "oracle strict order" |
| 190 | text LBND "oracle indices in bounds" |
| 191 | text LHDR "oracle preserved base header" |
| 192 | text LMGEO "oracle manifest geometry" |
| 193 | text LMP "oracle manifest P" |
| 194 | text LBSHA "oracle base SHA" |
| 195 | text LEBIT "oracle entry bits" |
| 196 | text LEFIN "oracle entry changed finite" |
| 197 | text LEMAG "oracle entry magnitude" |
| 198 | text LEMOM "oracle saved moments" |
| 199 | text LOSHA "oracle expected output SHA" |
| 200 | text LOF32 "oracle expected f32 SHA" |
| 201 | text LTALL "oracle all tensors present" |
| 202 | text LTGEO "oracle tensor record geometry" |
| 203 | text LTCNT "oracle tensor changed count" |
| 204 | text LTBS "oracle tensor base SHA" |
| 205 | text LTOS "oracle tensor output SHA" |
| 206 | text LAGREE "manifest oracle agrees with independent request" |
| 207 | text LSHOW "show UTF8 provenance" |
| 208 | text LAPPX "apply exact oracle bytes" |
| 209 | text LAPPR "apply equals independent requested bytes" |
| 210 | text LSURV "verify f32 survival count" |
| 211 | text LREVB "revert byte-identical base" |
| 212 | text LBFMT "oracle binding format" |
| 213 | text LBCK "oracle binding CK and f32" |
| 214 | text LBRT "oracle binding runtime and patch" |
| 215 | text LBSELF "oracle binding self digest" |
| 216 | text LOUTP "OUT exists preserved" |
| 217 | text LSLICE "inspect exact slice bits" |
| 218 | text LBASEW "BASE never written" |
| 219 | text LMUTP "mutant patch policy" |
| 220 | text LMUTS "mutant apply equals its own independent request" |
| 221 | text LMUTR "independent oracle rejects rehashed finite-value mutant accepted by verify" |
| 222 | text LOVER "oversized metadata creates no output" |
| 223 | text LREF ": refusal creates no output" |
| 224 | text LEXO "f32 cast boundary vectors" |
| 225 | text LRMS "scaled RMS survives maximum finite f64, counts nonfinite separately" |
| 226 | text LFBASE "final base identity" |
| 227 | text LRPIN "real base pinned SHA" |
| 228 | text LROFF "Wolfram layer3 w2 offset" |
| 229 | text LRTEN "real ten entry identity" |
| 230 | text LRAPP "real apply equals independently requested bytes" |
| 231 | text LRREV "real byte-identical revert SHA" |
| 232 | text LRBASE "real base unchanged" |
| 233 | text LROUT "real output SHA matches independent expected bytes" |
| 234 | text LRMOUT "real manifest output SHA matches independent expected bytes" |
| 235 | text LRF32 "real f32 SHA matches independent expected bytes" |
| 236 | text LRMF32 "real manifest f32 SHA matches independent expected bytes" |
| 237 | |
| 238 | note ---- output and verdicts ---------------------------------------------------------------------- |
| 239 | fn say s view uchar * to void |
| 240 | r = write 1 s 0 len s |
| 241 | end |
| 242 | fn saynum v ulong to void |
| 243 | x = v |
| 244 | n = ulong 0 |
| 245 | while ge x 10 |
| 246 | put dig n uchar add 48 rem x 10 |
| 247 | x = div x 10 |
| 248 | n = add n 1 |
| 249 | end |
| 250 | put dig n uchar add 48 x |
| 251 | for i ulong add n 1 |
| 252 | r = write 1 dig sub n i 1 |
| 253 | end |
| 254 | end |
| 255 | fn saypb to void |
| 256 | r = write 1 pb 0 get pn 0 |
| 257 | end |
| 258 | fn tally to void |
| 259 | saynum get cnt 0 |
| 260 | say CMDT |
| 261 | saynum get cnt 1 |
| 262 | say NL |
| 263 | end |
| 264 | note FAIL with label pb + m (pb may be empty), then the summary; exit 1. |
| 265 | fn failpm m view uchar * to void |
| 266 | say FAILT |
| 267 | saypb |
| 268 | say m |
| 269 | say NL |
| 270 | say WPFT |
| 271 | tally |
| 272 | exit 1 |
| 273 | end |
| 274 | fn pclear to void |
| 275 | put pn 0 0 |
| 276 | end |
| 277 | fn fail m view uchar * to void |
| 278 | pclear |
| 279 | failpm m |
| 280 | end |
| 281 | fn need c bool m view uchar * to void |
| 282 | if not c |
| 283 | fail m |
| 284 | end |
| 285 | put cnt 0 add get cnt 0 1 |
| 286 | say PASST |
| 287 | say m |
| 288 | say NL |
| 289 | end |
| 290 | note need with label pb + m |
| 291 | fn needpm c bool m view uchar * to void |
| 292 | if not c |
| 293 | failpm m |
| 294 | end |
| 295 | put cnt 0 add get cnt 0 1 |
| 296 | say PASST |
| 297 | saypb |
| 298 | say m |
| 299 | say NL |
| 300 | end |
| 301 | |
| 302 | note ---- path builder, slots, argument packets --------------------------------------------------- |
| 303 | fn pbyte b uchar to void |
| 304 | n = get pn 0 |
| 305 | if ge n 4095 |
| 306 | fail LCAP |
| 307 | end |
| 308 | put pb n b |
| 309 | put pn 0 add n 1 |
| 310 | end |
| 311 | fn ptext s view uchar * to void |
| 312 | for i ulong len s |
| 313 | pbyte get s i |
| 314 | end |
| 315 | end |
| 316 | fn pnum v ulong to void |
| 317 | x = v |
| 318 | n = ulong 0 |
| 319 | while ge x 10 |
| 320 | put dig n uchar add 48 rem x 10 |
| 321 | x = div x 10 |
| 322 | n = add n 1 |
| 323 | end |
| 324 | put dig n uchar add 48 x |
| 325 | for i ulong add n 1 |
| 326 | pbyte get dig sub n i |
| 327 | end |
| 328 | end |
| 329 | fn phex v ulong to void |
| 330 | for i ulong 16 |
| 331 | pbyte get HEXD and shr v mul sub 15 i 4 15 |
| 332 | end |
| 333 | end |
| 334 | note append word k (0-based, space separated) of s |
| 335 | fn pword s view uchar * k ulong to void |
| 336 | w = ulong 0 |
| 337 | for i ulong len s |
| 338 | c = get s i |
| 339 | if eq c 32 |
| 340 | w = add w 1 |
| 341 | else |
| 342 | if eq w k |
| 343 | pbyte c |
| 344 | end |
| 345 | end |
| 346 | end |
| 347 | end |
| 348 | note Slot k is 512 bytes of sb at k * 512, its length in sl. |
| 349 | fn pslot k ulong to void |
| 350 | o = mul k 512 |
| 351 | for i ulong get sl k |
| 352 | pbyte get sb add o i |
| 353 | end |
| 354 | end |
| 355 | fn keepat k ulong to void |
| 356 | n = get pn 0 |
| 357 | if gt n 512 |
| 358 | fail LCAP |
| 359 | end |
| 360 | o = mul k 512 |
| 361 | for i ulong n |
| 362 | put sb add o i get pb i |
| 363 | end |
| 364 | put sl k n |
| 365 | end |
| 366 | fn under k ulong base ulong s view uchar * to void |
| 367 | pclear |
| 368 | pslot base |
| 369 | ptext s |
| 370 | keepat k |
| 371 | end |
| 372 | note slot k = WORK/s |
| 373 | fn wname k ulong s view uchar * to void |
| 374 | pclear |
| 375 | pslot SWORK |
| 376 | pbyte 47 |
| 377 | ptext s |
| 378 | keepat k |
| 379 | end |
| 380 | note slot k = WORK/a N |
| 381 | fn wnamep k ulong a view uchar * v ulong to void |
| 382 | pclear |
| 383 | pslot SWORK |
| 384 | pbyte 47 |
| 385 | ptext a |
| 386 | pnum v |
| 387 | keepat k |
| 388 | end |
| 389 | note slot k = WORK/a N b |
| 390 | fn wnamen k ulong a view uchar * v ulong b view uchar * to void |
| 391 | pclear |
| 392 | pslot SWORK |
| 393 | pbyte 47 |
| 394 | ptext a |
| 395 | pnum v |
| 396 | ptext b |
| 397 | keepat k |
| 398 | end |
| 399 | fn slotis k ulong s view uchar * to bool |
| 400 | if ne get sl k len s |
| 401 | ret false |
| 402 | end |
| 403 | o = mul k 512 |
| 404 | for i ulong len s |
| 405 | if ne get sb add o i get s i |
| 406 | ret false |
| 407 | end |
| 408 | end |
| 409 | ret true |
| 410 | end |
| 411 | fn argslot i ulong k ulong to void |
| 412 | r = argread i pb 0 512 |
| 413 | if le r 0 |
| 414 | say USAGE |
| 415 | exit 2 |
| 416 | end |
| 417 | put pn 0 ulong r |
| 418 | keepat k |
| 419 | end |
| 420 | fn aclear to void |
| 421 | put ap 0 2 |
| 422 | put ap 1 0 |
| 423 | end |
| 424 | fn apb to void |
| 425 | p = get ap 0 |
| 426 | n = get pn 0 |
| 427 | if or gt add add p n 2 len av ge get ap 1 64 |
| 428 | fail LCAP |
| 429 | end |
| 430 | put av p uchar and n 255 |
| 431 | put av add p 1 uchar shr n 8 |
| 432 | for i ulong n |
| 433 | put av add add p 2 i get pb i |
| 434 | end |
| 435 | put ap 0 add add p 2 n |
| 436 | put ap 1 add get ap 1 1 |
| 437 | end |
| 438 | fn atext s view uchar * to void |
| 439 | pclear |
| 440 | ptext s |
| 441 | apb |
| 442 | end |
| 443 | fn aslot k ulong to void |
| 444 | pclear |
| 445 | pslot k |
| 446 | apb |
| 447 | end |
| 448 | fn anum v ulong to void |
| 449 | pclear |
| 450 | pnum v |
| 451 | apb |
| 452 | end |
| 453 | note one argument per space-separated word of s |
| 454 | fn awords s view uchar * to void |
| 455 | pclear |
| 456 | for i ulong len s |
| 457 | if eq get s i 32 |
| 458 | apb |
| 459 | pclear |
| 460 | else |
| 461 | pbyte get s i |
| 462 | end |
| 463 | end |
| 464 | apb |
| 465 | end |
| 466 | note packet: wpatch CMD |
| 467 | fn acmd s view uchar * to void |
| 468 | aclear |
| 469 | aslot SWP |
| 470 | atext s |
| 471 | end |
| 472 | |
| 473 | note ---- child processes --------------------------------------------------------------------------- |
| 474 | fn showcmd to void |
| 475 | say RUNT |
| 476 | p = ulong 2 |
| 477 | for i ulong get ap 1 |
| 478 | n = or ulong get av p shl ulong get av add p 1 8 |
| 479 | say SP |
| 480 | r = write 1 av add p 2 n |
| 481 | p = add add p 2 n |
| 482 | end |
| 483 | say NL |
| 484 | end |
| 485 | fn redir s int d int to void |
| 486 | if ne s d |
| 487 | if ne dupfd s d 0 long d |
| 488 | exit 127 |
| 489 | end |
| 490 | end |
| 491 | end |
| 492 | fn drain rd int to void |
| 493 | n = ulong 0 |
| 494 | k = long 1 |
| 495 | while gt k 0 bound 999999 |
| 496 | if eq n len ob |
| 497 | fail LCAP |
| 498 | end |
| 499 | k = read rd ob n sub len ob n |
| 500 | if gt k 0 |
| 501 | n = add n ulong k |
| 502 | end |
| 503 | end |
| 504 | r = fclose rd |
| 505 | put obn 0 n |
| 506 | end |
| 507 | fn reap pid long to ulong |
| 508 | w = waitpid int pid stb 0 4 0 |
| 509 | if ne w pid |
| 510 | fail LCHILD |
| 511 | end |
| 512 | if ne get stb 0 0 |
| 513 | ret add 256 ulong and get stb 0 127 |
| 514 | end |
| 515 | ret ulong get stb 1 |
| 516 | end |
| 517 | fn echoob to void |
| 518 | n = get obn 0 |
| 519 | s = ulong 0 |
| 520 | for i ulong n |
| 521 | if eq get ob i 10 |
| 522 | say BART |
| 523 | r = write 1 ob s add sub i s 1 |
| 524 | s = add i 1 |
| 525 | end |
| 526 | end |
| 527 | if lt s n |
| 528 | say BART |
| 529 | r = write 1 ob s sub n s |
| 530 | say NL |
| 531 | end |
| 532 | end |
| 533 | note Run the packet in av: stdout is captured into ob, stderr passes through. Checks the exit. |
| 534 | fn go want ulong to void |
| 535 | put av 0 uchar and get ap 1 255 |
| 536 | put av 1 uchar shr get ap 1 8 |
| 537 | showcmd |
| 538 | pf = new uchar 8 0 |
| 539 | if ne pipefds pf 0 8 0 0 |
| 540 | fail LCHILD |
| 541 | end |
| 542 | rd = int or ulong get pf 0 shl ulong get pf 1 8 |
| 543 | wr = int or ulong get pf 4 shl ulong get pf 5 8 |
| 544 | t0 = monons |
| 545 | pid = fork |
| 546 | if lt pid 0 |
| 547 | fail LCHILD |
| 548 | end |
| 549 | if eq pid 0 |
| 550 | r = fclose rd |
| 551 | redir wr 1 |
| 552 | r = execprog av 0 get ap 0 |
| 553 | exit 127 |
| 554 | end |
| 555 | r = fclose wr |
| 556 | drain rd |
| 557 | x = reap pid |
| 558 | t = sub monons t0 |
| 559 | put cnt 1 add get cnt 1 1 |
| 560 | echoob |
| 561 | say EXITT |
| 562 | saynum x |
| 563 | say WANTT |
| 564 | saynum want |
| 565 | say ELAPT |
| 566 | saynum ulong t |
| 567 | say NL |
| 568 | need eq x want LEXIT |
| 569 | end |
| 570 | note Slot k = child stdout without trailing white space. |
| 571 | fn keepout k ulong to void |
| 572 | n = get obn 0 |
| 573 | going = true |
| 574 | while going |
| 575 | if eq n 0 |
| 576 | going = false |
| 577 | else |
| 578 | if le get ob sub n 1 32 |
| 579 | n = sub n 1 |
| 580 | else |
| 581 | going = false |
| 582 | end |
| 583 | end |
| 584 | end |
| 585 | pclear |
| 586 | for i ulong n |
| 587 | pbyte get ob i |
| 588 | end |
| 589 | keepat k |
| 590 | end |
| 591 | note true when the bytes now in pb occur in ob |
| 592 | fn obhaspb to bool |
| 593 | n = get obn 0 |
| 594 | m = get pn 0 |
| 595 | if gt m n |
| 596 | ret false |
| 597 | end |
| 598 | for i ulong add sub n m 1 |
| 599 | hit = true |
| 600 | for j ulong m |
| 601 | if ne get ob add i j get pb j |
| 602 | hit = false |
| 603 | end |
| 604 | end |
| 605 | if hit |
| 606 | ret true |
| 607 | end |
| 608 | end |
| 609 | ret false |
| 610 | end |
| 611 | |
| 612 | note ---- files and maps ----------------------------------------------------------------------------- |
| 613 | fn failio k ulong to void |
| 614 | pclear |
| 615 | pslot k |
| 616 | failpm LIO |
| 617 | end |
| 618 | fn fsize k ulong to ulong |
| 619 | pclear |
| 620 | pslot k |
| 621 | fd = int fopen pb 0 get pn 0 0 0 |
| 622 | if lt fd 0 |
| 623 | failio k |
| 624 | end |
| 625 | sz = fseek fd 0 2 |
| 626 | r = fclose fd |
| 627 | if lt sz 0 |
| 628 | failio k |
| 629 | end |
| 630 | ret ulong sz |
| 631 | end |
| 632 | fn mopen k ulong to long |
| 633 | pclear |
| 634 | pslot k |
| 635 | fd = int fopen pb 0 get pn 0 0 0 |
| 636 | if lt fd 0 |
| 637 | failio k |
| 638 | end |
| 639 | sz = fseek fd 0 2 |
| 640 | h = mapnew fd 0 ulong sz 1 2 |
| 641 | r = fclose fd |
| 642 | if lt h 0 |
| 643 | failio k |
| 644 | end |
| 645 | ret h |
| 646 | end |
| 647 | note Create slot k (must not exist) with n zero bytes; return a shared read/write map. |
| 648 | fn mcreate k ulong n ulong to long |
| 649 | pclear |
| 650 | pslot k |
| 651 | fd = int fopen pb 0 get pn 0 194 420 |
| 652 | if lt fd 0 |
| 653 | failio k |
| 654 | end |
| 655 | if ne ftrunc fd long n 0 |
| 656 | failio k |
| 657 | end |
| 658 | h = mapnew fd 0 n 3 1 |
| 659 | r = fclose fd |
| 660 | if lt h 0 |
| 661 | failio k |
| 662 | end |
| 663 | ret h |
| 664 | end |
| 665 | fn mdrop h long to void |
| 666 | r = mapdrop h |
| 667 | end |
| 668 | fn cpy src long so ulong dst long doff ulong n ulong to void |
| 669 | b = new uchar 65536 0 |
| 670 | p = ulong 0 |
| 671 | while lt p n bound 999999 |
| 672 | k = sub n p |
| 673 | if gt k 65536 |
| 674 | k = 65536 |
| 675 | end |
| 676 | r = mapread src add so p b 0 k |
| 677 | r = mapwrite dst add doff p b 0 k |
| 678 | p = add p k |
| 679 | end |
| 680 | end |
| 681 | fn mcopy src long n ulong k ulong to long |
| 682 | h = mcreate k n |
| 683 | cpy src 0 h 0 n |
| 684 | ret h |
| 685 | end |
| 686 | fn exists k ulong to bool |
| 687 | pclear |
| 688 | pslot k |
| 689 | ret eq faccess pb 0 get pn 0 0 0 |
| 690 | end |
| 691 | fn mkd k ulong to void |
| 692 | pclear |
| 693 | pslot k |
| 694 | if ne makedir pb 0 get pn 0 493 0 |
| 695 | failio k |
| 696 | end |
| 697 | end |
| 698 | fn wtext k ulong s view uchar * to void |
| 699 | pclear |
| 700 | pslot k |
| 701 | fd = int fopen pb 0 get pn 0 193 420 |
| 702 | if lt fd 0 |
| 703 | failio k |
| 704 | end |
| 705 | r = write fd s 0 len s |
| 706 | c = fclose fd |
| 707 | if or ne r long len s ne c 0 |
| 708 | failio k |
| 709 | end |
| 710 | end |
| 711 | fn g8 h long o ulong to ulong |
| 712 | ret mapget h o 8 |
| 713 | end |
| 714 | fn s8 h long o ulong v ulong to void |
| 715 | r = mapset h o 8 v |
| 716 | end |
| 717 | fn gb h long o ulong to ulong |
| 718 | b = new uchar 1 0 |
| 719 | r = mapread h o b 0 1 |
| 720 | ret ulong get b 0 |
| 721 | end |
| 722 | fn sbt h long o ulong v ulong to void |
| 723 | b = new uchar 1 0 |
| 724 | put b 0 uchar v |
| 725 | r = mapwrite h o b 0 1 |
| 726 | end |
| 727 | fn flip h long o ulong to void |
| 728 | sbt h o xor gb h o 1 |
| 729 | end |
| 730 | fn fnvh h long n ulong to ulong |
| 731 | b = new uchar 65536 0 |
| 732 | v = ulong 14695981039346656037 |
| 733 | p = ulong 120 |
| 734 | while lt p n bound 999999 |
| 735 | k = sub n p |
| 736 | if gt k 65536 |
| 737 | k = 65536 |
| 738 | end |
| 739 | r = mapread h p b 0 k |
| 740 | for i ulong k |
| 741 | v = mul xor v ulong get b i 1099511628211 |
| 742 | end |
| 743 | p = add p k |
| 744 | end |
| 745 | ret v |
| 746 | end |
| 747 | fn reseal h long n ulong to void |
| 748 | s8 h 112 fnvh h n |
| 749 | end |
| 750 | fn mreq h1 long o1 ulong h2 long n ulong to bool |
| 751 | p = ulong 0 |
| 752 | while lt p n bound 999999 |
| 753 | k = sub n p |
| 754 | if gt k 65536 |
| 755 | k = 65536 |
| 756 | end |
| 757 | r = mapread h1 add o1 p ca 0 k |
| 758 | r = mapread h2 p cb 0 k |
| 759 | for i ulong k |
| 760 | if ne get ca i get cb i |
| 761 | ret false |
| 762 | end |
| 763 | end |
| 764 | p = add p k |
| 765 | end |
| 766 | ret true |
| 767 | end |
| 768 | fn fsame k1 ulong k2 ulong to bool |
| 769 | n = fsize k1 |
| 770 | if ne n fsize k2 |
| 771 | ret false |
| 772 | end |
| 773 | if eq n 0 |
| 774 | ret true |
| 775 | end |
| 776 | h1 = mopen k1 |
| 777 | h2 = mopen k2 |
| 778 | same = mreq h1 0 h2 n |
| 779 | mdrop h1 |
| 780 | mdrop h2 |
| 781 | ret same |
| 782 | end |
| 783 | fn mtext h long o ulong s view uchar * to bool |
| 784 | b = new uchar 4096 0 |
| 785 | if gt len s 4096 |
| 786 | fail LCAP |
| 787 | end |
| 788 | r = mapread h o b 0 len s |
| 789 | if ne r long len s |
| 790 | ret false |
| 791 | end |
| 792 | for i ulong len s |
| 793 | if ne get b i get s i |
| 794 | ret false |
| 795 | end |
| 796 | end |
| 797 | ret true |
| 798 | end |
| 799 | note Omega SHA-256 of n bytes at o into dg. |
| 800 | fn shah h long o ulong n ulong to void |
| 801 | b = new uchar 65536 0 |
| 802 | c = new uchar 104 0 |
| 803 | d = new uchar 32 0 |
| 804 | sha256_init c |
| 805 | p = ulong 0 |
| 806 | while lt p n bound 999999 |
| 807 | k = sub n p |
| 808 | if gt k 65536 |
| 809 | k = 65536 |
| 810 | end |
| 811 | r = mapread h add o p b 0 k |
| 812 | sha256_update c part b 0 k |
| 813 | p = add p k |
| 814 | end |
| 815 | sha256_final c d |
| 816 | for i ulong 32 |
| 817 | put dg i get d i |
| 818 | end |
| 819 | end |
| 820 | fn hb to long |
| 821 | ret long get hh 0 |
| 822 | end |
| 823 | fn he to long |
| 824 | ret long get hh 1 |
| 825 | end |
| 826 | fn hm to long |
| 827 | ret long get hh 2 |
| 828 | end |
| 829 | fn mfg i ulong to ulong |
| 830 | ret get mf i |
| 831 | end |
| 832 | |
| 833 | note ---- oracle requests -------------------------------------------------------------------------- |
| 834 | fn rqb b uchar to void |
| 835 | n = get rqn 0 |
| 836 | if ge n len rq |
| 837 | fail LCAP |
| 838 | end |
| 839 | put rq n b |
| 840 | put rqn 0 add n 1 |
| 841 | end |
| 842 | fn rqt s view uchar * to void |
| 843 | for i ulong len s |
| 844 | rqb get s i |
| 845 | end |
| 846 | end |
| 847 | fn rqnum v ulong to void |
| 848 | pclear |
| 849 | pnum v |
| 850 | for i ulong get pn 0 |
| 851 | rqb get pb i |
| 852 | end |
| 853 | end |
| 854 | fn rqslot k ulong to void |
| 855 | o = mul k 512 |
| 856 | for i ulong get sl k |
| 857 | rqb get sb add o i |
| 858 | end |
| 859 | end |
| 860 | fn rqnl to void |
| 861 | rqb 10 |
| 862 | put rqn 1 add get rqn 1 1 |
| 863 | end |
| 864 | fn qsha k ulong o ulong n ulong to void |
| 865 | rqt QSHA |
| 866 | rqnum o |
| 867 | rqb 32 |
| 868 | if eq n ALL |
| 869 | rqb 45 |
| 870 | else |
| 871 | rqnum n |
| 872 | end |
| 873 | rqb 32 |
| 874 | rqslot k |
| 875 | rqnl |
| 876 | end |
| 877 | fn qf32 k ulong to void |
| 878 | rqt QF32 |
| 879 | rqslot k |
| 880 | rqnl |
| 881 | end |
| 882 | fn qne a ulong b ulong s ulong c ulong k ulong to void |
| 883 | rqt QNE |
| 884 | rqnum a |
| 885 | rqb 32 |
| 886 | rqnum b |
| 887 | rqb 32 |
| 888 | rqnum s |
| 889 | rqb 32 |
| 890 | rqnum c |
| 891 | rqb 32 |
| 892 | rqslot k |
| 893 | rqnl |
| 894 | end |
| 895 | note Run the oracle on the pending request; its answer lines go to oo, starts in ol. |
| 896 | fn orun to void |
| 897 | put cnt 2 add get cnt 2 1 |
| 898 | wnamen SRQ FORQ get cnt 2 FREQ |
| 899 | pclear |
| 900 | pslot SRQ |
| 901 | fd = int fopen pb 0 get pn 0 193 420 |
| 902 | if lt fd 0 |
| 903 | failio SRQ |
| 904 | end |
| 905 | r = write fd rq 0 get rqn 0 |
| 906 | c = fclose fd |
| 907 | if or ne r long get rqn 0 ne c 0 |
| 908 | failio SRQ |
| 909 | end |
| 910 | aclear |
| 911 | atext PY |
| 912 | aslot SORC |
| 913 | aslot SRQ |
| 914 | go 0 |
| 915 | n = get obn 0 |
| 916 | if gt n len oo |
| 917 | fail LCAP |
| 918 | end |
| 919 | k = ulong 0 |
| 920 | put ol 0 0 |
| 921 | for i ulong n |
| 922 | put oo i get ob i |
| 923 | if eq get ob i 10 |
| 924 | k = add k 1 |
| 925 | if ge k len ol |
| 926 | fail LCAP |
| 927 | end |
| 928 | put ol k add i 1 |
| 929 | end |
| 930 | end |
| 931 | put oln 0 k |
| 932 | need and eq k get rqn 1 eq get ol k n LORL |
| 933 | put rqn 0 0 |
| 934 | put rqn 1 0 |
| 935 | end |
| 936 | note line i holds exactly 64 lower-case hex digits equal to the 32 bytes b |
| 937 | fn hexis i ulong b view uchar 32 to bool |
| 938 | s = get ol i |
| 939 | if ne sub get ol add i 1 s 65 |
| 940 | ret false |
| 941 | end |
| 942 | for j ulong 32 |
| 943 | x = get b j |
| 944 | o = add s mul j 2 |
| 945 | if ne get oo o get HEXD shr x 4 |
| 946 | ret false |
| 947 | end |
| 948 | if ne get oo add o 1 get HEXD and x 15 |
| 949 | ret false |
| 950 | end |
| 951 | end |
| 952 | ret true |
| 953 | end |
| 954 | fn ohexm i ulong h long o ulong to bool |
| 955 | b = new uchar 32 0 |
| 956 | r = mapread h o b 0 32 |
| 957 | ret hexis i b |
| 958 | end |
| 959 | fn ohexd i ulong to bool |
| 960 | b = new uchar 32 0 |
| 961 | for j ulong 32 |
| 962 | put b j get dg j |
| 963 | end |
| 964 | ret hexis i b |
| 965 | end |
| 966 | fn ohext i ulong s view uchar * to bool |
| 967 | o = get ol i |
| 968 | if ne sub get ol add i 1 o add len s 1 |
| 969 | ret false |
| 970 | end |
| 971 | for j ulong len s |
| 972 | if ne get oo add o j get s j |
| 973 | ret false |
| 974 | end |
| 975 | end |
| 976 | ret true |
| 977 | end |
| 978 | fn oeq i ulong j ulong to bool |
| 979 | a = get ol i |
| 980 | b = get ol j |
| 981 | n = sub get ol add i 1 a |
| 982 | if ne n sub get ol add j 1 b |
| 983 | ret false |
| 984 | end |
| 985 | for k ulong n |
| 986 | if ne get oo add a k get oo add b k |
| 987 | ret false |
| 988 | end |
| 989 | end |
| 990 | ret true |
| 991 | end |
| 992 | fn onum i ulong to ulong |
| 993 | v = ulong 0 |
| 994 | s = get ol i |
| 995 | n = sub sub get ol add i 1 s 1 |
| 996 | for k ulong n |
| 997 | d = sub ulong get oo add s k 48 |
| 998 | v = add mul v 10 d |
| 999 | end |
| 1000 | ret v |
| 1001 | end |
| 1002 | note slot k ends in / + the 64 hex digits of line i + .wp |
| 1003 | fn namechk k ulong i ulong to bool |
| 1004 | n = get sl k |
| 1005 | if lt n 68 |
| 1006 | ret false |
| 1007 | end |
| 1008 | o = add mul k 512 sub n 68 |
| 1009 | if ne get sb o 47 |
| 1010 | ret false |
| 1011 | end |
| 1012 | s = get ol i |
| 1013 | for j ulong 64 |
| 1014 | if ne get sb add add o 1 j get oo add s j |
| 1015 | ret false |
| 1016 | end |
| 1017 | end |
| 1018 | a = eq get sb add o 65 46 |
| 1019 | b = eq get sb add o 66 119 |
| 1020 | c = eq get sb add o 67 112 |
| 1021 | ret and and a b c |
| 1022 | end |
| 1023 | |
| 1024 | note ---- checkpoint geometry ----------------------------------------------------------------------- |
| 1025 | fn tadd kd ulong ly ulong r ulong c ulong to void |
| 1026 | n = get tn 0 |
| 1027 | if ge n 256 |
| 1028 | fail LCAP |
| 1029 | end |
| 1030 | o = mul n 6 |
| 1031 | put tt o kd |
| 1032 | put tt add o 1 ly |
| 1033 | put tt add o 2 r |
| 1034 | put tt add o 3 c |
| 1035 | put tt add o 4 get tn 1 |
| 1036 | put tt add o 5 mul r c |
| 1037 | put tn 0 add n 1 |
| 1038 | put tn 1 add get tn 1 mul r c |
| 1039 | end |
| 1040 | fn tlayer y ulong d ulong f ulong to void |
| 1041 | tadd 2 y 1 d |
| 1042 | tadd 3 y d d |
| 1043 | tadd 4 y d d |
| 1044 | tadd 5 y d d |
| 1045 | tadd 6 y d d |
| 1046 | tadd 7 y 1 d |
| 1047 | tadd 8 y d f |
| 1048 | tadd 9 y f d |
| 1049 | end |
| 1050 | fn tensors h long to void |
| 1051 | put tn 0 0 |
| 1052 | put tn 1 0 |
| 1053 | d = g8 h 24 |
| 1054 | f = g8 h 40 |
| 1055 | tadd 0 0 g8 h 8 d |
| 1056 | tadd 1 0 g8 h 16 d |
| 1057 | for y ulong g8 h 48 |
| 1058 | tlayer y d f |
| 1059 | end |
| 1060 | tadd 10 0 1 d |
| 1061 | end |
| 1062 | fn tget i ulong j ulong to ulong |
| 1063 | ret get tt add mul i 6 j |
| 1064 | end |
| 1065 | fn ckcheck h long n ulong to void |
| 1066 | need mtext h 0 CK02 LMAG |
| 1067 | pp = g8 h 96 |
| 1068 | need eq n add 120 mul 24 pp LCKL |
| 1069 | need eq fnvh h n g8 h 112 LFNV |
| 1070 | tensors h |
| 1071 | k = sub get tn 0 1 |
| 1072 | need eq add tget k 4 tget k 5 pp LGEOP |
| 1073 | end |
| 1074 | |
| 1075 | note ---- manifest --------------------------------------------------------------------------------- |
| 1076 | note mf: 0 size, 1 policy, 2 tensors, 3 entries, 4 P, 5 entry offset, 6 entry size, 7 end of |
| 1077 | note entries, 8 params length, 9 rationale length. The map handle is hh 2. |
| 1078 | fn manfields k ulong to void |
| 1079 | h = mopen k |
| 1080 | put hh 2 ulong h |
| 1081 | put mf 0 fsize k |
| 1082 | put mf 1 g8 h 16 |
| 1083 | put mf 2 g8 h 24 |
| 1084 | put mf 3 g8 h 32 |
| 1085 | put mf 4 g8 h 40 |
| 1086 | es = ulong 40 |
| 1087 | if eq g8 h 16 0 |
| 1088 | es = 24 |
| 1089 | end |
| 1090 | eo = add 376 mul 128 g8 h 24 |
| 1091 | put mf 5 eo |
| 1092 | put mf 6 es |
| 1093 | put mf 7 add eo mul es g8 h 32 |
| 1094 | put mf 8 g8 h 224 |
| 1095 | put mf 9 g8 h 232 |
| 1096 | end |
| 1097 | fn entix i ulong to ulong |
| 1098 | ret g8 hm add mfg 5 mul mfg 6 i |
| 1099 | end |
| 1100 | fn provok to bool |
| 1101 | h = hm |
| 1102 | e = mfg 7 |
| 1103 | if eq get cnt 3 0 |
| 1104 | a = and eq mfg 8 len PARS mtext h e PARS |
| 1105 | b = and eq mfg 9 len RATS mtext h add e mfg 8 RATS |
| 1106 | ret and a b |
| 1107 | end |
| 1108 | a = and eq mfg 8 len PARR mtext h e PARR |
| 1109 | b = and eq mfg 9 len RATR mtext h add e mfg 8 RATR |
| 1110 | ret and a b |
| 1111 | end |
| 1112 | fn ordered to bool |
| 1113 | m = mfg 3 |
| 1114 | if eq m 0 |
| 1115 | ret true |
| 1116 | end |
| 1117 | for i ulong sub m 1 |
| 1118 | if ge entix i entix add i 1 |
| 1119 | ret false |
| 1120 | end |
| 1121 | end |
| 1122 | ret true |
| 1123 | end |
| 1124 | fn inbounds to bool |
| 1125 | for i ulong mfg 3 |
| 1126 | if ge entix i mfg 4 |
| 1127 | ret false |
| 1128 | end |
| 1129 | end |
| 1130 | ret true |
| 1131 | end |
| 1132 | note Manifest structure. Oracle lines 0 and 1 are the manifest SHA and the entry-range SHA. |
| 1133 | fn mancheck k ulong to void |
| 1134 | h = hm |
| 1135 | need mtext h 0 WP01 LWMAG |
| 1136 | need namechk k 0 LNAME |
| 1137 | need eq g8 h 8 mfg 0 LMLEN |
| 1138 | need le mfg 1 2 LPOL |
| 1139 | need ohexm 1 h 192 LEID |
| 1140 | need eq add add mfg 7 mfg 8 mfg 9 mfg 0 LMETA |
| 1141 | need provok LPROV |
| 1142 | need ordered LORD |
| 1143 | need inbounds LBND |
| 1144 | end |
| 1145 | note Queue the manifest SHA and entry-range SHA requests (lines 0 and 1). |
| 1146 | fn qman k ulong to void |
| 1147 | qsha k 0 ALL |
| 1148 | qsha k mfg 5 mul mfg 6 mfg 3 |
| 1149 | end |
| 1150 | fn entchk i ulong to void |
| 1151 | h = hm |
| 1152 | o = add mfg 5 mul mfg 6 i |
| 1153 | old = g8 h add o 8 |
| 1154 | nw = g8 h add o 16 |
| 1155 | wo = add 120 mul 8 g8 h o |
| 1156 | need and eq g8 hb wo old eq g8 he wo nw LEBIT |
| 1157 | need and ne old nw ne and shr nw 52 2047 2047 LEFIN |
| 1158 | need le bitcast f64 and nw 0x7fffffffffffffff 1000000.0 LEMAG |
| 1159 | if gt mfg 1 0 |
| 1160 | pp = mfg 4 |
| 1161 | a = eq g8 h add o 24 g8 hb add wo mul 8 pp |
| 1162 | b = eq g8 h add o 32 g8 hb add wo mul 16 pp |
| 1163 | need and a b LEMOM |
| 1164 | end |
| 1165 | end |
| 1166 | note Expected output derived from the manifest: edited, saved moments zeroed, resealed. |
| 1167 | fn mexpect k ulong to void |
| 1168 | n = fsize SEDIT |
| 1169 | x = mcopy he n k |
| 1170 | pp = mfg 4 |
| 1171 | for i ulong mfg 3 |
| 1172 | wo = add 120 mul 8 entix i |
| 1173 | if ge mfg 1 1 |
| 1174 | s8 x add wo mul 8 pp 0 |
| 1175 | end |
| 1176 | if eq mfg 1 2 |
| 1177 | s8 x add wo mul 16 pp 0 |
| 1178 | end |
| 1179 | end |
| 1180 | reseal x n |
| 1181 | mdrop x |
| 1182 | end |
| 1183 | fn tchanged i ulong to ulong |
| 1184 | lo = tget i 4 |
| 1185 | hi = add lo tget i 5 |
| 1186 | c = ulong 0 |
| 1187 | for j ulong mfg 3 |
| 1188 | x = entix j |
| 1189 | if and ge x lo lt x hi |
| 1190 | c = add c 1 |
| 1191 | end |
| 1192 | end |
| 1193 | ret c |
| 1194 | end |
| 1195 | fn trec i ulong to bool |
| 1196 | h = hm |
| 1197 | r = add 376 mul 128 i |
| 1198 | a = and eq g8 h r tget i 0 eq g8 h add r 8 tget i 1 |
| 1199 | b = and eq g8 h add r 16 tget i 2 eq g8 h add r 24 tget i 3 |
| 1200 | c = and eq g8 h add r 32 64 eq g8 h add r 40 tget i 4 |
| 1201 | ret and and a b c |
| 1202 | end |
| 1203 | note Per-tensor checks; oracle lines from first: nt base-range SHAs, then nt output-range SHAs. |
| 1204 | fn tchk first ulong to void |
| 1205 | nt = mfg 2 |
| 1206 | need eq nt get tn 0 LTALL |
| 1207 | for i ulong nt |
| 1208 | r = add 376 mul 128 i |
| 1209 | need trec i LTGEO |
| 1210 | need eq g8 hm add r 48 tchanged i LTCNT |
| 1211 | need ohexm add first i hm add r 64 LTBS |
| 1212 | need ohexm add add first nt i hm add r 96 LTOS |
| 1213 | end |
| 1214 | end |
| 1215 | note Zero the saved moments of word offset wo as policy p clears them. |
| 1216 | fn zmom x long wo ulong p ulong to void |
| 1217 | pp = g8 x 96 |
| 1218 | if ge p 1 |
| 1219 | s8 x add wo mul 8 pp 0 |
| 1220 | end |
| 1221 | if eq p 2 |
| 1222 | s8 x add wo mul 16 pp 0 |
| 1223 | end |
| 1224 | end |
| 1225 | fn rqword x long i ulong p ulong to void |
| 1226 | wo = add 120 mul 8 get rix i |
| 1227 | s8 x wo get rbt i |
| 1228 | zmom x wo p |
| 1229 | end |
| 1230 | note Requested output from intent: copy of slot src with rix/rbt bits, moments zeroed per policy. |
| 1231 | fn reqout src ulong k ulong p ulong to void |
| 1232 | hs = mopen src |
| 1233 | n = fsize src |
| 1234 | x = mcopy hs n k |
| 1235 | mdrop hs |
| 1236 | for i ulong get rcn 0 |
| 1237 | rqword x i p |
| 1238 | end |
| 1239 | reseal x n |
| 1240 | mdrop x |
| 1241 | end |
| 1242 | |
| 1243 | note ---- small: one policy -------------------------------------------------------------------------- |
| 1244 | fn pdiff p ulong to void |
| 1245 | wnamep SOD FPAT p |
| 1246 | mkd SOD |
| 1247 | acmd CDIFF |
| 1248 | aslot SBASE |
| 1249 | aslot SEDIT |
| 1250 | anum p |
| 1251 | aslot SPF |
| 1252 | aslot SRF |
| 1253 | aslot SOD |
| 1254 | go 0 |
| 1255 | keepout add SP0 p |
| 1256 | end |
| 1257 | fn porc p ulong to void |
| 1258 | k = add SP0 p |
| 1259 | manfields k |
| 1260 | wnamen SMEX FMEX p FCK |
| 1261 | mexpect SMEX |
| 1262 | nt = mfg 2 |
| 1263 | qman k |
| 1264 | qsha SBASE 0 ALL |
| 1265 | qsha SMEX 0 ALL |
| 1266 | qf32 SMEX |
| 1267 | qne add mfg 5 8 add mfg 5 16 mfg 6 mfg 3 k |
| 1268 | for i ulong nt |
| 1269 | qsha SBASE add 120 mul 8 tget i 4 mul 8 tget i 5 |
| 1270 | end |
| 1271 | for i ulong nt |
| 1272 | qsha SMEX add 120 mul 8 tget i 4 mul 8 tget i 5 |
| 1273 | end |
| 1274 | orun |
| 1275 | mancheck k |
| 1276 | need eq mfg 1 p LPOL |
| 1277 | ckcheck hb fsize SBASE |
| 1278 | need mreq hm 256 hb 120 LHDR |
| 1279 | geo = true |
| 1280 | for i ulong 6 |
| 1281 | if ne g8 hm add 48 mul 8 i g8 hb add 8 mul 8 i |
| 1282 | geo = false |
| 1283 | end |
| 1284 | end |
| 1285 | need geo LMGEO |
| 1286 | need eq mfg 4 g8 hb 96 LMP |
| 1287 | need ohexm 2 hm 96 LBSHA |
| 1288 | for i ulong mfg 3 |
| 1289 | entchk i |
| 1290 | end |
| 1291 | need ohexm 3 hm 128 LOSHA |
| 1292 | need ohexm 4 hm 160 LOF32 |
| 1293 | tchk 6 |
| 1294 | end |
| 1295 | fn pshow p ulong to void |
| 1296 | acmd CSHOW |
| 1297 | aslot add SP0 p |
| 1298 | go 0 |
| 1299 | n = get obn 0 |
| 1300 | a = len SHOWA |
| 1301 | z = len SHOWZ |
| 1302 | ok = gt n add add a z 64 |
| 1303 | if ok |
| 1304 | for i ulong a |
| 1305 | if ne get ob i get SHOWA i |
| 1306 | ok = false |
| 1307 | end |
| 1308 | end |
| 1309 | s = get ol 0 |
| 1310 | for j ulong 64 |
| 1311 | if ne get ob add a j get oo add s j |
| 1312 | ok = false |
| 1313 | end |
| 1314 | end |
| 1315 | for i ulong z |
| 1316 | if ne get ob add sub n z i get SHOWZ i |
| 1317 | ok = false |
| 1318 | end |
| 1319 | end |
| 1320 | end |
| 1321 | need ok LSHOW |
| 1322 | end |
| 1323 | fn papply p ulong to void |
| 1324 | acmd CVAL |
| 1325 | aslot add SP0 p |
| 1326 | aslot SBASE |
| 1327 | go 0 |
| 1328 | wnamen SOUT FAPP p FCK |
| 1329 | wnamen SREV FREV p FCK |
| 1330 | acmd CAPP |
| 1331 | aslot add SP0 p |
| 1332 | aslot SBASE |
| 1333 | aslot SOUT |
| 1334 | go 0 |
| 1335 | need fsame SOUT SMEX LAPPX |
| 1336 | need fsame SREQ SOUT LAPPR |
| 1337 | acmd CVER |
| 1338 | aslot add SP0 p |
| 1339 | aslot SOUT |
| 1340 | go 0 |
| 1341 | pclear |
| 1342 | ptext SURV |
| 1343 | pnum onum 5 |
| 1344 | ptext CHGD |
| 1345 | pnum mfg 3 |
| 1346 | need obhaspb LSURV |
| 1347 | acmd CREV |
| 1348 | aslot add SP0 p |
| 1349 | aslot SOUT |
| 1350 | aslot SREV |
| 1351 | go 0 |
| 1352 | need fsame SREV SSNAP LREVB |
| 1353 | end |
| 1354 | fn pbind p ulong to void |
| 1355 | k = add SP0 p |
| 1356 | wnamep SBIND FBND p |
| 1357 | acmd CBIND |
| 1358 | aslot k |
| 1359 | aslot SOUT |
| 1360 | aslot SWP |
| 1361 | aslot SBIND |
| 1362 | go 0 |
| 1363 | qsha SMEX 0 ALL |
| 1364 | qf32 SMEX |
| 1365 | qsha SWP 0 ALL |
| 1366 | qsha k 0 ALL |
| 1367 | qsha SBIND 0 136 |
| 1368 | orun |
| 1369 | h = mopen SBIND |
| 1370 | need and eq fsize SBIND 168 mtext h 0 WB01 LBFMT |
| 1371 | need and ohexm 0 h 8 ohexm 1 h 40 LBCK |
| 1372 | need and ohexm 2 h 72 ohexm 3 h 104 LBRT |
| 1373 | need ohexm 4 h 136 LBSELF |
| 1374 | mdrop h |
| 1375 | end |
| 1376 | fn pcheckb p ulong to void |
| 1377 | acmd CCB |
| 1378 | aslot SBIND |
| 1379 | aslot SOUT |
| 1380 | aslot SWP |
| 1381 | go 0 |
| 1382 | acmd CCB |
| 1383 | aslot SBIND |
| 1384 | aslot SBASE |
| 1385 | aslot SWP |
| 1386 | go 60 |
| 1387 | wnamep SRT FRT p |
| 1388 | n = fsize SWP |
| 1389 | h = mopen SWP |
| 1390 | x = mcreate SRT add n 1 |
| 1391 | cpy h 0 x 0 n |
| 1392 | mdrop x |
| 1393 | mdrop h |
| 1394 | acmd CCB |
| 1395 | aslot SBIND |
| 1396 | aslot SOUT |
| 1397 | aslot SRT |
| 1398 | go 62 |
| 1399 | wnamep SBADB FBADB p |
| 1400 | h = mopen SBIND |
| 1401 | x = mcopy h 168 SBADB |
| 1402 | mdrop h |
| 1403 | flip x 40 |
| 1404 | shah x 0 136 |
| 1405 | r = mapwrite x 136 dg 0 32 |
| 1406 | acmd CCB |
| 1407 | aslot SBADB |
| 1408 | aslot SOUT |
| 1409 | aslot SWP |
| 1410 | go 61 |
| 1411 | flip x 104 |
| 1412 | acmd CCB |
| 1413 | aslot SBADB |
| 1414 | aslot SOUT |
| 1415 | aslot SWP |
| 1416 | go 59 |
| 1417 | mdrop x |
| 1418 | end |
| 1419 | fn prefuse p ulong to void |
| 1420 | acmd CAPP |
| 1421 | aslot add SP0 p |
| 1422 | aslot SBASE |
| 1423 | aslot SOUT |
| 1424 | go 52 |
| 1425 | need fsame SOUT SMEX LOUTP |
| 1426 | acmd CAPP |
| 1427 | aslot add SP0 p |
| 1428 | aslot SBASE |
| 1429 | aslot SBASE |
| 1430 | go 52 |
| 1431 | acmd CREV |
| 1432 | aslot add SP0 p |
| 1433 | aslot SOUT |
| 1434 | aslot SBASE |
| 1435 | go 52 |
| 1436 | acmd CDIFF |
| 1437 | aslot SBASE |
| 1438 | aslot SEDIT |
| 1439 | anum p |
| 1440 | aslot SPF |
| 1441 | aslot SRF |
| 1442 | aslot SOD |
| 1443 | go 52 |
| 1444 | end |
| 1445 | fn policy p ulong to void |
| 1446 | pdiff p |
| 1447 | porc p |
| 1448 | wnamen SREQ FEXP p FCK |
| 1449 | reqout SBASE SREQ p |
| 1450 | need fsame SREQ SMEX LAGREE |
| 1451 | pshow p |
| 1452 | papply p |
| 1453 | pbind p |
| 1454 | pcheckb p |
| 1455 | prefuse p |
| 1456 | mdrop hm |
| 1457 | end |
| 1458 | |
| 1459 | note ---- small: fixtures and adversarial manifests -------------------------------------------------- |
| 1460 | fn train to void |
| 1461 | wname STRAIN FTRAIN |
| 1462 | h = mcreate STRAIN 3000 |
| 1463 | b = new uchar 15 0 |
| 1464 | for i ulong len TRAINW |
| 1465 | put b i get TRAINW i |
| 1466 | end |
| 1467 | for i ulong 200 |
| 1468 | r = mapwrite h mul i 15 b 0 15 |
| 1469 | end |
| 1470 | mdrop h |
| 1471 | wname SBASE FBASE |
| 1472 | aclear |
| 1473 | aslot SOLLM |
| 1474 | atext CINIT |
| 1475 | aslot SBASE |
| 1476 | awords INITA |
| 1477 | go 0 |
| 1478 | aclear |
| 1479 | aslot SOLLM |
| 1480 | atext CTRAIN |
| 1481 | aslot SBASE |
| 1482 | aslot STRAIN |
| 1483 | anum 2 |
| 1484 | anum 1 |
| 1485 | go 0 |
| 1486 | end |
| 1487 | note edited = base + 0.001 at every tensor start, index 1 low bit flipped; requested = those bits. |
| 1488 | fn mkedit to void |
| 1489 | n = fsize SBASE |
| 1490 | h = mopen SBASE |
| 1491 | put hh 0 ulong h |
| 1492 | ckcheck h n |
| 1493 | wname SSNAP FSNAP |
| 1494 | x = mcopy h n SSNAP |
| 1495 | mdrop x |
| 1496 | wname SEDIT FEDIT |
| 1497 | x = mcopy h n SEDIT |
| 1498 | put hh 1 ulong x |
| 1499 | k = get tn 0 |
| 1500 | for i ulong k |
| 1501 | wo = add 120 mul 8 tget i 4 |
| 1502 | s8 x wo bitcast ulong add bitcast f64 g8 x wo DLT |
| 1503 | put rix i tget i 4 |
| 1504 | put rbt i g8 x wo |
| 1505 | end |
| 1506 | s8 x 128 xor g8 x 128 1 |
| 1507 | put rix k 1 |
| 1508 | put rbt k g8 x 128 |
| 1509 | put rcn 0 add k 1 |
| 1510 | reseal x n |
| 1511 | wname SPF FPF |
| 1512 | wtext SPF PARS |
| 1513 | wname SRF FRF |
| 1514 | wtext SRF RATS |
| 1515 | end |
| 1516 | fn inspect to void |
| 1517 | acmd CINSP |
| 1518 | aslot SBASE |
| 1519 | go 0 |
| 1520 | acmd CINSP |
| 1521 | aslot SBASE |
| 1522 | atext WTE |
| 1523 | awords SLICEA |
| 1524 | go 0 |
| 1525 | pclear |
| 1526 | phex g8 hb 120 |
| 1527 | a = obhaspb |
| 1528 | pclear |
| 1529 | phex g8 hb 128 |
| 1530 | need and a obhaspb LSLICE |
| 1531 | acmd CINSP |
| 1532 | aslot SBASE |
| 1533 | atext WTE |
| 1534 | awords OOBA |
| 1535 | go 27 |
| 1536 | end |
| 1537 | note Policy-2 patch for an edit whose index-0 value is 0.25: verify accepts it, yet its applied |
| 1538 | note bytes must differ from expected-2.ck (the in-run negative control of the byte oracle). |
| 1539 | fn mutant to void |
| 1540 | n = fsize SEDIT |
| 1541 | wname SX0 FMUTE |
| 1542 | x = mcopy he n SX0 |
| 1543 | s8 x 120 bitcast ulong QTR |
| 1544 | reseal x n |
| 1545 | mdrop x |
| 1546 | wname SX1 FMUTD |
| 1547 | mkd SX1 |
| 1548 | acmd CDIFF |
| 1549 | aslot SBASE |
| 1550 | aslot SX0 |
| 1551 | anum 2 |
| 1552 | aslot SPF |
| 1553 | aslot SRF |
| 1554 | aslot SX1 |
| 1555 | go 0 |
| 1556 | keepout SX2 |
| 1557 | wname SX3 FMUTO |
| 1558 | acmd CAPP |
| 1559 | aslot SX2 |
| 1560 | aslot SBASE |
| 1561 | aslot SX3 |
| 1562 | go 0 |
| 1563 | acmd CVER |
| 1564 | aslot SX2 |
| 1565 | aslot SX3 |
| 1566 | go 0 |
| 1567 | old = get rbt 0 |
| 1568 | put rbt 0 bitcast ulong QTR |
| 1569 | wname SX4 FMUTR |
| 1570 | reqout SBASE SX4 2 |
| 1571 | put rbt 0 old |
| 1572 | need fsame SX4 SX3 LMUTS |
| 1573 | wnamen SREQ FEXP 2 FCK |
| 1574 | need not fsame SREQ SX3 LMUTR |
| 1575 | end |
| 1576 | fn fill h long o ulong n ulong to void |
| 1577 | b = new uchar 65536 97 |
| 1578 | p = ulong 0 |
| 1579 | while lt p n bound 999999 |
| 1580 | k = sub n p |
| 1581 | if gt k 65536 |
| 1582 | k = 65536 |
| 1583 | end |
| 1584 | r = mapwrite h add o p b 0 k |
| 1585 | p = add p k |
| 1586 | end |
| 1587 | end |
| 1588 | note Oversized params (f 0) or rationale (f 1): 16777217 bytes of a, length fields updated. |
| 1589 | fn oversize f ulong to void |
| 1590 | manfields add SP0 2 |
| 1591 | n0 = mfg 0 |
| 1592 | e = add mfg 7 mfg 8 |
| 1593 | if eq f 0 |
| 1594 | e = mfg 7 |
| 1595 | end |
| 1596 | dropn = mfg 9 |
| 1597 | if eq f 0 |
| 1598 | dropn = mfg 8 |
| 1599 | end |
| 1600 | nn = sub add n0 OVER dropn |
| 1601 | if eq f 0 |
| 1602 | pclear |
| 1603 | pslot SWORK |
| 1604 | pbyte 47 |
| 1605 | ptext FOVP |
| 1606 | else |
| 1607 | pclear |
| 1608 | pslot SWORK |
| 1609 | pbyte 47 |
| 1610 | ptext FOVR |
| 1611 | end |
| 1612 | ptext FWP |
| 1613 | keepat SX0 |
| 1614 | pn0 = get pn 0 |
| 1615 | put pn 0 sub pn0 3 |
| 1616 | ptext FCK |
| 1617 | keepat SX1 |
| 1618 | x = mcreate SX0 nn |
| 1619 | cpy hm 0 x 0 e |
| 1620 | fill x e OVER |
| 1621 | if eq f 0 |
| 1622 | cpy hm add e mfg 8 x add e OVER mfg 9 |
| 1623 | s8 x 224 OVER |
| 1624 | else |
| 1625 | s8 x 232 OVER |
| 1626 | end |
| 1627 | s8 x 8 nn |
| 1628 | mdrop x |
| 1629 | mdrop hm |
| 1630 | acmd CVAL |
| 1631 | aslot SX0 |
| 1632 | aslot SBASE |
| 1633 | go 57 |
| 1634 | acmd CSHOW |
| 1635 | aslot SX0 |
| 1636 | go 57 |
| 1637 | acmd CAPP |
| 1638 | aslot SX0 |
| 1639 | aslot SBASE |
| 1640 | aslot SX1 |
| 1641 | go 57 |
| 1642 | need not exists SX1 LOVER |
| 1643 | end |
| 1644 | fn badutf to void |
| 1645 | manfields add SP0 2 |
| 1646 | n = mfg 0 |
| 1647 | wname SX0 FUTF |
| 1648 | x = mcopy hm n SX0 |
| 1649 | sbt x sub n 1 255 |
| 1650 | mdrop x |
| 1651 | mdrop hm |
| 1652 | acmd CVAL |
| 1653 | aslot SX0 |
| 1654 | aslot SBASE |
| 1655 | go 31 |
| 1656 | end |
| 1657 | note Apply mutation c (0..16, named by word c of MUTN) to x; return the expected refusal code. |
| 1658 | fn mutate x long c ulong to ulong |
| 1659 | eo = mfg 5 |
| 1660 | if eq c 0 |
| 1661 | flip x 96 |
| 1662 | ret 50 |
| 1663 | end |
| 1664 | if eq c 1 |
| 1665 | s8 x 48 add g8 x 48 1 |
| 1666 | ret 36 |
| 1667 | end |
| 1668 | if eq c 2 |
| 1669 | s8 x 392 add g8 x 392 1 |
| 1670 | ret 37 |
| 1671 | end |
| 1672 | if eq c 3 |
| 1673 | s8 x eo mfg 4 |
| 1674 | ret 38 |
| 1675 | end |
| 1676 | if eq c 4 |
| 1677 | s8 x add eo 16 0x7ff8000000000000 |
| 1678 | ret 40 |
| 1679 | end |
| 1680 | if eq c 5 |
| 1681 | s8 x add eo 16 0x7ff0000000000000 |
| 1682 | ret 41 |
| 1683 | end |
| 1684 | if eq c 6 |
| 1685 | s8 x add eo 16 bitcast ulong BIGM |
| 1686 | ret 42 |
| 1687 | end |
| 1688 | if eq c 7 |
| 1689 | for j ulong 5 |
| 1690 | a = g8 x add eo mul 8 j |
| 1691 | s8 x add eo mul 8 j g8 x add add eo 40 mul 8 j |
| 1692 | s8 x add add eo 40 mul 8 j a |
| 1693 | end |
| 1694 | ret 39 |
| 1695 | end |
| 1696 | if eq c 8 |
| 1697 | s8 x add eo 40 g8 x eo |
| 1698 | ret 43 |
| 1699 | end |
| 1700 | ret mutate2 x c |
| 1701 | end |
| 1702 | fn mutate2 x long c ulong to ulong |
| 1703 | eo = mfg 5 |
| 1704 | if eq c 9 |
| 1705 | s8 x add eo 8 xor g8 x add eo 8 1 |
| 1706 | ret 47 |
| 1707 | end |
| 1708 | if eq c 10 |
| 1709 | s8 x add eo 24 xor g8 x add eo 24 1 |
| 1710 | ret 48 |
| 1711 | end |
| 1712 | if eq c 11 |
| 1713 | flip x 192 |
| 1714 | ret 46 |
| 1715 | end |
| 1716 | if eq c 12 |
| 1717 | s8 x 424 add g8 x 424 1 |
| 1718 | ret 45 |
| 1719 | end |
| 1720 | if eq c 13 |
| 1721 | flip x 440 |
| 1722 | ret 49 |
| 1723 | end |
| 1724 | if eq c 14 |
| 1725 | flip x 472 |
| 1726 | ret 49 |
| 1727 | end |
| 1728 | if eq c 15 |
| 1729 | flip x 128 |
| 1730 | ret 53 |
| 1731 | end |
| 1732 | flip x 160 |
| 1733 | ret 54 |
| 1734 | end |
| 1735 | fn mutcase c ulong to void |
| 1736 | n = mfg 0 |
| 1737 | pclear |
| 1738 | pslot SWORK |
| 1739 | pbyte 47 |
| 1740 | pword MUTN c |
| 1741 | ptext FWP |
| 1742 | keepat SX0 |
| 1743 | put pn 0 sub get pn 0 3 |
| 1744 | ptext FCK |
| 1745 | keepat SX1 |
| 1746 | x = mcopy hm n SX0 |
| 1747 | code = mutate x c |
| 1748 | if ne c 11 |
| 1749 | shah x mfg 5 mul mfg 6 mfg 3 |
| 1750 | r = mapwrite x 192 dg 0 32 |
| 1751 | end |
| 1752 | mdrop x |
| 1753 | acmd CVAL |
| 1754 | aslot SX0 |
| 1755 | aslot SBASE |
| 1756 | go code |
| 1757 | acmd CAPP |
| 1758 | aslot SX0 |
| 1759 | aslot SBASE |
| 1760 | aslot SX1 |
| 1761 | go code |
| 1762 | gone = not exists SX1 |
| 1763 | pclear |
| 1764 | pword MUTN c |
| 1765 | needpm gone LREF |
| 1766 | end |
| 1767 | fn flipped to void |
| 1768 | n = mfg 0 |
| 1769 | wname SX0 FFLIP |
| 1770 | mkd SX0 |
| 1771 | k = add SP0 1 |
| 1772 | pclear |
| 1773 | pslot SX0 |
| 1774 | o = add mul k 512 sub get sl k 68 |
| 1775 | for i ulong 68 |
| 1776 | pbyte get sb add o i |
| 1777 | end |
| 1778 | keepat SX0 |
| 1779 | x = mcopy hm n SX0 |
| 1780 | flip x sub n 1 |
| 1781 | mdrop x |
| 1782 | wnamen SX1 FAPP 1 FCK |
| 1783 | acmd CSHOW |
| 1784 | aslot SX0 |
| 1785 | go 30 |
| 1786 | acmd CVAL |
| 1787 | aslot SX0 |
| 1788 | aslot SBASE |
| 1789 | go 30 |
| 1790 | acmd CVER |
| 1791 | aslot SX0 |
| 1792 | aslot SX1 |
| 1793 | go 30 |
| 1794 | wname SX2 FBAPP |
| 1795 | acmd CAPP |
| 1796 | aslot SX0 |
| 1797 | aslot SBASE |
| 1798 | aslot SX2 |
| 1799 | go 30 |
| 1800 | wname SX2 FBREV |
| 1801 | acmd CREV |
| 1802 | aslot SX0 |
| 1803 | aslot SX1 |
| 1804 | aslot SX2 |
| 1805 | go 30 |
| 1806 | wname SX2 FBBND |
| 1807 | acmd CBIND |
| 1808 | aslot SX0 |
| 1809 | aslot SX1 |
| 1810 | aslot SWP |
| 1811 | aslot SX2 |
| 1812 | go 30 |
| 1813 | end |
| 1814 | fn truncs to void |
| 1815 | n = mfg 0 |
| 1816 | wname SX0 FTRUNC |
| 1817 | x = mcopy hm sub n 1 SX0 |
| 1818 | mdrop x |
| 1819 | acmd CVAL |
| 1820 | aslot SX0 |
| 1821 | aslot SBASE |
| 1822 | go 32 |
| 1823 | pclear |
| 1824 | pslot SX0 |
| 1825 | r = unlink pb 0 get pn 0 |
| 1826 | x = mcopy hm 100 SX0 |
| 1827 | mdrop x |
| 1828 | acmd CSHOW |
| 1829 | aslot SX0 |
| 1830 | go 32 |
| 1831 | end |
| 1832 | fn diffbad to void |
| 1833 | acmd CDIFF |
| 1834 | aslot SBASE |
| 1835 | aslot SBASE |
| 1836 | anum 0 |
| 1837 | aslot SPF |
| 1838 | aslot SRF |
| 1839 | aslot SWORK |
| 1840 | go 55 |
| 1841 | n = fsize SEDIT |
| 1842 | wname SX0 FWRM |
| 1843 | x = mcopy he n SX0 |
| 1844 | o = add 120 mul 8 g8 x 96 |
| 1845 | s8 x o xor g8 x o 1 |
| 1846 | reseal x n |
| 1847 | mdrop x |
| 1848 | acmd CDIFF |
| 1849 | aslot SBASE |
| 1850 | aslot SX0 |
| 1851 | anum 0 |
| 1852 | aslot SPF |
| 1853 | aslot SRF |
| 1854 | aslot SWORK |
| 1855 | go 56 |
| 1856 | end |
| 1857 | fn exval i ulong to ulong |
| 1858 | if eq i 0 |
| 1859 | ret 0 |
| 1860 | end |
| 1861 | if eq i 1 |
| 1862 | ret 0x8000000000000000 |
| 1863 | end |
| 1864 | if eq i 2 |
| 1865 | ret 1 |
| 1866 | end |
| 1867 | if eq i 3 |
| 1868 | ret 0x3690000000000000 |
| 1869 | end |
| 1870 | if eq i 4 |
| 1871 | ret 0x3ff0000010000000 |
| 1872 | end |
| 1873 | if eq i 5 |
| 1874 | ret 0x3ff0000030000000 |
| 1875 | end |
| 1876 | if eq i 6 |
| 1877 | ret 0x47f0000000000000 |
| 1878 | end |
| 1879 | if eq i 7 |
| 1880 | ret 0x7ff0000000000000 |
| 1881 | end |
| 1882 | if eq i 8 |
| 1883 | ret 0xfff0000000000000 |
| 1884 | end |
| 1885 | if eq i 9 |
| 1886 | ret 0x7ff8000000000000 |
| 1887 | end |
| 1888 | ret 0x7fefffffffffffff |
| 1889 | end |
| 1890 | note true when the bytes of s occur in ob at o, before e |
| 1891 | fn obat o ulong e ulong s view uchar * to bool |
| 1892 | if gt add o len s e |
| 1893 | ret false |
| 1894 | end |
| 1895 | for j ulong len s |
| 1896 | if ne get ob add o j get s j |
| 1897 | ret false |
| 1898 | end |
| 1899 | end |
| 1900 | ret true |
| 1901 | end |
| 1902 | note true when the inspect line starting `wte ` has rms= with a leading digit 1-9 and nonfinite=3 |
| 1903 | fn rmsok to bool |
| 1904 | n = get obn 0 |
| 1905 | s = ulong 0 |
| 1906 | for i ulong n |
| 1907 | if eq get ob i 10 |
| 1908 | if obat s i WTEL |
| 1909 | ret lineok s i |
| 1910 | end |
| 1911 | s = add i 1 |
| 1912 | end |
| 1913 | end |
| 1914 | ret false |
| 1915 | end |
| 1916 | fn lineok s ulong e ulong to bool |
| 1917 | r = false |
| 1918 | f = false |
| 1919 | for i ulong sub e s |
| 1920 | o = add s i |
| 1921 | if obat o e RMSK |
| 1922 | if lt add o 4 e |
| 1923 | c = get ob add o 4 |
| 1924 | r = and ge c 49 le c 57 |
| 1925 | end |
| 1926 | end |
| 1927 | if obat o e NONF3 |
| 1928 | f = true |
| 1929 | end |
| 1930 | end |
| 1931 | ret and r f |
| 1932 | end |
| 1933 | fn exotic to void |
| 1934 | n = fsize SBASE |
| 1935 | wname SX0 FEXO |
| 1936 | x = mcopy hb n SX0 |
| 1937 | for i ulong 11 |
| 1938 | s8 x add 120 mul 8 i exval i |
| 1939 | end |
| 1940 | reseal x n |
| 1941 | wname SX1 FEXE |
| 1942 | y = mcopy x n SX1 |
| 1943 | mdrop x |
| 1944 | s8 y 216 bitcast ulong QTR |
| 1945 | reseal y n |
| 1946 | mdrop y |
| 1947 | wname SX2 FEXD |
| 1948 | mkd SX2 |
| 1949 | acmd CDIFF |
| 1950 | aslot SX0 |
| 1951 | aslot SX1 |
| 1952 | anum 0 |
| 1953 | aslot SPF |
| 1954 | aslot SRF |
| 1955 | aslot SX2 |
| 1956 | go 0 |
| 1957 | keepout SX3 |
| 1958 | qf32 SX1 |
| 1959 | orun |
| 1960 | h = mopen SX3 |
| 1961 | need ohexm 0 h 160 LEXO |
| 1962 | mdrop h |
| 1963 | acmd CVAL |
| 1964 | aslot SX3 |
| 1965 | aslot SX0 |
| 1966 | go 0 |
| 1967 | acmd CINSP |
| 1968 | aslot SX0 |
| 1969 | go 0 |
| 1970 | need rmsok LRMS |
| 1971 | end |
| 1972 | fn small to void |
| 1973 | train |
| 1974 | mkedit |
| 1975 | inspect |
| 1976 | for p ulong 3 |
| 1977 | policy p |
| 1978 | end |
| 1979 | need fsame SBASE SSNAP LBASEW |
| 1980 | mutant |
| 1981 | oversize 0 |
| 1982 | oversize 1 |
| 1983 | badutf |
| 1984 | manfields add SP0 1 |
| 1985 | for c ulong 17 |
| 1986 | mutcase c |
| 1987 | end |
| 1988 | flipped |
| 1989 | truncs |
| 1990 | mdrop hm |
| 1991 | diffbad |
| 1992 | exotic |
| 1993 | need fsame SBASE SSNAP LFBASE |
| 1994 | end |
| 1995 | |
| 1996 | note ---- real --------------------------------------------------------------------------------------- |
| 1997 | fn redit to void |
| 1998 | n = fsize SBASE |
| 1999 | h = mopen SBASE |
| 2000 | put hh 0 ulong h |
| 2001 | wname SEDIT FR40E |
| 2002 | x = mcopy h n SEDIT |
| 2003 | put hh 1 ulong x |
| 2004 | tensors x |
| 2005 | off = ulong 0 |
| 2006 | for i ulong get tn 0 |
| 2007 | if and eq tget i 0 9 eq tget i 1 3 |
| 2008 | off = tget i 4 |
| 2009 | end |
| 2010 | end |
| 2011 | need eq off BASEOFF LROFF |
| 2012 | for i ulong 10 |
| 2013 | wo = add 120 mul 8 add off i |
| 2014 | s8 x wo bitcast ulong add bitcast f64 g8 x wo DLT |
| 2015 | put rix i add off i |
| 2016 | put rbt i g8 x wo |
| 2017 | end |
| 2018 | put rcn 0 10 |
| 2019 | reseal x n |
| 2020 | end |
| 2021 | fn rten to bool |
| 2022 | if ne mfg 3 10 |
| 2023 | ret false |
| 2024 | end |
| 2025 | for i ulong 10 |
| 2026 | if ne entix i add get rix 0 i |
| 2027 | ret false |
| 2028 | end |
| 2029 | end |
| 2030 | ret true |
| 2031 | end |
| 2032 | fn real to void |
| 2033 | qsha SBASE 0 ALL |
| 2034 | orun |
| 2035 | need ohext 0 BSHA LRPIN |
| 2036 | redit |
| 2037 | wname SREQ FR40X |
| 2038 | reqout SBASE SREQ 2 |
| 2039 | wname SPF FPF |
| 2040 | wtext SPF PARR |
| 2041 | wname SRF FRF |
| 2042 | wtext SRF RATR |
| 2043 | wname SOD FPATS |
| 2044 | mkd SOD |
| 2045 | acmd CDIFF |
| 2046 | aslot SBASE |
| 2047 | aslot SEDIT |
| 2048 | anum 2 |
| 2049 | aslot SPF |
| 2050 | aslot SRF |
| 2051 | aslot SOD |
| 2052 | go 0 |
| 2053 | keepout SP0 |
| 2054 | manfields SP0 |
| 2055 | qman SP0 |
| 2056 | orun |
| 2057 | mancheck SP0 |
| 2058 | need rten LRTEN |
| 2059 | acmd CVAL |
| 2060 | aslot SP0 |
| 2061 | aslot SBASE |
| 2062 | go 0 |
| 2063 | wname SOUT FR40A |
| 2064 | wname SREV FR40R |
| 2065 | acmd CAPP |
| 2066 | aslot SP0 |
| 2067 | aslot SBASE |
| 2068 | aslot SOUT |
| 2069 | go 0 |
| 2070 | need fsame SREQ SOUT LRAPP |
| 2071 | acmd CVER |
| 2072 | aslot SP0 |
| 2073 | aslot SOUT |
| 2074 | go 0 |
| 2075 | acmd CREV |
| 2076 | aslot SP0 |
| 2077 | aslot SOUT |
| 2078 | aslot SREV |
| 2079 | go 0 |
| 2080 | aclear |
| 2081 | atext SUMT |
| 2082 | aslot SBASE |
| 2083 | aslot SREV |
| 2084 | aslot SOUT |
| 2085 | go 0 |
| 2086 | qsha SREV 0 ALL |
| 2087 | qsha SBASE 0 ALL |
| 2088 | qsha SOUT 0 ALL |
| 2089 | qsha SREQ 0 ALL |
| 2090 | qf32 SREQ |
| 2091 | qf32 SOUT |
| 2092 | orun |
| 2093 | need ohext 0 BSHA LRREV |
| 2094 | need ohext 1 BSHA LRBASE |
| 2095 | need oeq 2 3 LROUT |
| 2096 | need ohexm 3 hm 128 LRMOUT |
| 2097 | need oeq 5 4 LRF32 |
| 2098 | need ohexm 4 hm 160 LRMF32 |
| 2099 | end |
| 2100 | |
| 2101 | note Print dg as 64 lowercase hex digits. |
| 2102 | fn sayhex to void |
| 2103 | pclear |
| 2104 | for i ulong 32 |
| 2105 | pbyte get HEXD shr get dg i 4 |
| 2106 | pbyte get HEXD and get dg i 15 |
| 2107 | end |
| 2108 | saypb |
| 2109 | end |
| 2110 | note `wpcheck sum FILE`: the Omega SHA-256 of FILE as hex and a newline (wpbuild uses it to check |
| 2111 | note the vendored net sources). An unreadable FILE is a FAIL with exit 1. An empty FILE is not |
| 2112 | note mapped (a zero-length map traps); its digest is the SHA-256 of no bytes. |
| 2113 | fn sumone to int |
| 2114 | argslot 2 SBASE |
| 2115 | n = fsize SBASE |
| 2116 | c = new uchar 104 0 |
| 2117 | d = new uchar 32 0 |
| 2118 | if eq n 0 |
| 2119 | sha256_init c |
| 2120 | sha256_final c d |
| 2121 | for i ulong 32 |
| 2122 | put dg i get d i |
| 2123 | end |
| 2124 | else |
| 2125 | h = mopen SBASE |
| 2126 | shah h 0 n |
| 2127 | mdrop h |
| 2128 | end |
| 2129 | sayhex |
| 2130 | say NL |
| 2131 | ret 0 |
| 2132 | end |
| 2133 | fn main to int |
| 2134 | c = argcnt |
| 2135 | if and and ne c 3 ne c 5 ne c 6 |
| 2136 | say USAGE |
| 2137 | ret 2 |
| 2138 | end |
| 2139 | argslot 1 SMODE |
| 2140 | if and eq c 3 slotis SMODE MSUM |
| 2141 | ret sumone |
| 2142 | end |
| 2143 | ok = or and eq c 5 slotis SMODE MSMALL and eq c 6 slotis SMODE MREAL |
| 2144 | if not ok |
| 2145 | say USAGE |
| 2146 | ret 2 |
| 2147 | end |
| 2148 | argslot 2 SBUILD |
| 2149 | argslot 3 SWORK |
| 2150 | argslot 4 SORC |
| 2151 | if eq c 6 |
| 2152 | argslot 5 SBASE |
| 2153 | put cnt 3 1 |
| 2154 | end |
| 2155 | under SWP SBUILD SLWP |
| 2156 | under SOLLM SBUILD SLOLLM |
| 2157 | mkd SWORK |
| 2158 | h = mopen SWP |
| 2159 | shah h 0 fsize SWP |
| 2160 | mdrop h |
| 2161 | say HEADT |
| 2162 | pclear |
| 2163 | pslot SMODE |
| 2164 | saypb |
| 2165 | say WPSHT |
| 2166 | sayhex |
| 2167 | say NL |
| 2168 | if eq c 5 |
| 2169 | small |
| 2170 | else |
| 2171 | real |
| 2172 | end |
| 2173 | say WPPT |
| 2174 | tally |
| 2175 | ret 0 |
| 2176 | end |