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/omega-mv/blob/main/seed/helix/bft_healer.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / helix / bft_healer.om` 516 lines ยท 9342 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note seed/helix/bft_healer.om: Pure-Omega N = 3f + 1 Byzantine Fault-Tolerant Braid Controller, 3 note Automatic Quarantine & Cold-Regrowth Healer, Live Compiler Mitosis Evaluator, and 4 note Arboris Predator <-> Ascetic Real-Thermal Hot-Swap Controller. 5 note 6 note Mirrors seed/helix/proofs/HelixBFT.lean (generalized N = 3f + 1: N=4,f=1 and N=7,f=2): 7 note quorum N H0 ... H_{N-1} (1 <= N <= 7, f = (N-1)/3, threshold = N - f = 2f + 1) 8 note Exit 0: unanimous (N/N agree) 9 note Exit 100+mask: quorum (>= 2f+1) with 1..f faults; bit i in mask marks faulty strand i 10 note Exit 20: NO_QUORUM (> f Byzantine faults, fail-closed halt!) 11 note quorum H0 H1 H2 H3 (legacy 4-strand shorthand: exit 0, 10+fault, or 20) 12 note mitosis-eval INC_COST MONK_RC TRICK_RC CAND_COST 13 note Evaluates live Compiler Mitosis admission gate + real /sys/class/thermal sensor 14 note Exit 0: HARVESTED_INTO_BRAID, Exit 1: REJECTED (incumbent kept safe) 15 note mitosis 16 note Runs live Compiler Mitosis + real /sys/class/thermal Arboris Predator <-> Ascetic gate 17 note thermal 18 note Reads max /sys/class/thermal/thermal_zone0..7/temp (fallback 55C) and reports active mode 19 20 global bfDig uchar 1024 21 global bfBuf uchar 256 22 global bfThm uchar 64 23 global bfThSt ulong 2 24 25 text bfUse "usage: bft_healer quorum N H0..H_{N-1} | mitosis-eval INC MONK_RC TRICK_RC CAND | mitosis | thermal\n" 26 text bfUn1 "BFT_QUORUM status=UNANIMOUS n=" 27 text bfUn2 " f=" 28 text bfUn3 " votes=" 29 text bfSl "/" 30 text bfUn4 " faulty_mask=0 digest=" 31 text bfHl1 "BFT_QUORUM status=QUARANTINE_AND_REGROW n=" 32 text bfHl2 " faulty_mask=" 33 text bfDigS " quorum_digest=" 34 text bfNoQ1 "BFT_QUORUM status=NO_QUORUM_HALT n=" 35 text bfNoQ2 " votes_max=" 36 text bfNoQ3 " threshold=" 37 text bfNoQ4 " reason=faults_gt_f\n" 38 text bfLegUn "BFT_QUORUM status=UNANIMOUS votes=4/4 faulty=none digest=" 39 text bfLegHl "BFT_QUORUM status=QUARANTINE_AND_REGROW votes=3/4 faulty_strand=" 40 text bfLegNo "BFT_QUORUM status=NO_QUORUM_HALT votes_max=" 41 text bfLegN2 "/4 reason=f_ge_2_byzantine_faults\n" 42 text bfEvPre "MITOSIS_EVAL decision=" 43 text bfDecH "HARVESTED_INTO_BRAID" 44 text bfDecM "KILLED_BY_MONK" 45 text bfDecT "KILLED_BY_TRICKSTER" 46 text bfDecS "RETIRED_SLOWER" 47 text bfEvInc " inc=" 48 text bfEvCnd " cand=" 49 text bfEvChp " champion=" 50 text bfEvMrc " monk_rc=" 51 text bfEvTrc " trick_rc=" 52 text bfEvTmp " temp_c=" 53 text bfEvSns " sensor=" 54 text bfSnsLv "live" 55 text bfSnsFb "fallback" 56 text bfEvMod " mode=" 57 text bfModP "PREDATOR" 58 text bfModA "ASCETIC" 59 text bfThPfx "/sys/class/thermal/thermal_zone" 60 text bfThSfx "/temp" 61 text bfThOut "ARBORIS_THERMAL temp_c=" 62 text bfMitHdr "=== COMPILER MITOSIS + ARBORIS REAL-THERMAL PREDATOR <-> ASCETIC HOT-SWAP ===\n" 63 text bfMitOk "MITOSIS_AND_HOTSWAP PASS children_tested=5 harvested=2 killed=2 retired=1 hotswaps=4 semantic_drift=0\n" 64 text bfFail "MITOSIS_AND_HOTSWAP FAIL\n" 65 text bfNl "\n" 66 67 fn bfWrt s view uchar * to void 68 r = write 1 s 0 len s 69 end 70 71 fn bfNum v ulong to void 72 b = new uchar 24 0 73 p = ulong 24 74 x = v 75 while true bound 24 76 p = sub p 1 77 put b p uchar add 48 rem x 10 78 x = div x 10 79 if eq x 0 80 break 81 end 82 end 83 r = write 1 b p sub 24 p 84 end 85 86 fn bfParseU n ulong to ulong 87 if eq n 0 88 ret 0xffffffffffffffff 89 end 90 v = ulong 0 91 for i ulong n bound 32 92 c = ulong get bfBuf i 93 if or lt c 48 gt c 57 94 ret 0xffffffffffffffff 95 end 96 v = add mul v 10 sub c 48 97 end 98 ret v 99 end 100 101 fn bfReadArgU idx ulong to ulong 102 k = argread idx bfBuf 0 32 103 if le k 0 104 ret 0xffffffffffffffff 105 end 106 ret bfParseU ulong k 107 end 108 109 fn bfEqDig a ulong b ulong to bool 110 oa = mul a 64 111 ob = mul b 64 112 for i ulong 64 113 if ne get bfDig add oa i get bfDig add ob i 114 ret false 115 end 116 end 117 ret true 118 end 119 120 fn bfPrintDig idx ulong to void 121 o = mul idx 64 122 r = write 1 bfDig o 64 123 end 124 125 note Read real Linux thermal zones 0..7 (/sys/class/thermal/thermal_zoneK/temp). 126 note Stores bfThSt[0] = max temp in Celsius, bfThSt[1] = 1 if live sensor found else 0 (fallback 55C). 127 fn bfReadThermal to void 128 best = ulong 0 129 found = ulong 0 130 for z ulong 8 131 p = ulong 0 132 for i ulong len bfThPfx 133 put bfThm p get bfThPfx i 134 p = add p 1 135 end 136 put bfThm p uchar add 48 z 137 p = add p 1 138 for i ulong len bfThSfx 139 put bfThm p get bfThSfx i 140 p = add p 1 141 end 142 fd = fopen bfThm 0 p 0 0 143 if ge fd 0 144 k = read int fd bfBuf 0 32 145 rc = fclose int fd 146 if gt k 0 147 v = ulong 0 148 ok = false 149 for j ulong ulong k bound 32 150 ch = ulong get bfBuf j 151 if and ge ch 48 le ch 57 152 v = add mul v 10 sub ch 48 153 ok = true 154 else 155 break 156 end 157 end 158 if ok 159 tc = div v 1000 160 if and ge tc 1 le tc 150 161 if or eq found 0 gt tc best 162 best = tc 163 found = 1 164 end 165 end 166 end 167 end 168 end 169 end 170 if eq found 0 171 put bfThSt 0 55 172 put bfThSt 1 0 173 else 174 put bfThSt 0 best 175 put bfThSt 1 1 176 end 177 end 178 179 note Exact Mitosis admission gate mirroring HelixBFT.lean mitosisStep 180 fn bfMitosisStep incCost ulong monkOk bool trickOk bool childCost ulong to ulong 181 if and monkOk and trickOk lt childCost incCost 182 ret childCost 183 end 184 ret incCost 185 end 186 187 note Arboris Predator(0) <-> Ascetic(1) thermal/power policy 188 fn bfArbMode onWall bool tempC ulong to ulong 189 if or not onWall ge tempC 80 190 ret 1 191 end 192 ret 0 193 end 194 195 fn bfDoQuorumLegacy to int 196 for s ulong 4 197 k = argread add 2 s bfBuf 0 120 198 if lt k 64 199 bfWrt bfUse 200 ret 2 201 end 202 o = mul s 64 203 for i ulong 64 204 put bfDig add o i get bfBuf i 205 end 206 end 207 bestS = ulong 0 208 bestC = ulong 0 209 for s ulong 4 210 c = ulong 0 211 for t ulong 4 212 if bfEqDig s t 213 c = add c 1 214 end 215 end 216 if gt c bestC 217 bestC = c 218 bestS = s 219 end 220 end 221 if eq bestC 4 222 bfWrt bfLegUn 223 bfPrintDig bestS 224 bfWrt bfNl 225 ret 0 226 end 227 if eq bestC 3 228 fault = ulong 0 229 for t ulong 4 230 if not bfEqDig bestS t 231 fault = t 232 break 233 end 234 end 235 bfWrt bfLegHl 236 bfNum fault 237 bfWrt bfDigS 238 bfPrintDig bestS 239 bfWrt bfNl 240 ret int add 10 fault 241 end 242 bfWrt bfLegNo 243 bfNum bestC 244 bfWrt bfLegN2 245 ret 20 246 end 247 248 fn bfDoQuorum to int 249 if lt argcnt 4 250 bfWrt bfUse 251 ret 2 252 end 253 note Backward-compatible 4-arg form: bft_healer quorum H0 H1 H2 H3 254 if eq argcnt 6 255 k2 = argread 2 bfBuf 0 120 256 if eq k2 64 257 ret bfDoQuorumLegacy 258 end 259 end 260 n = bfReadArgU 2 261 if or eq n 0 gt n 7 262 bfWrt bfUse 263 ret 2 264 end 265 if ne ulong argcnt add 3 n 266 bfWrt bfUse 267 ret 2 268 end 269 for s ulong n bound 7 270 k = argread add 3 s bfBuf 0 120 271 if lt k 64 272 bfWrt bfUse 273 ret 2 274 end 275 o = mul s 64 276 for i ulong 64 277 put bfDig add o i get bfBuf i 278 end 279 end 280 f = div sub n 1 3 281 thresh = sub n f 282 bestS = ulong 0 283 bestC = ulong 0 284 for s ulong n bound 7 285 c = ulong 0 286 for t ulong n bound 7 287 if bfEqDig s t 288 c = add c 1 289 end 290 end 291 if gt c bestC 292 bestC = c 293 bestS = s 294 end 295 end 296 if eq bestC n 297 bfWrt bfUn1 298 bfNum n 299 bfWrt bfUn2 300 bfNum f 301 bfWrt bfUn3 302 bfNum bestC 303 bfWrt bfSl 304 bfNum n 305 bfWrt bfUn4 306 bfPrintDig bestS 307 bfWrt bfNl 308 ret 0 309 end 310 if ge bestC thresh 311 mask = ulong 0 312 for t ulong n bound 7 313 if not bfEqDig bestS t 314 mask = or mask shl ulong 1 t 315 end 316 end 317 bfWrt bfHl1 318 bfNum n 319 bfWrt bfUn2 320 bfNum f 321 bfWrt bfUn3 322 bfNum bestC 323 bfWrt bfSl 324 bfNum n 325 bfWrt bfHl2 326 bfNum mask 327 bfWrt bfDigS 328 bfPrintDig bestS 329 bfWrt bfNl 330 ret int add 100 mask 331 end 332 bfWrt bfNoQ1 333 bfNum n 334 bfWrt bfUn2 335 bfNum f 336 bfWrt bfNoQ2 337 bfNum bestC 338 bfWrt bfSl 339 bfNum n 340 bfWrt bfNoQ3 341 bfNum thresh 342 bfWrt bfNoQ4 343 ret 20 344 end 345 346 fn bfPrintEval inc ulong monkRc ulong trickRc ulong cand ulong champ ulong to int 347 bfReadThermal 348 tc = get bfThSt 0 349 live = get bfThSt 1 350 mode = bfArbMode true tc 351 bfWrt bfEvPre 352 retc = int 1 353 if ne monkRc 0 354 bfWrt bfDecM 355 else 356 if ne trickRc 0 357 bfWrt bfDecT 358 else 359 if lt cand inc 360 bfWrt bfDecH 361 retc = 0 362 else 363 bfWrt bfDecS 364 end 365 end 366 end 367 bfWrt bfEvInc 368 bfNum inc 369 bfWrt bfEvCnd 370 bfNum cand 371 bfWrt bfEvChp 372 bfNum champ 373 bfWrt bfEvMrc 374 bfNum monkRc 375 bfWrt bfEvTrc 376 bfNum trickRc 377 bfWrt bfEvTmp 378 bfNum tc 379 bfWrt bfEvSns 380 if ne live 0 381 bfWrt bfSnsLv 382 else 383 bfWrt bfSnsFb 384 end 385 bfWrt bfEvMod 386 if eq mode 0 387 bfWrt bfModP 388 else 389 bfWrt bfModA 390 end 391 bfWrt bfNl 392 ret retc 393 end 394 395 fn bfDoMitosisEval to int 396 if ne argcnt 6 397 bfWrt bfUse 398 ret 2 399 end 400 inc = bfReadArgU 2 401 monkRc = bfReadArgU 3 402 trickRc = bfReadArgU 4 403 cand = bfReadArgU 5 404 if or or eq inc 0xffffffffffffffff eq monkRc 0xffffffffffffffff or eq trickRc 0xffffffffffffffff eq cand 0xffffffffffffffff 405 bfWrt bfUse 406 ret 2 407 end 408 champ = bfMitosisStep inc eq monkRc 0 eq trickRc 0 cand 409 ret bfPrintEval inc monkRc trickRc cand champ 410 end 411 412 fn bfDoThermal to int 413 bfReadThermal 414 tc = get bfThSt 0 415 live = get bfThSt 1 416 mode = bfArbMode true tc 417 bfWrt bfThOut 418 bfNum tc 419 bfWrt bfEvSns 420 if ne live 0 421 bfWrt bfSnsLv 422 else 423 bfWrt bfSnsFb 424 end 425 bfWrt bfEvMod 426 if eq mode 0 427 bfWrt bfModP 428 else 429 bfWrt bfModA 430 end 431 bfWrt bfNl 432 ret 0 433 end 434 435 fn bfDoMitosis to int 436 bfWrt bfMitHdr 437 champ = ulong 15184 438 c = bfMitosisStep champ true true 14200 439 if ne c 14200 440 bfWrt bfFail 441 ret 1 442 end 443 r = bfPrintEval champ 0 0 14200 c 444 champ = c 445 c = bfMitosisStep champ false true 12000 446 if ne c 14200 447 bfWrt bfFail 448 ret 1 449 end 450 r = bfPrintEval champ 1 0 12000 c 451 c = bfMitosisStep champ true false 13100 452 if ne c 14200 453 bfWrt bfFail 454 ret 1 455 end 456 r = bfPrintEval champ 0 1 13100 c 457 c = bfMitosisStep champ true true 15900 458 if ne c 14200 459 bfWrt bfFail 460 ret 1 461 end 462 r = bfPrintEval champ 0 0 15900 c 463 c = bfMitosisStep champ true true 13400 464 if ne c 13400 465 bfWrt bfFail 466 ret 1 467 end 468 r = bfPrintEval champ 0 0 13400 c 469 champ = c 470 bfReadThermal 471 tc = get bfThSt 0 472 if ne bfArbMode true add tc 85 1 473 bfWrt bfFail 474 ret 1 475 end 476 if ne bfArbMode false tc 1 477 bfWrt bfFail 478 ret 1 479 end 480 if ne bfArbMode true 52 0 481 bfWrt bfFail 482 ret 1 483 end 484 r = bfDoThermal 485 bfWrt bfMitOk 486 ret 0 487 end 488 489 fn main to int 490 if lt argcnt 2 491 bfWrt bfUse 492 ret 2 493 end 494 cl = argread 1 bfBuf 0 32 495 if lt cl 1 496 bfWrt bfUse 497 ret 2 498 end 499 c0 = ulong get bfBuf 0 500 if eq c0 113 501 ret bfDoQuorum 502 end 503 if eq c0 116 504 ret bfDoThermal 505 end 506 if eq c0 109 507 if ge cl 12 508 if eq get bfBuf 7 45 509 ret bfDoMitosisEval 510 end 511 end 512 ret bfDoMitosis 513 end 514 bfWrt bfUse 515 ret 2 516 end