interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-train / native / btwave / gate.om

1283 lines · 22989 bytes Raw Blame History
1note SPDX-License-Identifier: AGPL-3.0-only
2note BTWAVE-P0: Pure Seeded OM-2 Gate & Mutant Harness (native/btwave/gate.om).
3note Concatenated after native/btwave/trit.om (reusing FIPS 180-4 SHA-256 primitives)
4note and compiled with pinned omc:
5note T=$(mktemp -d)
6note cat native/btwave/trit.om native/btwave/gate.om | "$OMC" > "$T/gate"
7note chmod +x "$T/gate"
8note cp -r evidence/BTWAVE-P0 "$T/ev"
9note "$T/gate" "$OMC" "$T/ev"; rc=$?
10note rm -rf "$T"
11note (exit "$rc")
12note Zero shell, Python, C, C++, or Rust implementation code.
13
14global Gomc uchar 512
15global Gomclen ulong 1
16global Gout uchar 512
17global Goutlen ulong 1
18
19global Gsrc uchar 131072
20global Gsrclen ulong 1
21global Gmut uchar 131072
22global Gmutlen ulong 1
23global Gexp uchar 65536
24global Gexplen ulong 1
25global Gfile uchar 2097152
26global Gfilelen ulong 1
27global Gtsv uchar 131072
28global Gtsvlen ulong 1
29
30global Gtin uchar 128
31global Gtinlen ulong 1
32global Gtbin uchar 128
33global Gtbinlen ulong 1
34global Gtout uchar 128
35global Gtoutlen ulong 1
36
37global Gpkt uchar 4096
38global Gpath uchar 1024
39
40global Gbsha1 uchar 64
41global Gbsha2 uchar 64
42global Gssha uchar 64
43global Gmsha uchar 64
44global Gosha uchar 64
45
46text Sdevnull "/dev/null"
47text Sf1 "native/btwave/trit.om"
48text Sf2 "native/btwave/ledger.om"
49text Sf3 "native/btwave/wave_ipc.om"
50text Sf4 "native/btwave/main.om"
51text Sexpf "/expected-trace.out"
52text Sipcf "/ipc.stdout"
53text Srecf "/receipt.tsv"
54text Stmpin "/tmp/btwave_g_in_"
55text Stmpbin "/tmp/btwave_g_bin_"
56text Stmpout "/tmp/btwave_g_out_"
57
58text PinOmc "f4fa7951816bbd09c5eaaae6692852a70c3c305164b365027c5b683dec7d63e9"
59text PinTrace "b0c6399a7ae894148e8e1678a272add68385bdf67d6221044ded82216fb73575"
60text PinEmpty "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
61text SipcPref "IPC PASS coreA=16 coreB=17 rounds=8 contrib=240 extract=180 odraft_refused=-10 elapsed_ns="
62
63text Hc1 "case"
64text Hc2 "build"
65text Hc3 "source_sha256"
66text Hc4 "compile_rc"
67text Hc5 "binary_sha256"
68text Hc6 "run_exit"
69text Hc7 "stdout_sha256"
70text Hc8 "verdict"
71
72text Tdash "-"
73text Torig "original"
74text Tself "selftest"
75text Ttrace "trace"
76text Tipc "ipc"
77text Tusage "usage"
78text Tcomp "compile"
79text Tovfb "overflow-backstop"
80text Tovfp "ovf-probe"
81text Ttrapt "trap-trit"
82text Ttrapd "trap-dup"
83text Ttrapr "trap-req"
84text Tbadarg "unknown"
85text Textra "extra"
86
87text Tpass "PASS"
88text Tscaught "SELFTEST_CAUGHT"
89text Tsmiss "SELFTEST_MISSED"
90text Tokilled "ORACLE_KILLED"
91text Ttrap1 "TRAP1"
92text Ttrap9 "TRAP9"
93text Ttrap10 "TRAP10"
94text Tcref7 "COMPILE_REFUSED_7"
95
96text Tccor "comparator-corrupt-trace"
97text Tcanone "cli-arg-none"
98text Tcabad "cli-arg-bad"
99text Tcatwo "cli-arg-two"
100text Tptrit "probe-trap-trit"
101text Tpdup "probe-trap-dup"
102text Tpreq "probe-trap-req"
103text Tpovf "probe-ovf-guarded"
104
105text MsgUsage "BTWAVE FAIL usage: btwave-gate <omc_path> <outdir>\n"
106text MsgNotRun "BTWAVE NOT_RUN omc sha256 does not match pinned seed/out/omc\n"
107text MsgFail "BTWAVE FAIL gate check failed at step "
108text MsgPass "BTWAVE PASS mutants_killed=23/23 type_swaps_refused=4/4 trace_sha256=b0c6399a7ae894148e8e1678a272add68385bdf67d6221044ded82216fb73575\n"
109
110text M01id "m01-guard-opcode"
111text M01t "if and ne op 1 ne op 2"
112text M01r "if false"
113
114text M02id "m02-guard-epoch"
115text M02t "if ne ulong reqe add get Lstate 0 1"
116text M02r "if false"
117
118text M03id "m03-guard-give-work"
119text M03t "if or or eq worku 0 gt worku WMAX ne takeu 0"
120text M03r "if false"
121
122text M04id "m04-guard-h16-tie"
123text M04t "decs = h16dec build_rx sym mode"
124text M04r "decs = long sym"
125
126text M05id "m05-guard-active-power"
127text M05t "if ne t32pow jw 32"
128text M05r "if false"
129
130text M06id "m06-guard-scale-zero"
131text M06t "if or eq sc 0 or lt sc neg VMAX gt sc VMAX"
132text M06r "if false"
133
134text M07id "m07-guard-sha256-rcpt"
135text M07t "if not rcpt_eq expr rxr"
136text M07r "if false"
137
138text M08id "m08-guard-take-bounds"
139text M08t "if or or eq takeu 0 gt takeu WMAX ne worku 0"
140text M08r "if false"
141
142text M09id "m09-guard-give-first"
143text M09t "if not cred_pos curc"
144text M09r "if false"
145
146text M10id "m10-guard-reciprocity"
147text M10t "ret le add open g open req open c"
148text M10r "ret true"
149
150text M11id "m11-guard-chain-anchor"
151text M11t "anc = xor anc 1"
152text M11r "anc = anc"
153
154text M12id "m12-trit-neg-ident"
155text M12t "ret rotr a 32"
156text M12r "ret a"
157
158text M13id "m13-trit-dot-sum"
159text M13t "ret sub pp nn"
160text M13r "ret add pp nn"
161
162text M14id "m14-bt6-dark-bias"
163text M14t "z = ulong add u 364"
164text M14r "z = ulong add u 365"
165
166text M15id "m15-hc3-14of16-drop"
167text M15t "if or lt u -7 gt u 8"
168text M15r "if or lt u -6 gt u 7"
169
170text M16id "m16-h16-allow-4flip-tie"
171text M16t "if and le bestd 3 eq ties 1"
172text M16r "if le bestd 4"
173
174text M17id "m17-mutate-before-verdict"
175text M17t "curg = GrantJmk get Lstate 2"
176text M17r "put Lstate 2 add get Lstate 2 takeu|curg = GrantJmk sub get Lstate 2 takeu"
177
178text M18id "m18-trap-trit-overlap"
179text M18t "n = or shr as 32 and as M32"
180text M18r "n = or p shr as 32"
181
182text M19id "m19-trap-wavedup-holds"
183text M19t "ret WaveDupmk or shl u 32 u"
184text M19r "ret WaveDupmk or shl u 32 xor u 1"
185
186text M20id "m20-trap-bt6-requires"
187text M20t "u = sub long idx 364"
188text M20r "u = sub long idx 363"
189
190text M21id "m21-vmax-ceiling-blowup"
191text M21t "const VMAX long 65536"
192text M21r "const VMAX long 9000000000000000000"
193
194text M22id "m22-coordinated-selftest-blind"
195text M22t "rm = rem add mul mulk i addk 3"
196text M22r "rm = rem add mul mulk i add addk 1 3"
197
198text M23id "m23-ipc-peer-wrong-job"
199text M23t "decs = h16dec rxw"
200text M23r "decs = xor h16dec rxw 1"
201text Tipcref "IPC_REFUSED_65"
202
203text X1id "x1-swap-credit-for-grant"
204text X1t "if not recip_ok curc curg reqg"
205text X1r "if not recip_ok curc curc reqg"
206
207text X2id "x2-swap-grant-for-credit"
208text X2t "if not recip_ok curc curg reqg"
209text X2r "if not recip_ok curg curg reqg"
210
211text X3id "x3-raw-ulong-as-trit32"
212text X3t "decs = h16dec build_rx sym mode"
213text X3r "decs = h16dec sym"
214
215text X4id "x4-swap-grant-as-wavedup"
216text X4t "if not wdup_chk wd uint and reqep 0xffff"
217text X4r "if not wdup_chk curg uint and reqep 0xffff"
218
219fn hex_nibble v uint to uchar
220if lt v 10
221ret uchar add 48 v
222end
223ret uchar add 87 v
224end
225
226fn read_src_byte kind ulong idx ulong to uchar
227if eq kind 0
228ret get Gfile idx
229end
230if eq kind 1
231ret get Gexp idx
232end
233if eq kind 2
234ret get Gsrc idx
235end
236ret get Gmut idx
237end
238
239fn sha256_gosha_kind kind ulong n ulong to void
240s = new uint 8 0
241w = new uint 64 0
242kt = new uint 64 0
243blk = new uchar 64 0
244pad = new uchar 128 0
245dg = new uchar 32 0
246wsiv s
247wskinit kt
248nb = shr n 6
249for b ulong nb
250base = shl b 6
251for j ulong 64 unroll
252put blk j read_src_byte kind add base j
253end
254wscomp s w kt view blk 0
255end
256remb = and n 63
257rbase = shl nb 6
258for i ulong remb
259put pad i read_src_byte kind add rbase i
260end
261wsfin s w kt pad n
262wsout dg s
263for i ulong 32 unroll
264bv = uint get dg i
265put Gosha mul i 2 hex_nibble and shr bv 4 15
266put Gosha add mul i 2 1 hex_nibble and bv 15
267end
268end
269
270fn save_bsha1 to void
271for i ulong 64 unroll
272put Gbsha1 i get Gbsha2 i
273end
274end
275
276fn save_bsha2 to void
277for i ulong 64 unroll
278put Gbsha2 i get Gosha i
279end
280end
281
282fn save_ssha to void
283for i ulong 64 unroll
284put Gssha i get Gosha i
285end
286end
287
288fn save_msha to void
289for i ulong 64 unroll
290put Gmsha i get Gosha i
291end
292end
293
294fn bsha_eq_1_2 to bool
295for i ulong 64
296if ne get Gbsha1 i get Gbsha2 i
297ret false
298end
299end
300ret true
301end
302
303fn msha_eq_ssha to bool
304for i ulong 64
305if ne get Gmsha i get Gssha i
306ret false
307end
308end
309ret true
310end
311
312fn gosha_eq_pin pin view uchar * to bool
313if ne len pin 64
314ret false
315end
316for i ulong 64
317if ne get Gosha i get pin i
318ret false
319end
320end
321ret true
322end
323
324fn gfile_eq_gexp to bool
325n = get Gfilelen 0
326if ne n get Gexplen 0
327ret false
328end
329for i ulong n
330if ne get Gfile i get Gexp i
331ret false
332end
333end
334ret true
335end
336
337fn gfile_has_pref pref view uchar * to bool
338n = get Gfilelen 0
339np = len pref
340if lt n np
341ret false
342end
343for i ulong np
344if ne get Gfile i get pref i
345ret false
346end
347end
348ret true
349end
350
351fn tsv_putc c uchar to void
352p = get Gtsvlen 0
353put Gtsv p c
354put Gtsvlen 0 add p 1
355end
356
357fn tsv_txt s view uchar * to void
358for i ulong len s
359tsv_putc get s i
360end
361end
362
363fn tsv_tab to void
364tsv_putc 9
365end
366
367fn tsv_nl to void
368tsv_putc 10
369end
370
371fn tsv_u64 v ulong to void
372dg = new uchar 24 0
373if eq v 0
374tsv_putc 48
375ret
376end
377k = ulong 0
378x = v
379while gt x 0 bound 24
380put dg k uchar add 48 and rem x 10 0xff
381x = div x 10
382k = add k 1
383end
384for i ulong k
385tsv_putc get dg sub sub k 1 i
386end
387end
388
389fn tsv_hdr to void
390tsv_txt Hc1
391tsv_tab
392tsv_txt Hc2
393tsv_tab
394tsv_txt Hc3
395tsv_tab
396tsv_txt Hc4
397tsv_tab
398tsv_txt Hc5
399tsv_tab
400tsv_txt Hc6
401tsv_tab
402tsv_txt Hc7
403tsv_tab
404tsv_txt Hc8
405tsv_nl
406end
407
408note ssel: 0=Gssha, 1=Gmsha, 2=Gosha
409fn tsv_head cid view uchar * bld view uchar * ssel ulong crc long to void
410tsv_txt cid
411tsv_tab
412tsv_txt bld
413tsv_tab
414for i ulong 64
415if eq ssel 0
416tsv_putc get Gssha i
417else
418if eq ssel 1
419tsv_putc get Gmsha i
420else
421tsv_putc get Gosha i
422end
423end
424end
425tsv_tab
426tsv_u64 ulong crc
427tsv_tab
428end
429
430note bsel: 0=dash, 1=Gbsha1, 2=Gbsha2; osel: 0=dash, 1=Gosha
431fn tsv_tail bsel ulong rexit long osel ulong verd view uchar * to void
432if eq bsel 0
433tsv_txt Tdash
434else
435for i ulong 64
436if eq bsel 1
437tsv_putc get Gbsha1 i
438else
439tsv_putc get Gbsha2 i
440end
441end
442end
443tsv_tab
444if lt rexit 0
445tsv_txt Tdash
446else
447tsv_u64 ulong rexit
448end
449tsv_tab
450if eq osel 0
451tsv_txt Tdash
452else
453for i ulong 64
454tsv_putc get Gosha i
455end
456end
457tsv_tab
458tsv_txt verd
459tsv_nl
460end
461
462fn write_txt fd int s view uchar * to long
463off = ulong 0
464n = len s
465while lt off n bound 65536
466nw = write fd s off sub n off
467if le nw 0
468ret -1
469end
470off = add off ulong nw
471end
472ret 0
473end
474
475fn write_tin use_mut bool to long
476fd = int fopen Gtin 0 get Gtinlen 0 577 420
477if lt fd 0
478ret -1
479end
480off = ulong 0
481n = get Gsrclen 0
482if use_mut
483n = get Gmutlen 0
484end
485while lt off n bound 65536
486nw = long 0
487if use_mut
488nw = write fd Gmut off sub n off
489else
490nw = write fd Gsrc off sub n off
491end
492if le nw 0
493x0 = fclose fd
494ret -2
495end
496off = add off ulong nw
497end
498x1 = fclose fd
499ret 0
500end
501
502fn write_gpath_from_gfile plen ulong to long
503fd = int fopen Gpath 0 plen 577 420
504if lt fd 0
505ret -1
506end
507off = ulong 0
508n = get Gfilelen 0
509while lt off n bound 65536
510nw = write fd Gfile off sub n off
511if le nw 0
512x0 = fclose fd
513ret -2
514end
515off = add off ulong nw
516end
517x1 = fclose fd
518ret 0
519end
520
521fn write_gpath_from_gtsv plen ulong to long
522fd = int fopen Gpath 0 plen 577 420
523if lt fd 0
524ret -1
525end
526off = ulong 0
527n = get Gtsvlen 0
528while lt off n bound 65536
529nw = write fd Gtsv off sub n off
530if le nw 0
531x0 = fclose fd
532ret -2
533end
534off = add off ulong nw
535end
536x1 = fclose fd
537ret 0
538end
539
540fn read_fd_to_gfile fd int to long
541off = ulong 0
542go = true
543while go bound 65536
544if ge off 2097152
545x0 = fclose fd
546ret -2
547end
548nr = read fd Gfile off sub 2097152 off
549if lt nr 0
550x1 = fclose fd
551ret -3
552end
553if eq nr 0
554go = false
555else
556off = add off ulong nr
557end
558end
559x2 = fclose fd
560put Gfilelen 0 off
561ret long off
562end
563
564note pkind: 0=Gomc, 1=Gtbin, 2=Gtout, 3=Gpath(plen)
565fn read_kind_to_gfile pkind ulong plen ulong to long
566fd = int -1
567if eq pkind 0
568fd = int fopen Gomc 0 get Gomclen 0 0 0
569end
570if eq pkind 1
571fd = int fopen Gtbin 0 get Gtbinlen 0 0 0
572end
573if eq pkind 2
574fd = int fopen Gtout 0 get Gtoutlen 0 0 0
575end
576if eq pkind 3
577fd = int fopen Gpath 0 plen 0 0
578end
579if lt fd 0
580ret -1
581end
582ret read_fd_to_gfile fd
583end
584
585fn append_src_file path view uchar * to long
586fd = int fopen path 0 len path 0 0
587if lt fd 0
588ret -1
589end
590nr = read_fd_to_gfile fd
591if lt nr 0
592ret -2
593end
594cur = get Gsrclen 0
595n = ulong nr
596if gt add cur n 131072
597ret -3
598end
599for i ulong n
600put Gsrc add cur i get Gfile i
601end
602put Gsrclen 0 add cur n
603ret 0
604end
605
606fn build_out_path sfx view uchar * to ulong
607ol = get Goutlen 0
608sl = len sfx
609for i ulong ol
610put Gpath i get Gout i
611end
612for i ulong sl
613put Gpath add ol i get sfx i
614end
615ret add ol sl
616end
617
618fn append_dec dst edit uchar 128 pos ulong v ulong to ulong
619dg = new uchar 24 0
620if eq v 0
621put dst pos 48
622ret add pos 1
623end
624k = ulong 0
625x = v
626while gt x 0 bound 24
627put dg k uchar add 48 and rem x 10 0xff
628x = div x 10
629k = add k 1
630end
631p = pos
632for i ulong k
633put dst p get dg sub sub k 1 i
634p = add p 1
635end
636ret p
637end
638
639fn init_tmp_paths to void
640tmp = new uchar 128 0
641pid = ulong getpid
642for i ulong len Stmpin
643put tmp i get Stmpin i
644end
645l1 = append_dec tmp len Stmpin pid
646for i ulong l1
647put Gtin i get tmp i
648end
649put Gtinlen 0 l1
650for i ulong len Stmpbin
651put tmp i get Stmpbin i
652end
653l2 = append_dec tmp len Stmpbin pid
654for i ulong l2
655put Gtbin i get tmp i
656end
657put Gtbinlen 0 l2
658for i ulong len Stmpout
659put tmp i get Stmpout i
660end
661l3 = append_dec tmp len Stmpout pid
662for i ulong l3
663put Gtout i get tmp i
664end
665put Gtoutlen 0 l3
666end
667
668fn cleanup_tmp to void
669x1 = unlink Gtin 0 get Gtinlen 0
670x2 = unlink Gtbin 0 get Gtbinlen 0
671x3 = unlink Gtout 0 get Gtoutlen 0
672end
673
674fn pkt_put_u16 pos ulong v ulong to ulong
675put Gpkt pos uchar and v 0xff
676put Gpkt add pos 1 uchar and shr v 8 0xff
677ret add pos 2
678end
679
680fn pkt_add_gomc pos ulong to ulong
681n = get Gomclen 0
682p = pkt_put_u16 pos n
683for i ulong n
684put Gpkt add p i get Gomc i
685end
686ret add p n
687end
688
689fn pkt_add_gtbin pos ulong to ulong
690n = get Gtbinlen 0
691p = pkt_put_u16 pos n
692for i ulong n
693put Gpkt add p i get Gtbin i
694end
695ret add p n
696end
697
698fn pkt_add_txt pos ulong s view uchar * to ulong
699n = len s
700p = pkt_put_u16 pos n
701for i ulong n
702put Gpkt add p i get s i
703end
704ret add p n
705end
706
707fn child_exec inkind ulong outkind ulong pktlen ulong to void
708fdi = int -1
709if eq inkind 1
710fdi = int fopen Gtin 0 get Gtinlen 0 0 0
711else
712fdi = int fopen Sdevnull 0 len Sdevnull 0 0
713end
714if lt fdi 0
715exit 125
716end
717fdo = int -1
718if eq outkind 0
719fdo = int fopen Gtbin 0 get Gtbinlen 0 577 493
720else
721fdo = int fopen Gtout 0 get Gtoutlen 0 577 420
722end
723if lt fdo 0
724exit 126
725end
726fde = int fopen Sdevnull 0 len Sdevnull 1 0
727if lt fde 0
728exit 127
729end
730if ne fdi 0
731d0 = dupfd fdi 0 0
732end
733if ne fdo 1
734d1 = dupfd fdo 1 0
735end
736if ne fde 2
737d2 = dupfd fde 2 0
738end
739r = execprog Gpkt 0 pktlen
740exit 124
741end
742
743fn spawn_pkt inkind ulong outkind ulong pktlen ulong to long
744wst = new uchar 4 0
745pid = fork
746if lt pid 0
747ret -1
748end
749if eq pid 0
750child_exec inkind outkind pktlen
751end
752wp = waitpid int pid wst 0 4 0
753if lt wp 0
754ret -2
755end
756st = rd32le view wst 0
757if eq and st 0x7f 0
758ret long and shr st 8 0xff
759end
760ret long add 128 and st 0x7f
761end
762
763fn compile_cur use_mut bool to long
764if lt write_tin use_mut 0
765ret -1
766end
767x0 = unlink Gtbin 0 get Gtbinlen 0
768p = pkt_put_u16 0 1
769plen = pkt_add_gomc p
770rc = spawn_pkt 1 0 plen
771if eq rc 0
772fd = int fopen Gtbin 0 get Gtbinlen 0 0 0
773if lt fd 0
774ret -2
775end
776x1 = fchmod fd 493
777x2 = fclose fd
778nr = read_kind_to_gfile 1 0
779if le nr 0
780ret -3
781end
782sha256_gosha_kind 0 ulong nr
783save_bsha2
784end
785ret rc
786end
787
788fn run_bin0 to long
789p = pkt_put_u16 0 1
790plen = pkt_add_gtbin p
791rc = spawn_pkt 0 1 plen
792nr = read_kind_to_gfile 2 0
793if lt nr 0
794ret -1
795end
796sha256_gosha_kind 0 ulong nr
797ret rc
798end
799
800fn run_bin1 arg1 view uchar * to long
801p = pkt_put_u16 0 2
802p = pkt_add_gtbin p
803plen = pkt_add_txt p arg1
804rc = spawn_pkt 0 1 plen
805nr = read_kind_to_gfile 2 0
806if lt nr 0
807ret -1
808end
809sha256_gosha_kind 0 ulong nr
810ret rc
811end
812
813fn run_bin2 arg1 view uchar * arg2 view uchar * to long
814p = pkt_put_u16 0 3
815p = pkt_add_gtbin p
816p = pkt_add_txt p arg1
817plen = pkt_add_txt p arg2
818rc = spawn_pkt 0 1 plen
819nr = read_kind_to_gfile 2 0
820if lt nr 0
821ret -1
822end
823sha256_gosha_kind 0 ulong nr
824ret rc
825end
826
827fn match_at pos ulong slen ulong tgt view uchar * tlen ulong to bool
828if gt add pos tlen slen
829ret false
830end
831for j ulong tlen
832if ne get Gsrc add pos j get tgt j
833ret false
834end
835end
836ret true
837end
838
839fn emit_rep pos ulong rep view uchar * to ulong
840o = pos
841for k ulong len rep
842ch = get rep k
843if eq ch 124
844put Gmut o 10
845else
846put Gmut o ch
847end
848o = add o 1
849end
850ret o
851end
852
853fn patch_src tgt view uchar * rep view uchar * to long
854slen = get Gsrclen 0
855tlen = len tgt
856i = ulong 0
857o = ulong 0
858hits = long 0
859while lt i slen bound 131072
860if and eq hits 0 match_at i slen tgt tlen
861o = emit_rep o rep
862i = add i tlen
863hits = add hits 1
864else
865put Gmut o get Gsrc i
866o = add o 1
867i = add i 1
868end
869end
870put Gmutlen 0 o
871ret hits
872end
873
874fn print_err_step step ulong to int
875dg = new uchar 24 0
876x0 = write_txt 2 MsgFail
877k = ulong 0
878v = step
879while gt v 0 bound 24
880put dg k uchar add 48 and rem v 10 0xff
881v = div v 10
882k = add k 1
883end
884for i ulong k
885put Gpath i get dg sub sub k 1 i
886end
887put Gpath k 10
888x1 = write 2 Gpath 0 add k 1
889cleanup_tmp
890ret 1
891end
892
893fn check_orig_3x to int
894for r ulong 3
895crc = compile_cur false
896if ne crc 0
897ret 10
898end
899if eq r 0
900save_bsha1
901else
902if not bsha_eq_1_2
903ret 11
904end
905end
906rc1 = run_bin1 Tself
907if or ne rc1 0 not gosha_eq_pin PinEmpty
908ret 12
909end
910tsv_head Torig Tself 0 0
911tsv_tail 1 0 1 Tpass
912rc2 = run_bin1 Ttrace
913if or ne rc2 0 not gosha_eq_pin PinTrace
914ret 13
915end
916if not gfile_eq_gexp
917ret 14
918end
919tsv_head Torig Ttrace 0 0
920tsv_tail 1 0 1 Tpass
921end
922ret 0
923end
924
925fn check_ipc_and_controls to int
926rci = run_bin1 Tipc
927if or ne rci 0 not gfile_has_pref SipcPref
928ret 20
929end
930ipcl = build_out_path Sipcf
931if lt write_gpath_from_gfile ipcl 0
932ret 21
933end
934tsv_head Torig Tipc 0 0
935tsv_tail 1 0 0 Tpass
936ep = build_out_path Sexpf
937nr = read_kind_to_gfile 3 ep
938if le nr 0
939ret 22
940end
941put Gfile 0 uchar xor uint get Gfile 0 1
942sha256_gosha_kind 0 ulong nr
943if or gfile_eq_gexp gosha_eq_pin PinTrace
944ret 23
945end
946tsv_head Tccor Ttrace 2 0
947tsv_tail 0 -1 1 Tpass
948rcn = run_bin0
949if or ne rcn 2 not gosha_eq_pin PinEmpty
950ret 24
951end
952tsv_head Tcanone Tusage 0 0
953tsv_tail 1 rcn 1 Tpass
954rcb = run_bin1 Tbadarg
955if or ne rcb 2 not gosha_eq_pin PinEmpty
956ret 25
957end
958tsv_head Tcabad Tusage 0 0
959tsv_tail 1 rcb 1 Tpass
960rct = run_bin2 Ttrace Textra
961if or ne rct 2 not gosha_eq_pin PinEmpty
962ret 26
963end
964tsv_head Tcatwo Tusage 0 0
965tsv_tail 1 rct 1 Tpass
966ret 0
967end
968
969fn check_trap_probes to int
970r1 = run_bin1 Ttrapt
971if ne r1 110
972ret 30
973end
974tsv_head Tptrit Ttrapt 0 0
975tsv_tail 1 r1 1 Ttrap10
976r2 = run_bin1 Ttrapd
977if ne r2 110
978ret 31
979end
980tsv_head Tpdup Ttrapd 0 0
981tsv_tail 1 r2 1 Ttrap10
982r3 = run_bin1 Ttrapr
983if ne r3 109
984ret 32
985end
986tsv_head Tpreq Ttrapr 0 0
987tsv_tail 1 r3 1 Ttrap9
988r4 = run_bin1 Tovfp
989if ne r4 0
990ret 33
991end
992tsv_head Tpovf Tovfp 0 0
993tsv_tail 1 r4 1 Tpass
994ret 0
995end
996
997fn prep_mutant tgt view uchar * rep view uchar * to int
998if ne patch_src tgt rep 1
999ret 1
1000end
1001sha256_gosha_kind 3 get Gmutlen 0
1002save_msha
1003if msha_eq_ssha
1004ret 2
1005end
1006ret 0
1007end
1008
1009fn exec_mutant mid view uchar * mode ulong ovfchk bool to int
1010crc = compile_cur true
1011if ne crc 0
1012ret 3
1013end
1014rcs = run_bin1 Tself
1015if eq mode 0
1016if eq rcs 0
1017ret 4
1018end
1019tsv_head mid Tself 1 0
1020tsv_tail 2 rcs 1 Tscaught
1021end
1022if eq mode 1
1023if ne rcs 110
1024ret 5
1025end
1026tsv_head mid Tself 1 0
1027tsv_tail 2 rcs 1 Ttrap10
1028end
1029if eq mode 2
1030if ne rcs 109
1031ret 6
1032end
1033tsv_head mid Tself 1 0
1034tsv_tail 2 rcs 1 Ttrap9
1035end
1036if eq mode 3
1037if ne rcs 0
1038ret 7
1039end
1040tsv_head mid Tself 1 0
1041tsv_tail 2 rcs 1 Tsmiss
1042end
1043rct = run_bin1 Ttrace
1044if and eq rct 0 gosha_eq_pin PinTrace
1045ret 8
1046end
1047tsv_head mid Ttrace 1 0
1048if eq rct 110
1049tsv_tail 2 rct 1 Ttrap10
1050else
1051if eq rct 109
1052tsv_tail 2 rct 1 Ttrap9
1053else
1054tsv_tail 2 rct 1 Tokilled
1055end
1056end
1057if ovfchk
1058rco = run_bin1 Tovfp
1059if ne rco 101
1060ret 9
1061end
1062tsv_head mid Tovfb 1 0
1063tsv_tail 2 rco 1 Ttrap1
1064end
1065ret 0
1066end
1067
1068fn exec_type_swap xid view uchar * to int
1069crc = compile_cur true
1070if ne crc 7
1071ret 2
1072end
1073tsv_head xid Tcomp 1 crc
1074tsv_tail 0 -1 0 Tcref7
1075ret 0
1076end
1077
1078note IPC mutant: node B decodes and returns a different job wave with a self-consistent
1079note receipt. Killed only when the host refuses it (btwave ipc exit 65, no stdout).
1080fn exec_ipc_mutant mid view uchar * to int
1081crc = compile_cur true
1082if ne crc 0
1083ret 3
1084end
1085rci = run_bin1 Tipc
1086if or ne rci 65 not gosha_eq_pin PinEmpty
1087ret 10
1088end
1089tsv_head mid Tipc 1 0
1090tsv_tail 2 rci 1 Tipcref
1091ret 0
1092end
1093
1094fn run_all_mutants_a to int
1095if or ne prep_mutant M01t M01r 0 ne exec_mutant M01id 0 false 0
1096ret 101
1097end
1098if or ne prep_mutant M02t M02r 0 ne exec_mutant M02id 0 false 0
1099ret 102
1100end
1101if or ne prep_mutant M03t M03r 0 ne exec_mutant M03id 0 false 0
1102ret 103
1103end
1104if or ne prep_mutant M04t M04r 0 ne exec_mutant M04id 0 false 0
1105ret 104
1106end
1107if or ne prep_mutant M05t M05r 0 ne exec_mutant M05id 0 false 0
1108ret 105
1109end
1110if or ne prep_mutant M06t M06r 0 ne exec_mutant M06id 0 false 0
1111ret 106
1112end
1113if or ne prep_mutant M07t M07r 0 ne exec_mutant M07id 0 false 0
1114ret 107
1115end
1116if or ne prep_mutant M08t M08r 0 ne exec_mutant M08id 0 false 0
1117ret 108
1118end
1119if or ne prep_mutant M09t M09r 0 ne exec_mutant M09id 0 false 0
1120ret 109
1121end
1122if or ne prep_mutant M10t M10r 0 ne exec_mutant M10id 0 false 0
1123ret 110
1124end
1125if or ne prep_mutant M11t M11r 0 ne exec_mutant M11id 0 false 0
1126ret 111
1127end
1128ret 0
1129end
1130
1131fn run_all_mutants_b to int
1132if or ne prep_mutant M12t M12r 0 ne exec_mutant M12id 0 false 0
1133ret 112
1134end
1135if or ne prep_mutant M13t M13r 0 ne exec_mutant M13id 0 false 0
1136ret 113
1137end
1138if or ne prep_mutant M14t M14r 0 ne exec_mutant M14id 0 false 0
1139ret 114
1140end
1141if or ne prep_mutant M15t M15r 0 ne exec_mutant M15id 0 false 0
1142ret 115
1143end
1144if or ne prep_mutant M16t M16r 0 ne exec_mutant M16id 0 false 0
1145ret 116
1146end
1147if or ne prep_mutant M17t M17r 0 ne exec_mutant M17id 0 false 0
1148ret 117
1149end
1150if or ne prep_mutant M18t M18r 0 ne exec_mutant M18id 1 false 0
1151ret 118
1152end
1153if or ne prep_mutant M19t M19r 0 ne exec_mutant M19id 1 false 0
1154ret 119
1155end
1156if or ne prep_mutant M20t M20r 0 ne exec_mutant M20id 2 false 0
1157ret 120
1158end
1159if or ne prep_mutant M21t M21r 0 ne exec_mutant M21id 0 true 0
1160ret 121
1161end
1162if or ne prep_mutant M22t M22r 0 ne exec_mutant M22id 3 false 0
1163ret 122
1164end
1165if or ne prep_mutant M23t M23r 0 ne exec_ipc_mutant M23id 0
1166ret 123
1167end
1168ret 0
1169end
1170
1171fn run_all_swaps to int
1172if or ne prep_mutant X1t X1r 0 ne exec_type_swap X1id 0
1173ret 201
1174end
1175if or ne prep_mutant X2t X2r 0 ne exec_type_swap X2id 0
1176ret 202
1177end
1178if or ne prep_mutant X3t X3r 0 ne exec_type_swap X3id 0
1179ret 203
1180end
1181if or ne prep_mutant X4t X4r 0 ne exec_type_swap X4id 0
1182ret 204
1183end
1184ret 0
1185end
1186
1187fn load_inputs to int
1188nr = read_kind_to_gfile 0 0
1189if le nr 0
1190ret 77
1191end
1192sha256_gosha_kind 0 ulong nr
1193if not gosha_eq_pin PinOmc
1194ret 77
1195end
1196ep = build_out_path Sexpf
1197en = read_kind_to_gfile 3 ep
1198if or le en 0 gt en 65536
1199ret 3
1200end
1201for i ulong ulong en
1202put Gexp i get Gfile i
1203end
1204put Gexplen 0 ulong en
1205sha256_gosha_kind 1 get Gexplen 0
1206if not gosha_eq_pin PinTrace
1207ret 4
1208end
1209put Gsrclen 0 0
1210if lt append_src_file Sf1 0
1211ret 5
1212end
1213if lt append_src_file Sf2 0
1214ret 6
1215end
1216if lt append_src_file Sf3 0
1217ret 7
1218end
1219if lt append_src_file Sf4 0
1220ret 8
1221end
1222sha256_gosha_kind 2 get Gsrclen 0
1223save_ssha
1224ret 0
1225end
1226
1227fn main to int
1228if ne argcnt 3
1229x0 = write_txt 2 MsgUsage
1230ret 2
1231end
1232l1 = argread 1 Gomc 0 512
1233l2 = argread 2 Gout 0 512
1234if or le l1 0 le l2 0
1235x1 = write_txt 2 MsgUsage
1236ret 2
1237end
1238put Gomclen 0 ulong l1
1239put Goutlen 0 ulong l2
1240init_tmp_paths
1241lrc = load_inputs
1242if eq lrc 77
1243x2 = write_txt 2 MsgNotRun
1244cleanup_tmp
1245ret 77
1246end
1247if ne lrc 0
1248ret print_err_step ulong lrc
1249end
1250put Gtsvlen 0 0
1251tsv_hdr
1252rc = check_orig_3x
1253if ne rc 0
1254ret print_err_step ulong rc
1255end
1256rc = check_ipc_and_controls
1257if ne rc 0
1258ret print_err_step ulong rc
1259end
1260rc = check_trap_probes
1261if ne rc 0
1262ret print_err_step ulong rc
1263end
1264rc = run_all_mutants_a
1265if ne rc 0
1266ret print_err_step ulong rc
1267end
1268rc = run_all_mutants_b
1269if ne rc 0
1270ret print_err_step ulong rc
1271end
1272rc = run_all_swaps
1273if ne rc 0
1274ret print_err_step ulong rc
1275end
1276cleanup_tmp
1277rp = build_out_path Srecf
1278if lt write_gpath_from_gtsv rp 0
1279ret print_err_step 250
1280end
1281x3 = write_txt 1 MsgPass
1282ret 0
1283end