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 / seed / qualification / security673 / game / evidence / native-v3 / solve2.attempt1.om
| 1 | note SC1-G transport only. No transition or invariant code is shared. |
| 2 | global wire uchar 4096 |
| 3 | global pos ulong 1 |
| 4 | global avail ulong 1 |
| 5 | global digits uchar 32 |
| 6 | global samples ulong 101 |
| 7 | text nl "\n" |
| 8 | text sp " " |
| 9 | text tags "construct_ns=\nsolve_ns=\ncheck_ns=\nstates=\nedges=\nwinning=\nrounds=\narray_bytes=\nPASS SC1-G-v3 finite model only\nFAIL QUANTIFIER_CLOSURE\nFAIL OMITTED_DISTURBANCE_CLOSURE\nFAIL FRESHNESS_AT_RENAME\nFAIL UNCERTAIN_REFUND\nFAIL SELECTED_NOT_SAFE\nFAIL EARLY_STOP_CLOSURE\nFAIL CERTIFICATE\nPASS certified serial witnesses empty-set costs\nFAIL PAIRED_PRODUCT\ndistinct_hidden_states=\ndistinct_hidden_edges=\nsample_ns=\np50_ns=\np95_ns=\np99_ns=\nidentical_zero_states=\nidentical_zero_edges=\nWITNESS source action disturbance raw effective\nFAIL TRANSITION_CONFORMANCE\nFAIL CLOSURE\nFAIL SOURCE_INVARIANT\nFAIL DISABLED_ACTION\nFAIL EXACTNESS\nFAIL SELECTION_COST\n" |
| 10 | fn label id uint to void |
| 11 | p = ulong 0 |
| 12 | n = uint 0 |
| 13 | for j ulong len tags |
| 14 | if eq get tags j 10 |
| 15 | if eq n id |
| 16 | r = write 2 tags p add sub j p 1 |
| 17 | if ne r long add sub j p 1 |
| 18 | exit 90 |
| 19 | end |
| 20 | ret |
| 21 | end |
| 22 | n = add n 1 |
| 23 | p = add j 1 |
| 24 | end |
| 25 | end |
| 26 | exit 90 |
| 27 | end |
| 28 | fn number n ulong to void |
| 29 | p = ulong 0 |
| 30 | while ge n 10 bound 32 |
| 31 | put digits p uchar add rem n 10 48 |
| 32 | n = div n 10 |
| 33 | p = add p 1 |
| 34 | end |
| 35 | put digits p uchar add n 48 |
| 36 | p = add p 1 |
| 37 | for j ulong p |
| 38 | r = write 2 digits sub sub p j 1 1 |
| 39 | if ne r 1 |
| 40 | exit 90 |
| 41 | end |
| 42 | end |
| 43 | r = write 2 nl 0 1 |
| 44 | if ne r 1 |
| 45 | exit 90 |
| 46 | end |
| 47 | end |
| 48 | fn mode to uint |
| 49 | if eq argcnt 1 |
| 50 | ret 0 |
| 51 | end |
| 52 | if ne argcnt 2 |
| 53 | exit 90 |
| 54 | end |
| 55 | if ne argread 1 wire 0 1 1 |
| 56 | exit 90 |
| 57 | end |
| 58 | m = get wire 0 |
| 59 | if or lt m 48 gt m 56 |
| 60 | exit 90 |
| 61 | end |
| 62 | ret sub uint m 48 |
| 63 | end |
| 64 | fn flush to void |
| 65 | n = get pos 0 |
| 66 | if ne write 1 wire 0 n long n |
| 67 | exit 90 |
| 68 | end |
| 69 | put pos 0 0 |
| 70 | end |
| 71 | fn sendword x uint to void |
| 72 | for i ulong 4 |
| 73 | p = get pos 0 |
| 74 | put wire p uchar and shr x mul uint i 8 255 |
| 75 | put pos 0 add p 1 |
| 76 | if eq get pos 0 4096 |
| 77 | flush |
| 78 | end |
| 79 | end |
| 80 | end |
| 81 | fn recvword to uint |
| 82 | x = uint 0 |
| 83 | for i ulong 4 |
| 84 | if eq get pos 0 get avail 0 |
| 85 | n = read 0 wire 0 len wire |
| 86 | if le n 0 |
| 87 | exit 90 |
| 88 | end |
| 89 | put avail 0 ulong n |
| 90 | put pos 0 0 |
| 91 | end |
| 92 | p = get pos 0 |
| 93 | x = or x shl uint get wire p mul uint i 8 |
| 94 | put pos 0 add p 1 |
| 95 | end |
| 96 | ret x |
| 97 | end |
| 98 | fn endinput to void |
| 99 | if ne get pos 0 get avail 0 |
| 100 | exit 90 |
| 101 | end |
| 102 | if ne read 0 wire 0 len wire 0 |
| 103 | exit 90 |
| 104 | end |
| 105 | end |
| 106 | fn percentiles to void |
| 107 | for i ulong 101 |
| 108 | label 20 |
| 109 | number get samples i |
| 110 | end |
| 111 | for i ulong 101 |
| 112 | for j ulong 100 |
| 113 | if gt get samples j get samples add j 1 |
| 114 | t = get samples j |
| 115 | put samples j get samples add j 1 |
| 116 | put samples add j 1 t |
| 117 | end |
| 118 | end |
| 119 | end |
| 120 | label 21 |
| 121 | number get samples 50 |
| 122 | label 22 |
| 123 | number get samples 95 |
| 124 | label 23 |
| 125 | number get samples 99 |
| 126 | end |
| 127 | note SC1-G-v3 source-fixed experiment 2; no runtime fault selector. |
| 128 | fn fault to uint |
| 129 | ret 2 |
| 130 | end |
| 131 | note SC1-G-v3 synchronous greatest fixed point over monitored raw transitions. |
| 132 | global moves uint 2593 |
| 133 | global cert uint 2593 |
| 134 | global chosen uint 2593 |
| 135 | global edges uint 420066 |
| 136 | global keep uchar 2593 |
| 137 | global next uchar 2593 |
| 138 | global mut uint 1 |
| 139 | global totals ulong 4 |
| 140 | fn phase s uint c uint to uint |
| 141 | if eq c 0 |
| 142 | ret rem s 18 |
| 143 | end |
| 144 | ret rem div s 18 18 |
| 145 | end |
| 146 | fn replace s uint c uint p uint to uint |
| 147 | old = phase s c |
| 148 | if eq c 0 |
| 149 | ret add sub s old p |
| 150 | end |
| 151 | ret add sub s mul old 18 mul p 18 |
| 152 | end |
| 153 | fn epoch s uint to uint |
| 154 | ret rem div s 324 2 |
| 155 | end |
| 156 | fn object s uint to uint |
| 157 | ret rem div s 648 2 |
| 158 | end |
| 159 | fn charge p uint to uint |
| 160 | if lt p 2 |
| 161 | ret 0 |
| 162 | end |
| 163 | if and ge p 12 le p 14 |
| 164 | ret 1 |
| 165 | end |
| 166 | ret 2 |
| 167 | end |
| 168 | fn invariant s uint to bool |
| 169 | if ge s 2592 |
| 170 | ret false |
| 171 | end |
| 172 | a = phase s 0 |
| 173 | b = phase s 1 |
| 174 | if or eq a 17 eq b 17 |
| 175 | ret false |
| 176 | end |
| 177 | if gt add charge a charge b 3 |
| 178 | ret false |
| 179 | end |
| 180 | if or or eq a 15 eq a 16 or eq b 15 eq b 16 |
| 181 | ret eq rem div s 324 4 0 |
| 182 | end |
| 183 | ret true |
| 184 | end |
| 185 | fn enabled s uint u uint to bool |
| 186 | if not invariant s |
| 187 | ret false |
| 188 | end |
| 189 | if ge s 1296 |
| 190 | ret eq u 1 |
| 191 | end |
| 192 | if eq u 1 |
| 193 | ret false |
| 194 | end |
| 195 | if eq u 0 |
| 196 | ret and or eq phase s 0 0 eq phase s 0 14 or eq phase s 1 0 eq phase s 1 14 |
| 197 | end |
| 198 | c = div sub u 2 8 |
| 199 | k = rem sub u 2 8 |
| 200 | p = phase s c |
| 201 | if eq k 0 |
| 202 | ret and eq p 1 le add charge phase s 0 charge phase s 1 1 |
| 203 | end |
| 204 | if eq k 1 |
| 205 | ret and ge p 1 le p 10 |
| 206 | end |
| 207 | if eq k 2 |
| 208 | ret eq p 2 |
| 209 | end |
| 210 | if or eq k 3 eq k 7 |
| 211 | if and ge p 3 le p 6 |
| 212 | if eq k 7 |
| 213 | ret eq rem div s 324 4 0 |
| 214 | end |
| 215 | ret true |
| 216 | end |
| 217 | ret and eq k 7 eq p 16 |
| 218 | end |
| 219 | if eq k 4 |
| 220 | ret or and ge p 7 le p 10 eq p 15 |
| 221 | end |
| 222 | if eq k 5 |
| 223 | ret or eq p 11 eq p 15 |
| 224 | end |
| 225 | ret or eq p 12 eq p 13 |
| 226 | end |
| 227 | fn environment s uint d uint to uint |
| 228 | if eq d 1 |
| 229 | if eq phase s 0 0 |
| 230 | ret add s 1 |
| 231 | end |
| 232 | end |
| 233 | if eq d 2 |
| 234 | if eq phase s 1 0 |
| 235 | ret add s 18 |
| 236 | end |
| 237 | end |
| 238 | if eq d 3 |
| 239 | ret add s mul sub uint 1 epoch s 324 |
| 240 | end |
| 241 | if eq d 4 |
| 242 | ret add s mul sub uint 1 object s 648 |
| 243 | end |
| 244 | ret s |
| 245 | end |
| 246 | fn clean p uint to uint |
| 247 | if and ge p 2 le p 10 |
| 248 | ret 0 |
| 249 | end |
| 250 | if eq p 11 |
| 251 | ret 12 |
| 252 | end |
| 253 | ret p |
| 254 | end |
| 255 | fn recover s uint to uint |
| 256 | if or ge phase s 0 15 ge phase s 1 15 |
| 257 | ret 2592 |
| 258 | end |
| 259 | s = replace s 0 clean phase s 0 |
| 260 | s = replace s 1 clean phase s 1 |
| 261 | ret rem s 1296 |
| 262 | end |
| 263 | fn split s uint c uint k uint d uint to uint |
| 264 | p = phase s c |
| 265 | if eq d 7 |
| 266 | ret s |
| 267 | end |
| 268 | if eq d 5 |
| 269 | ret add replace s c 0 1296 |
| 270 | end |
| 271 | if eq p 15 |
| 272 | if or and eq k 4 eq d 4 and eq k 5 eq d 3 |
| 273 | ret 2592 |
| 274 | end |
| 275 | if or eq d 3 eq d 4 |
| 276 | ret environment replace s c 0 d |
| 277 | end |
| 278 | if eq d 6 |
| 279 | ret s |
| 280 | end |
| 281 | ret environment replace s c 14 d |
| 282 | end |
| 283 | if or eq d 3 eq d 4 |
| 284 | ret environment replace s c 0 d |
| 285 | end |
| 286 | ret environment replace s c 15 d |
| 287 | end |
| 288 | fn client s uint c uint k uint d uint to uint |
| 289 | p = phase s c |
| 290 | if eq k 0 |
| 291 | ret replace s c 2 |
| 292 | end |
| 293 | if eq k 1 |
| 294 | ret replace s c 0 |
| 295 | end |
| 296 | if eq k 2 |
| 297 | p = add uint 3 add epoch s mul object s 2 |
| 298 | ret replace s c p |
| 299 | end |
| 300 | if eq k 3 |
| 301 | if eq d 6 |
| 302 | ret s |
| 303 | end |
| 304 | ret replace s c add p 4 |
| 305 | end |
| 306 | if eq k 4 |
| 307 | tag = sub p 7 |
| 308 | if ne get mut 0 3 |
| 309 | if ne tag rem div s 324 4 |
| 310 | ret s |
| 311 | end |
| 312 | end |
| 313 | ret replace s c 11 |
| 314 | end |
| 315 | if eq k 5 |
| 316 | if eq d 6 |
| 317 | if eq get mut 0 4 |
| 318 | ret replace s c 17 |
| 319 | end |
| 320 | ret s |
| 321 | end |
| 322 | if eq d 8 |
| 323 | ret replace s c 13 |
| 324 | end |
| 325 | ret replace s c 12 |
| 326 | end |
| 327 | if eq k 6 |
| 328 | if eq d 8 |
| 329 | ret replace s c 13 |
| 330 | end |
| 331 | ret replace s c 14 |
| 332 | end |
| 333 | if ne rem div s 324 4 0 |
| 334 | ret s |
| 335 | end |
| 336 | ret replace s c 16 |
| 337 | end |
| 338 | fn step s uint u uint d uint to uint |
| 339 | if not enabled s u |
| 340 | ret 2592 |
| 341 | end |
| 342 | if ge u 2 |
| 343 | c = div sub u 2 8 |
| 344 | p = phase s c |
| 345 | if or eq p 15 eq p 16 |
| 346 | if lt s 1296 |
| 347 | ret split s c rem sub u 2 8 d |
| 348 | end |
| 349 | end |
| 350 | end |
| 351 | if eq d 5 |
| 352 | ret add rem s 1296 1296 |
| 353 | end |
| 354 | if eq d 7 |
| 355 | ret s |
| 356 | end |
| 357 | s = environment s d |
| 358 | if eq u 0 |
| 359 | ret s |
| 360 | end |
| 361 | if eq u 1 |
| 362 | ret recover s |
| 363 | end |
| 364 | ret client s div sub u 2 8 rem sub u 2 8 d |
| 365 | end |
| 366 | fn index s uint u uint d uint to uint |
| 367 | ret add mul add mul s 18 u 9 d |
| 368 | end |
| 369 | fn monitored s uint u uint d uint raw uint to uint |
| 370 | if or lt u 2 ge raw 2592 |
| 371 | ret raw |
| 372 | end |
| 373 | c = div sub u 2 8 |
| 374 | p = phase s c |
| 375 | q = phase raw c |
| 376 | if and eq p 11 eq q 17 |
| 377 | ret 2592 |
| 378 | end |
| 379 | if and eq rem sub u 2 8 4 eq q 11 |
| 380 | if and ge p 7 le p 10 |
| 381 | now = environment s d |
| 382 | if ne sub p 7 rem div now 324 4 |
| 383 | ret 2592 |
| 384 | end |
| 385 | end |
| 386 | end |
| 387 | ret raw |
| 388 | end |
| 389 | fn destination s uint u uint d uint to uint |
| 390 | ret monitored s u d get edges index s u d |
| 391 | end |
| 392 | fn construct to void |
| 393 | for i uint 4 |
| 394 | put totals i 0 |
| 395 | end |
| 396 | for s uint 2593 |
| 397 | put keep s 0 |
| 398 | if invariant s |
| 399 | put keep s 1 |
| 400 | end |
| 401 | m = uint 0 |
| 402 | for u uint 18 |
| 403 | if enabled s u |
| 404 | m = or m shl uint 1 u |
| 405 | for d uint 9 |
| 406 | put edges index s u d step s u d |
| 407 | put totals 0 add get totals 0 1 |
| 408 | end |
| 409 | end |
| 410 | end |
| 411 | put moves s m |
| 412 | end |
| 413 | end |
| 414 | fn safe s uint u uint to bool |
| 415 | if eq and get moves s shl uint 1 u 0 |
| 416 | ret false |
| 417 | end |
| 418 | for d uint 9 |
| 419 | if not and eq get mut 0 2 eq d 4 |
| 420 | if eq get keep destination s u d 0 |
| 421 | ret false |
| 422 | end |
| 423 | end |
| 424 | end |
| 425 | ret true |
| 426 | end |
| 427 | fn existsaction s uint to bool |
| 428 | for u uint 18 |
| 429 | if safe s u |
| 430 | ret true |
| 431 | end |
| 432 | end |
| 433 | ret false |
| 434 | end |
| 435 | fn swapped s uint to bool |
| 436 | for d uint 9 |
| 437 | found = false |
| 438 | for u uint 18 |
| 439 | if ne and get moves s shl uint 1 u 0 |
| 440 | if ne get keep destination s u d 0 |
| 441 | found = true |
| 442 | end |
| 443 | end |
| 444 | end |
| 445 | if not found |
| 446 | ret false |
| 447 | end |
| 448 | end |
| 449 | ret true |
| 450 | end |
| 451 | fn solve to void |
| 452 | changed = true |
| 453 | while changed bound 2594 |
| 454 | changed = false |
| 455 | put totals 1 add get totals 1 1 |
| 456 | for s uint 2593 |
| 457 | v = false |
| 458 | if ne get keep s 0 |
| 459 | if eq get mut 0 1 |
| 460 | v = swapped s |
| 461 | else |
| 462 | v = existsaction s |
| 463 | end |
| 464 | end |
| 465 | put next s 0 |
| 466 | if v |
| 467 | put next s 1 |
| 468 | end |
| 469 | if ne get next s get keep s |
| 470 | changed = true |
| 471 | end |
| 472 | end |
| 473 | for s uint 2593 |
| 474 | put keep s get next s |
| 475 | end |
| 476 | if eq get mut 0 6 |
| 477 | ret |
| 478 | end |
| 479 | end |
| 480 | end |
| 481 | fn certificate to void |
| 482 | for s uint 2593 |
| 483 | m = uint 0 |
| 484 | if ne get keep s 0 |
| 485 | put totals 2 add get totals 2 1 |
| 486 | for u uint 18 |
| 487 | if safe s u |
| 488 | m = or m shl uint 1 u |
| 489 | end |
| 490 | end |
| 491 | if or eq get mut 0 1 eq get mut 0 6 |
| 492 | if eq m 0 |
| 493 | m = get moves s |
| 494 | end |
| 495 | end |
| 496 | end |
| 497 | put cert s m |
| 498 | end |
| 499 | end |
| 500 | fn select s uint identity uint to uint |
| 501 | if ne identity 1 |
| 502 | ret 18 |
| 503 | end |
| 504 | m = get cert s |
| 505 | if eq m 0 |
| 506 | ret 18 |
| 507 | end |
| 508 | if eq get mut 0 5 |
| 509 | m = get moves s |
| 510 | end |
| 511 | best = uint 18 |
| 512 | price = uint 99 |
| 513 | for u uint 18 |
| 514 | if ne and m shl uint 1 u 0 |
| 515 | p = uint 2 |
| 516 | if lt u 2 |
| 517 | p = 1 |
| 518 | else |
| 519 | k = rem sub u 2 8 |
| 520 | if eq k 7 |
| 521 | p = 0 |
| 522 | end |
| 523 | if eq k 1 |
| 524 | p = 4 |
| 525 | end |
| 526 | end |
| 527 | if lt p price |
| 528 | price = p |
| 529 | best = u |
| 530 | end |
| 531 | end |
| 532 | end |
| 533 | ret best |
| 534 | end |
| 535 | fn selections to void |
| 536 | for s uint 2593 |
| 537 | put chosen s select s 1 |
| 538 | end |
| 539 | end |
| 540 | fn output to void |
| 541 | sendword 1396912455 |
| 542 | sendword 3 |
| 543 | sendword 2593 |
| 544 | sendword get mut 0 |
| 545 | for s uint 2593 |
| 546 | sendword get moves s |
| 547 | sendword get cert s |
| 548 | sendword get chosen s |
| 549 | for u uint 18 |
| 550 | if ne and get moves s shl uint 1 u 0 |
| 551 | for d uint 9 |
| 552 | sendword get edges index s u d |
| 553 | end |
| 554 | end |
| 555 | end |
| 556 | end |
| 557 | flush |
| 558 | end |
| 559 | fn benchmark to void |
| 560 | if ne get mut 0 0 |
| 561 | exit 90 |
| 562 | end |
| 563 | for i ulong 101 |
| 564 | start = monons |
| 565 | construct |
| 566 | solve |
| 567 | certificate |
| 568 | selections |
| 569 | put samples i ulong sub monons start |
| 570 | end |
| 571 | percentiles |
| 572 | end |
| 573 | fn main to int |
| 574 | put mut 0 fault |
| 575 | m = mode |
| 576 | if eq m 7 |
| 577 | benchmark |
| 578 | output |
| 579 | ret 0 |
| 580 | end |
| 581 | if or ne m 0 gt get mut 0 6 |
| 582 | ret 90 |
| 583 | end |
| 584 | start = monons |
| 585 | construct |
| 586 | label 0 |
| 587 | number ulong sub monons start |
| 588 | start = monons |
| 589 | solve |
| 590 | certificate |
| 591 | selections |
| 592 | label 1 |
| 593 | number ulong sub monons start |
| 594 | label 3 |
| 595 | number 2593 |
| 596 | label 4 |
| 597 | number get totals 0 |
| 598 | label 5 |
| 599 | number get totals 2 |
| 600 | label 6 |
| 601 | number get totals 1 |
| 602 | label 7 |
| 603 | number 1721554 |
| 604 | output |
| 605 | ret 0 |
| 606 | end |