Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/spark-rsi-mv/blob/main/om/reuse-eval/ref.om # spark-rsi-mv Native Rust recursive self-improvement engine with paired bootstrap evaluation and cryptographic ledger Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `spark-rsi-mv / om / reuse-eval / ref.om` 643 lines ยท 9823 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note ref.om: the evaluator's own reference of REUSE-1 profile R1 (docs/reuse/REUSE-1.md v1.0, 3 note omega-mv `d6edaad1`, section 1), written from the contract text alone (no candidate code read). 4 note Units before it: sha256 (omega-mv main om/sha256/sha256.om, unchanged). Prefix rf / RF. 5 note 6 note Use: put one request frame (op, p, p payload words) into RFRQ, call rfreq; the response is in 7 note RFRS (0 status, 1 q, 2 r0, 3 r1, 4 route 0, rest 0) and rfreq returns the status. 8 note Status rules (contract 1.3, 2, integrator clarification K2): 9 note p > 7234 or unknown op: 4. p not matching its op: 4. BEGIN: p < 65 or p != 65 + n: 4, 10 note n > 4096: 5, invalid PROG: 2, a value outside the domain: 3; a refused BEGIN keeps the 11 note previous session. Ops 2..8 without a session: 6. STATS and END: 0, q 0 (END drops the 12 note session). SET/INS/DEL/SWAP: 3 when an index is out of range, a value is outside the domain 13 note or INS would make n > 4096. BATCH: m outside 1..1024: 3; item op outside 3..6 or a DEL item 14 note with b != 0: 3; items judged in order on the state the earlier items leave; all or nothing. 15 note PROGRAM: invalid PROG 2 first, then any state value outside the new domain 3. 16 note Validity of one change depends only on n and the domain, so BATCH is validated by simulating n 17 note over the items and applied only when every item is valid (nothing is written before that). 18 note 19 note Hashing: rfpdig hashes RFP (512 LE bytes) into RFPD; streams use a context slot 0..7: 20 note rfhini slot, rfhabs slot n (RFHB[0..n), n <= 65536), rfhfin slot (-> RFHD). Digest word j = 21 note bytes 8j..8j+7 read big endian (contract 1.1). 22 23 global RFP ulong 64 24 global RFQ ulong 64 25 global RFN ulong 1 26 global RFX ulong 4096 27 global RFS ulong 1 28 global RFR ulong 2 29 global RFRQ ulong 7240 30 global RFRS ulong 8 31 global RFPD ulong 4 32 global RFHB uchar 65536 33 global RFHC uchar 832 34 global RFHD ulong 4 35 36 note ---- lane map, folds, transitions (contract 1.2) ---- 37 38 note one lane step: v < 2^wl, c < 2^wl, shifts c < wl 39 fn rfop wl ulong op ulong c ulong v ulong to ulong 40 m = sub shl ulong 1 wl 1 41 if eq op 1 42 ret and add v c m 43 end 44 if eq op 2 45 ret and sub v c m 46 end 47 if eq op 3 48 ret and mul v c m 49 end 50 if eq op 4 51 ret and v c 52 end 53 if eq op 5 54 ret or v c 55 end 56 if eq op 6 57 ret xor v c 58 end 59 if eq op 7 60 ret and shl v c m 61 end 62 ret shr v c 63 end 64 65 fn rflane x ulong to ulong 66 wl = get RFP 2 67 k = get RFP 4 68 v = x 69 for j ulong k 70 o = get RFP add 5 mul j 2 71 c = get RFP add 6 mul j 2 72 v = rfop wl o c v 73 end 74 ret v 75 end 76 77 fn rfident f ulong to ulong 78 if or eq f 3 eq f 6 79 ret `18446744073709551615` 80 end 81 ret 0 82 end 83 84 fn rffold f ulong a ulong b ulong to ulong 85 if eq f 1 86 ret add a b 87 end 88 if eq f 2 89 ret xor a b 90 end 91 if eq f 3 92 if lt b a 93 ret b 94 end 95 ret a 96 end 97 if eq f 4 98 if gt b a 99 ret b 100 end 101 ret a 102 end 103 if eq f 5 104 ret or a b 105 end 106 ret and a b 107 end 108 109 note delta(s, a): t of the lowest-numbered rule with rule.s = s and lo <= a <= hi, else s 110 fn rfdelta s ulong a ulong to ulong 111 r = get RFP 5 112 for i ulong r 113 w = get RFP add 22 i 114 if eq and w 255 s 115 lo = and shr w 8 255 116 hi = and shr w 16 255 117 if and le lo a le a hi 118 ret shr w 24 119 end 120 end 121 end 122 ret s 123 end 124 125 fn rfagg to void 126 n = get RFN 0 127 f = get RFP 3 128 acc = rfident f 129 for i ulong n 130 e = rflane get RFX i 131 acc = rffold f acc e 132 end 133 put RFR 0 acc 134 put RFR 1 n 135 end 136 137 fn rffsm to void 138 n = get RFN 0 139 q = get RFP 4 140 sum = ulong 0 141 for t ulong n 142 q = rfdelta q get RFX t 143 sum = add sum get RFP add 6 q 144 end 145 put RFR 0 q 146 put RFR 1 sum 147 end 148 149 note the result of RFP over (RFN, RFX) into RFR 150 fn rffull to void 151 if eq get RFP 1 1 152 rfagg 153 ret 154 end 155 rffsm 156 end 157 158 fn rfshape to ulong 159 if eq get RFP 1 2 160 ret 1 161 end 162 s = ulong 0 163 m = ulong 65536 164 k = get RFP 4 165 for j ulong k 166 s = add s mul m get RFP add 5 mul j 2 167 m = mul m 16 168 end 169 b = add get RFP 2 mul 256 get RFP 3 170 ret add add b mul 4096 k s 171 end 172 173 note ---- program validation (contract 1.1), on the staging buffer RFQ ---- 174 175 fn rfvagg to int 176 wl = get RFQ 2 177 if and ne wl 8 ne wl 16 178 ret 2 179 end 180 f = get RFQ 3 181 if or lt f 1 gt f 6 182 ret 2 183 end 184 k = get RFQ 4 185 if or lt k 1 gt k 6 186 ret 2 187 end 188 lim = shl ulong 1 wl 189 for j ulong 6 190 o = get RFQ add 5 mul j 2 191 c = get RFQ add 6 mul j 2 192 if lt j k 193 if or lt o 1 gt o 8 194 ret 2 195 end 196 if ge c lim 197 ret 2 198 end 199 if and ge o 7 ge c wl 200 ret 2 201 end 202 else 203 if or ne o 0 ne c 0 204 ret 2 205 end 206 end 207 end 208 for i ulong 47 209 if ne get RFQ add i 17 0 210 ret 2 211 end 212 end 213 ret 0 214 end 215 216 note one FSM rule word, r < R: s < S, t < S, lo <= hi < A 217 fn rfvrule w ulong s ulong a ulong to bool 218 rs = and w 255 219 lo = and shr w 8 255 220 hi = and shr w 16 255 221 t = shr w 24 222 if or ge rs s ge t s 223 ret false 224 end 225 if or gt lo hi ge hi a 226 ret false 227 end 228 ret true 229 end 230 231 fn rfvfsm to int 232 s = get RFQ 2 233 a = get RFQ 3 234 if or lt s 2 gt s 16 235 ret 2 236 end 237 if or lt a 2 gt a 16 238 ret 2 239 end 240 if ge get RFQ 4 s 241 ret 2 242 end 243 r = get RFQ 5 244 if or lt r 1 gt r 24 245 ret 2 246 end 247 for i ulong 16 248 l = get RFQ add 6 i 249 if lt i s 250 if gt l 255 251 ret 2 252 end 253 else 254 if ne l 0 255 ret 2 256 end 257 end 258 end 259 for j ulong 24 260 w = get RFQ add 22 j 261 if lt j r 262 if not rfvrule w s a 263 ret 2 264 end 265 else 266 if ne w 0 267 ret 2 268 end 269 end 270 end 271 for k ulong 18 272 if ne get RFQ add k 46 0 273 ret 2 274 end 275 end 276 ret 0 277 end 278 279 note 0 valid, 2 invalid (RFQ) 280 fn rfvalid to int 281 if ne get RFQ 0 `3544411312749556050` 282 ret 2 283 end 284 fam = get RFQ 1 285 if eq fam 1 286 ret rfvagg 287 end 288 if eq fam 2 289 ret rfvfsm 290 end 291 ret 2 292 end 293 294 note value domain of a valid program: AGG 2^wl, FSM A 295 fn rfdomq to ulong 296 if eq get RFQ 1 1 297 ret shl ulong 1 get RFQ 2 298 end 299 ret get RFQ 3 300 end 301 302 fn rfdom to ulong 303 if eq get RFP 1 1 304 ret shl ulong 1 get RFP 2 305 end 306 ret get RFP 3 307 end 308 309 note ---- changes (contract 1.3) ---- 310 311 note validity of one change on a state of n values with domain d: 0 or 3 312 fn rfchk op ulong a ulong b ulong n ulong d ulong to ulong 313 if eq op 3 314 if or ge a n ge b d 315 ret 3 316 end 317 ret 0 318 end 319 if eq op 4 320 if or gt a n ge b d 321 ret 3 322 end 323 if ge n 4096 324 ret 3 325 end 326 ret 0 327 end 328 if eq op 5 329 if or ge a n ne b 0 330 ret 3 331 end 332 ret 0 333 end 334 if eq op 6 335 if or ge a n ge b n 336 ret 3 337 end 338 ret 0 339 end 340 ret 3 341 end 342 343 note apply one already validated change to RFX, RFN 344 fn rfdo op ulong a ulong b ulong to void 345 n = get RFN 0 346 if eq op 3 347 put RFX a b 348 ret 349 end 350 if eq op 4 351 i = n 352 while gt i a bound 4097 353 put RFX i get RFX sub i 1 354 i = sub i 1 355 end 356 put RFX a b 357 put RFN 0 add n 1 358 ret 359 end 360 if eq op 5 361 j = a 362 while lt add j 1 n bound 4097 363 put RFX j get RFX add j 1 364 j = add j 1 365 end 366 put RFN 0 sub n 1 367 ret 368 end 369 t = get RFX a 370 put RFX a get RFX b 371 put RFX b t 372 end 373 374 note BATCH payload at RFRQ[2..]: m, then m triples; p already checked against 1 + 3m 375 fn rfbatch to ulong 376 m = get RFRQ 2 377 if or lt m 1 gt m 1024 378 ret 3 379 end 380 d = rfdom 381 n = get RFN 0 382 for i ulong m 383 o = get RFRQ add 3 mul i 3 384 a = get RFRQ add 4 mul i 3 385 b = get RFRQ add 5 mul i 3 386 if ne rfchk o a b n d 0 387 ret 3 388 end 389 if eq o 4 390 n = add n 1 391 end 392 if eq o 5 393 n = sub n 1 394 end 395 end 396 for j ulong m 397 o2 = get RFRQ add 3 mul j 3 398 a2 = get RFRQ add 4 mul j 3 399 b2 = get RFRQ add 5 mul j 3 400 rfdo o2 a2 b2 401 end 402 ret 0 403 end 404 405 note ---- requests (contract 2) ---- 406 407 fn rfbegin p ulong to ulong 408 if lt p 65 409 ret 4 410 end 411 n = get RFRQ 66 412 if ne p add n 65 413 ret 4 414 end 415 if gt n 4096 416 ret 5 417 end 418 for i ulong 64 419 put RFQ i get RFRQ add i 2 420 end 421 if ne rfvalid 0 422 ret 2 423 end 424 d = rfdomq 425 for j ulong n 426 if ge get RFRQ add j 67 d 427 ret 3 428 end 429 end 430 for k ulong 64 431 put RFP k get RFQ k 432 end 433 for t ulong n 434 put RFX t get RFRQ add t 67 435 end 436 put RFN 0 n 437 put RFS 0 1 438 ret 0 439 end 440 441 fn rfprog to ulong 442 for i ulong 64 443 put RFQ i get RFRQ add i 2 444 end 445 if ne rfvalid 0 446 ret 2 447 end 448 d = rfdomq 449 n = get RFN 0 450 for j ulong n 451 if ge get RFX j d 452 ret 3 453 end 454 end 455 for k ulong 64 456 put RFP k get RFQ k 457 end 458 ret 0 459 end 460 461 fn rfquery to ulong 462 rffull 463 put RFRS 1 3 464 put RFRS 2 get RFR 0 465 put RFRS 3 get RFR 1 466 ret 0 467 end 468 469 note the expected payload length of op given the frame, or 7235 when it cannot match 470 fn rfplen op ulong p ulong to ulong 471 if or eq op 2 or eq op 9 eq op 10 472 ret 0 473 end 474 if or eq op 3 or eq op 4 eq op 6 475 ret 2 476 end 477 if eq op 5 478 ret 1 479 end 480 if eq op 8 481 ret 64 482 end 483 if eq op 7 484 if lt p 1 485 ret 7235 486 end 487 m = get RFRQ 2 488 if gt m 2411 489 ret 7235 490 end 491 ret add 1 mul 3 m 492 end 493 ret 7235 494 end 495 496 fn rfreq2 to ulong 497 op = get RFRQ 0 498 p = get RFRQ 1 499 if gt p 7234 500 ret 4 501 end 502 if or lt op 1 gt op 10 503 ret 4 504 end 505 if eq op 1 506 ret rfbegin p 507 end 508 if ne p rfplen op p 509 ret 4 510 end 511 if eq op 9 512 ret 0 513 end 514 if eq op 10 515 put RFS 0 0 516 ret 0 517 end 518 if eq get RFS 0 0 519 ret 6 520 end 521 if eq op 2 522 ret rfquery 523 end 524 if eq op 7 525 ret rfbatch 526 end 527 if eq op 8 528 ret rfprog 529 end 530 b = ulong 0 531 if ne op 5 532 b = get RFRQ 3 533 end 534 a = get RFRQ 2 535 if ne rfchk op a b get RFN 0 rfdom 0 536 ret 3 537 end 538 rfdo op a b 539 ret 0 540 end 541 542 fn rfreq to int 543 for i ulong 8 544 put RFRS i 0 545 end 546 st = rfreq2 547 put RFRS 0 st 548 ret int st 549 end 550 551 fn rfreset to void 552 put RFS 0 0 553 put RFN 0 0 554 end 555 556 note ---- SHA-256 through omsha (sha256 unit) ---- 557 558 fn rfbswap x ulong to ulong 559 r = ulong 0 560 v = x 561 for i ulong 8 562 r = or shl r 8 and v 255 563 v = shr v 8 564 end 565 ret r 566 end 567 568 fn rfhini slot ulong to void 569 c = new uchar 104 0 570 b = new uchar 4096 0 571 w = new ulong 64 0 572 b8 = new ulong 512 0 573 omsha c b 0 0 w b8 574 rfhst c slot 575 end 576 577 note context slot into c and back; RFHB[off..off+k) into b 578 fn rfhld c edit uchar 104 slot ulong to void 579 o = mul slot 104 580 for i ulong 104 581 put c i get RFHC add o i 582 end 583 end 584 585 fn rfhst c edit uchar 104 slot ulong to void 586 o = mul slot 104 587 for i ulong 104 588 put RFHC add o i get c i 589 end 590 end 591 592 fn rfhcp b edit uchar 4096 off ulong k ulong to void 593 for j ulong k 594 put b j get RFHB add off j 595 end 596 end 597 598 fn rfhabs slot ulong n ulong to void 599 c = new uchar 104 0 600 b = new uchar 4096 0 601 w = new ulong 64 0 602 b8 = new ulong 512 0 603 rfhld c slot 604 off = ulong 0 605 while lt off n bound 17 606 k = sub n off 607 if gt k 4096 608 k = 4096 609 end 610 rfhcp b off k 611 omsha c b k 1 w b8 612 off = add off k 613 end 614 rfhst c slot 615 end 616 617 fn rfhfin slot ulong to void 618 c = new uchar 104 0 619 b = new uchar 4096 0 620 w = new ulong 64 0 621 b8 = new ulong 512 0 622 rfhld c slot 623 omsha c b 0 2 w b8 624 for j ulong 4 625 put RFHD j rfbswap get w j 626 end 627 end 628 629 note program digest of RFP into RFPD (uses slot 7 and RFHB[0..512)) 630 fn rfpdig to void 631 for i ulong 64 632 x = get RFP i 633 for j ulong 8 634 put RFHB add mul i 8 j uchar and shr x mul j 8 255 635 end 636 end 637 rfhini 7 638 rfhabs 7 512 639 rfhfin 7 640 for k ulong 4 641 put RFPD k get RFHD k 642 end 643 end