interplane.Get Omega
Read in your language

aien-protocols-mv

Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem

Brought by drakestapleton

branch main Branches Tags History

aien-protocols-mv / specs / execution-transcript / tools / make-corpus.sh

587 lines · 37435 bytes Raw Blame History
1#!/bin/bash
2# make-corpus.sh: regenerate the TRN1 (execution transcript)
3# shared conformance corpus (contract 0.2.0: wire schemas 1 and 3).
4# Language-neutral spec: ../TRN1_TRANSCRIPT_SPEC.md.
5#
6# Usage: make-corpus.sh OUT_DIR (normally specs/execution-transcript/vectors)
7#
8# Every vector is built byte by byte here from the spec tables, with digests
9# from coreutils sha256sum. Nothing is produced by the C reference verifier,
10# so the corpus and the verifier are two independent readings of the spec;
11# tools/check-corpus.sh makes them agree.
12#
13# Groups (all listed in OUT_DIR/expected.txt, pairs in OUT_DIR/compare.txt):
14# gNNN.trn golden transcripts (accepted)
15# pNNN.trn edge positives (accepted)
16# fNNN.trn forged replays: valid chain, different history (accepted alone,
17# DIVERGENCE when compared with their golden)
18# mNNN.trn mutated transcripts (refused with a named code and event)
19# jNNN.trn contract 0.2.0: accepted by TRN1, refused by the causal join
20# (expected join refusals in OUT_DIR/join.txt, NOT_RUN here)
21# Shell only: no Python, no tools beyond coreutils.
22set -eu
23export LC_ALL=C
24OUT=${1:?OUT_DIR}
25mkdir -p "$OUT"
26rm -f "$OUT"/*.trn "$OUT"/expected.txt "$OUT"/compare.txt "$OUT"/join.txt "$OUT"/.gitattributes
27# Vectors are exact bytes (digests cover every byte), so git must never apply
28# line-ending or text conversion to them. This file is part of the corpus and
29# is checked by check-corpus.sh like any vector.
30printf '*.trn binary\n' >"$OUT/.gitattributes"
31
32# ---- hex helpers (all integers little-endian) ---------------------------
33# le BYTES VALUE: VALUE as BYTES little-endian bytes, in hex
34le() {
35 local n=$1 v=$2 h out="" i
36 if [ "$n" -lt 8 ]; then v=$((v & ((1 << (8 * n)) - 1))); fi
37 h=$(printf "%0$((2 * n))x" "$v")
38 for ((i = 2 * n - 2; i >= 0; i -= 2)); do out+=${h:i:2}; done
39 printf '%s' "$out"
40}
41h8() { le 1 "$1"; }
42h16() { le 2 "$1"; }
43h32() { le 4 "$1"; }
44h64() { le 8 "$1"; }
45zeros() { local i out=""; for ((i = 0; i < $1; i++)); do out+=00; done; printf '%s' "$out"; }
46# txt STRING: the bytes of STRING in hex
47txt() { printf '%s' "$1" | od -An -v -tx1 | tr -d ' \n'; }
48# bin HEX: write raw bytes
49bin() { local e; e=$(printf '%s' "$1" | sed 's/../\\x&/g'); printf '%b' "$e"; }
50# sha HEX: SHA-256 of the bytes, in hex
51sha() { bin "$1" | sha256sum | cut -c1-64; }
52# dig STRING: a fixed 32-byte digest used as test data
53dig() { printf '%s' "$1" | sha256sum | cut -c1-64; }
54# flip HEX BYTE_OFFSET: HEX with the low bit of that byte inverted
55flip() {
56 local h=$1 o=$(($2 * 2)) b
57 b=$(printf '%02x' $((0x${h:o:2} ^ 1)))
58 printf '%s' "${h:0:o}$b${h:o+2}"
59}
60
61# ---- transcript builder ---------------------------------------------------
62# A transcript is built in the shell variables T (hex so far), PREV (digest of
63# the last record or header), SEQ, and OFF[i]/LEN[i] (byte offset and length
64# of record i, 1-based), so byte-level mutants can find records.
65SUB_TRANSCRIPT=0 SUB_WORLD=1 SUB_CORTEX=2 SUB_JSPACE=3 SUB_KERNEL=4 SUB_ARGUS=5
66SUB_RUNTIME=7 SUB_SCHED=8 SUB_KV=9 SUB_EXTERNAL=10
67# start PRODUCER RUN_ID_HEX [SCHEMA] [FLAGS] [RESERVED_HEX]
68start() {
69 T="TRN1"
70 T=$(txt TRN1)$(h16 "${3:-1}")$(h16 "${4:-0}")$2$(h16 "$1")${5:-$(zeros 6)}
71 PREV=$(sha "$T")
72 SEQ=0
73 OFF=() LEN=()
74}
75# rec TYPE SUB IDENT_HEX ANNOT_HEX [SEQ] [PREV] [RESERVED] [IDENT_LEN]
76rec() {
77 local s=${5:-$((SEQ + 1))} p=${6:-$PREV} il=${8:-$((${#3} / 2))} r
78 r=$(h16 "$1")$(h16 "$2")$(h32 "$il")$(h32 $((${#4} / 2)))$(h32 "${7:-0}")$(h64 "$s")$p$3$4
79 SEQ=$((SEQ + 1))
80 OFF[SEQ]=$((${#T} / 2))
81 LEN[SEQ]=$((${#r} / 2))
82 T+=$r
83 PREV=$(sha "$r")
84}
85end() { rec 65535 $SUB_TRANSCRIPT "$(h64 $((SEQ + 1)))$(zeros 8)" "${1:-}"; }
86save() { bin "$T" >"$OUT/$1"; }
87
88# ---- record identity builders (spec section 5) ------------------------------
89sched() { printf '%s' "$(h64 "$1")$(h64 "$2")$(h64 "$3")$(h64 "$4")"; }
90branch_create() { printf '%s' "$(h64 "$1")$(h64 "$2")$(h64 "$3")"; }
91branch_destroy() { printf '%s' "$(h64 "$1")$(h64 "$2")$(h32 "$3")$(zeros 4)"; }
92rng_seed() { printf '%s' "$(h64 "$1")$2"; }
93rng_draw() { printf '%s' "$(h64 "$1")$(h64 "$2")$(h64 "$3")"; }
94artifact() { printf '%s' "$(h32 "$1")$(zeros 4)$(h64 "$2")$3"; }
95# cap_transition CAP OP GEN_BEFORE GEN_AFTER PRINCIPAL ISSUER [RESERVED3_HEX]
96cap_transition() { printf '%s' "$(h32 "$1")$(h8 "$2")${7:-000000}$(h64 "$3")$(h64 "$4")$(h32 "$5")$(h32 "$6")"; }
97cortex_read() { printf '%s' "$(h32 "$1")$(h32 "$2")$(h64 "$3")$(h64 "$4")$5"; }
98effect_intent() { printf '%s' "$(h64 "$1")$(h32 "$2")$(h32 "$3")$(h64 "$4")$5"; }
99effect_commit() { printf '%s' "$(h64 "$1")$(h32 "$2")$(zeros 4)$3"; }
100# external_input SOURCE INPUT_SEQ CONTENT_HEX [DIGEST_HEX]
101external_input() { printf '%s' "$(h32 "$1")$(zeros 4)$(h64 "$2")${4:-$(sha "$3")}$3"; }
102clock_read() { printf '%s' "$(h32 "$1")$(zeros 4)$(h64 "$2")"; }
103crash_boundary() { printf '%s' "$(h64 "$1")$(h64 "$2")$3"; }
104checkpoint() { printf '%s' "$(h32 "$1")$(zeros 4)$2"; }
105# Omega RxCrumb canonical bytes (rx_world.c crumb_hash, after the tag):
106# crumb_canon ID KIND REACTION FACULTY WAKE COALESCED INPUTS_HEX CAPS_HEX OUTPUTS_HEX REASON PARENTS_HEX
107# where INPUTS_HEX etc. already start with their u32 count.
108crumb_canon() { printf '%s' "$(h64 "$1")$(h32 "$2")$(h32 "$3")$(h32 "$4")$(h64 "$5")$(h64 "$6")$7$8$9$(h32 "${10}")${11}"; }
109objv() { printf '%s' "$(h32 "$1")$(h32 "$2")$(h64 "$3")$(h64 "$4")"; } # obj id, obj gen, version, mask
110capv() { printf '%s' "$(h32 "$1")$(h64 "$2")$(h32 "$3")"; } # cap id, 64-bit generation, issuer
111crumb_digest() { sha "$(txt AIEN_RX_CAUSAL_V1)$1"; }
112# rx_crumb CANON [DIGEST]: RX_CRUMB identity = digest || canonical bytes
113rx_crumb() { printf '%s' "${2:-$(crumb_digest "$1")}$1"; }
114crumb_annot() { printf '%s' "$(h32 "$1")$(h64 "$2")$(h64 "$3")$(h64 "$4")"; } # worker, t_start, t_end, episode
115# ARGUS: 128-byte ArgusEvent wire bytes (aienos native/argus/argus_event.c encode_raw)
116# argus_ev SEQUENCE KIND CLASS OUTCOME PRINCIPAL CAP_ID CAP_GEN
117argus_ev() {
118 printf '%s' "$(h8 1)$(h8 "$3")$(h16 "$2")$(h8 0)$(h8 "$4")$(h16 0)$(h64 "$1")$(h64 "$1")$(h32 "$5")$(h32 0)$(h32 "$6")$(h32 0)$(h64 "$7")$(h64 1)$(h64 0)$(dig "machine A1")$(dig "evidence $1")"
119}
120# argus_rec EVENT_HEX CHAINED BEFORE_HEX [AFTER_HEX] [RESERVED7_HEX]
121argus_rec() {
122 local after=${4:-}
123 if [ -z "$after" ]; then
124 if [ "$2" != 0 ]; then after=$(sha "$3$1"); else after=$3; fi
125 fi
126 printf '%s' "$1$(h8 "$2")${5:-$(zeros 7)}$3$after"
127}
128ARGUS_AFTER=""
129sched_annot() { printf '%s' "$(h32 "$1")$(h64 "$2")"; } # worker, wall time (not compared)
130
131# ---- manifests ------------------------------------------------------------
132{
133 echo "# TRN1 shared conformance corpus. Spec: TRN1_TRANSCRIPT_SPEC.md (contract 0.1.0, wire schema 1)."
134 echo "# Line: <file> ok records=N run=<64 hex> final=<64 hex>"
135 echo "# or: <file> refuse <code> event=<record position, 0 = file header>"
136 echo "# codes: -1 MAGIC -2 VERSION -3 LENGTH -4 NONCANONICAL -5 UNKNOWN -6 SHAPE"
137 echo "# -7 GAP -8 CHAIN -9 DIGEST -10 TRUNCATED"
138 echo "# Generated by tools/make-corpus.sh; do not edit by hand."
139} >"$OUT/expected.txt"
140{
141 echo "# TRN1 replay comparison pairs. Spec section 8."
142 echo "# Line: <expected file> <actual file> MATCH through N"
143 echo "# or: <expected file> <actual file> DIVERGENCE event=N expected=<64 hex> actual=<64 hex> subsystem=<name>"
144 echo "# or: <expected file> <actual file> refuse expected|actual <code> event=N"
145 echo "# Generated by tools/make-corpus.sh; do not edit by hand."
146} >"$OUT/compare.txt"
147ok() { echo "$1 ok records=$2 run=$3 final=$PREV" >>"$OUT/expected.txt"; }
148refuse() { echo "$1 refuse $2 event=$3" >>"$OUT/expected.txt"; }
149pair() { echo "$1 $2 $3" >>"$OUT/compare.txt"; }
150# Compared digest of record I of the transcript in T (spec section 8).
151cmpd() {
152 local i=$1 o=$((OFF[$1] * 2)) il
153 il=$((0x$(printf '%s' "${T:o+14:2}${T:o+12:2}${T:o+10:2}${T:o+8:2}")))
154 sha "$(txt AIEN_TRN1_CMP)${T:o:8}${T:o+32:16}${T:o+8:8}${T:o+112:il*2}"
155}
156# cut FILE_HEX START_BYTE COUNT: bytes [START, START+COUNT)
157cut_hex() { printf '%s' "${1:$(($2 * 2)):$(($3 * 2))}"; }
158
159# ===========================================================================
160# g001: Omega World run (producer omega-world). Every record kind a World
161# writes today, including two real RxCrumbs (create, then commit with parent).
162# ===========================================================================
163RUN1=$(dig "run g001")
164C1=$(crumb_canon 1 1 4294967295 0 0 0 "$(h32 0)" "$(h32 0)" "$(h32 1)$(objv 5 1 3 255)" 0 "$(h32 0)")
165C1D=$(crumb_digest "$C1")
166C2=$(crumb_canon 2 3 3 1 1 0 "$(h32 1)$(objv 5 1 3 255)" "$(h32 1)$(capv 4 9 1)" "$(h32 1)$(objv 6 1 1 1)" 0 "$(h32 1)$(h64 1)$C1D")
167g001() { # g001 [worker-time skew for replay annotations] [run id]
168 local w=${1:-0}
169 start $SUB_WORLD "${2:-$RUN1}"
170 rec 4 $SUB_WORLD "$(rng_seed 1 "$(dig "seed g001")")" ""
171 rec 2 $SUB_JSPACE "$(branch_create 7 0 1)" ""
172 rec 1 $SUB_WORLD "$(sched 1 3 0 0)" "$(sched_annot $((2 + w)) $((1000 + w * 77)))"
173 rec 8 $SUB_CORTEX "$(cortex_read 5 1 3 255 "$(dig "cortex obj5 v3")")" ""
174 rec 15 $SUB_WORLD "$(rx_crumb "$C1")" "$(crumb_annot $((1 + w)) $((2000 + w)) $((2100 + w)) 1)"
175 rec 15 $SUB_WORLD "$(rx_crumb "$C2")" "$(crumb_annot $((2 + w)) $((2200 + w)) $((2900 + w)) 1)"
176 rec 7 $SUB_KERNEL "$(cap_transition 4 2 9 10 3 1)" ""
177 rec 9 $SUB_WORLD "$(effect_intent 1 2 4 10 "$(dig "effect 1 request")")" ""
178 rec 10 $SUB_WORLD "$(effect_commit 1 0 "$(dig "effect 1 result")")" ""
179 rec 14 $SUB_WORLD "$(checkpoint 1 "$(dig "world state after g001")")" ""
180}
181g001; end; save g001.trn; ok g001.trn 11 "$RUN1"
182G1=$T
183G1CMP=(); for i in $(seq 1 11); do G1CMP[i]=$(cmpd "$i"); done
184
185# g005: replay of g001 on another schedule. Different run id, workers and
186# wall times (annotations); same identities. Verifies alone and MATCHes g001.
187RUN5=$(dig "run g005 replay of g001")
188g001 3 "$RUN5"; end; save g005.trn; ok g005.trn 11 "$RUN5"
189pair g001.trn g005.trn "MATCH through 11"
190pair g001.trn g001.trn "MATCH through 11"
191
192# ===========================================================================
193# g002: Aienux ARGUS stream (producer aienos-argus). Two chained events, one
194# malformed event recorded but not chained (argus_core step 0), a revoke.
195# ===========================================================================
196RUN2=$(dig "run g002")
197E1=$(argus_ev 1 10 2 1 3 4 9)
198E2=$(argus_ev 2 11 2 1 3 4 10)
199E3=$(argus_ev 3 12 2 9 3 4 10)
200Z32=$(zeros 32)
201A1=$(sha "$Z32$E1"); A2=$(sha "$A1$E2")
202start $SUB_ARGUS "$RUN2"
203rec 16 $SUB_ARGUS "$(argus_rec "$E1" 1 "$Z32")" ""
204rec 16 $SUB_ARGUS "$(argus_rec "$E2" 1 "$A1")" ""
205rec 16 $SUB_ARGUS "$(argus_rec "$E3" 0 "$A2")" ""
206rec 7 $SUB_KERNEL "$(cap_transition 4 4 10 11 3 1)" ""
207rec 14 $SUB_ARGUS "$(checkpoint 2 "$A2")" ""
208end; save g002.trn; ok g002.trn 6 "$RUN2"
209G2=$T
210pair g002.trn g002.trn "MATCH through 6"
211
212# ===========================================================================
213# g003: the remaining record types (producer sovcore-runtime), including a
214# recovered crash boundary and external input with and without content.
215# ===========================================================================
216RUN3=$(dig "run g003")
217IN1=$(txt "hello transcript")
218g003() {
219 start $SUB_RUNTIME "$RUN3"
220 rec 11 $SUB_EXTERNAL "$(external_input 1 1 "$IN1")" ""
221 rec 11 $SUB_EXTERNAL "$(external_input 1 2 "" "$(dig "input 2 stored elsewhere")")" ""
222 rec 12 $SUB_RUNTIME "$(clock_read 1 42)" ""
223 rec 5 $SUB_RUNTIME "$(rng_draw 1 0 12345)" ""
224 rec 6 $SUB_RUNTIME "$(artifact 1 9 "$(dig "artifact 9")")" ""
225 rec 2 $SUB_KV "$(branch_create 2 1 1)" ""
226 rec 3 $SUB_KV "$(branch_destroy 2 1 -1)" ""
227 rec 13 $SUB_RUNTIME "$(crash_boundary 2 7 "$(dig "recovered state epoch 2")")" ""
228 rec 1 $SUB_SCHED "$(sched 1 1 0 0)" "$(sched_annot 0 5)"
229 rec 14 $SUB_KV "$(checkpoint 3 "$(dig "kv pages after g003")")" ""
230}
231g003; end; save g003.trn; ok g003.trn 11 "$RUN3"
232G3=$T
233
234# g004: the smallest transcript, END only.
235RUN4=$(dig "run g004")
236start $SUB_KERNEL "$RUN4"; end; save g004.trn; ok g004.trn 1 "$RUN4"
237
238# ===========================================================================
239# Edge positives.
240# ===========================================================================
241# p001: largest external input content (4096 bytes) and a large annotation.
242BIG=$(for i in $(seq 1 256); do printf '%s' "000102030405060708090a0b0c0d0e0f"; done)
243start $SUB_RUNTIME "$(dig "run p001")"
244rec 11 $SUB_EXTERNAL "$(external_input 2 1 "$BIG")" "$BIG$BIG"
245end; save p001.trn; ok p001.trn 2 "$(dig "run p001")"
246# p002: crumb at Omega's limits: 8 inputs, 8 caps, 8 outputs, and parents that
247# carry no digest (p = 0 and p >= id), as crumb_hash writes them.
248INS=$(h32 8); CAPS=$(h32 8); OUTS=$(h32 8)
249for i in 1 2 3 4 5 6 7 8; do INS+=$(objv "$i" 1 "$i" 255); CAPS+=$(capv "$i" $((1 << 40)) 0); OUTS+=$(objv $((i + 8)) 2 1 1); done
250CP=$(crumb_canon 5 3 2 1 4 2 "$INS" "$CAPS" "$OUTS" -3 "$(h32 4)$(h64 0)$(h64 4)$C1D$(h64 5)$(h64 9)")
251start $SUB_WORLD "$(dig "run p002")"
252rec 15 $SUB_WORLD "$(rx_crumb "$CP")" "$(crumb_annot 0 0 0 0)"
253end; save p002.trn; ok p002.trn 2 "$(dig "run p002")"
254
255# ===========================================================================
256# Forged replays: each has a valid chain (accepted alone) but a different
257# history than g001. Only comparison against the expected run finds them.
258# ===========================================================================
259div() { # div FILE EVENT SUBSYSTEM: record the DIVERGENCE pair against g001
260 pair g001.trn "$1" "DIVERGENCE event=$2 expected=${G1CMP[$2]} actual=$(cmpd "$2") subsystem=$3"
261}
262# f001 omission: record 3 (scheduler decision) dropped, renumbered, rechained.
263start $SUB_WORLD "$RUN1"
264rec 4 $SUB_WORLD "$(rng_seed 1 "$(dig "seed g001")")" ""
265rec 2 $SUB_JSPACE "$(branch_create 7 0 1)" ""
266rec 8 $SUB_CORTEX "$(cortex_read 5 1 3 255 "$(dig "cortex obj5 v3")")" ""
267rec 15 $SUB_WORLD "$(rx_crumb "$C1")" "$(crumb_annot 1 2000 2100 1)"
268rec 15 $SUB_WORLD "$(rx_crumb "$C2")" "$(crumb_annot 2 2200 2900 1)"
269rec 7 $SUB_KERNEL "$(cap_transition 4 2 9 10 3 1)" ""
270rec 9 $SUB_WORLD "$(effect_intent 1 2 4 10 "$(dig "effect 1 request")")" ""
271rec 10 $SUB_WORLD "$(effect_commit 1 0 "$(dig "effect 1 result")")" ""
272rec 14 $SUB_WORLD "$(checkpoint 1 "$(dig "world state after g001")")" ""
273end; save f001.trn; ok f001.trn 10 "$RUN1"; div f001.trn 3 omega-world
274# f002 reorder: records 3 and 4 swapped, rechained.
275start $SUB_WORLD "$RUN1"
276rec 4 $SUB_WORLD "$(rng_seed 1 "$(dig "seed g001")")" ""
277rec 2 $SUB_JSPACE "$(branch_create 7 0 1)" ""
278rec 8 $SUB_CORTEX "$(cortex_read 5 1 3 255 "$(dig "cortex obj5 v3")")" ""
279rec 1 $SUB_WORLD "$(sched 1 3 0 0)" "$(sched_annot 2 1000)"
280rec 15 $SUB_WORLD "$(rx_crumb "$C1")" "$(crumb_annot 1 2000 2100 1)"
281rec 15 $SUB_WORLD "$(rx_crumb "$C2")" "$(crumb_annot 2 2200 2900 1)"
282rec 7 $SUB_KERNEL "$(cap_transition 4 2 9 10 3 1)" ""
283rec 9 $SUB_WORLD "$(effect_intent 1 2 4 10 "$(dig "effect 1 request")")" ""
284rec 10 $SUB_WORLD "$(effect_commit 1 0 "$(dig "effect 1 result")")" ""
285rec 14 $SUB_WORLD "$(checkpoint 1 "$(dig "world state after g001")")" ""
286end; save f002.trn; ok f002.trn 11 "$RUN1"; div f002.trn 3 omega-world
287# f003: different RNG seed (first record).
288start $SUB_WORLD "$RUN1"
289rec 4 $SUB_WORLD "$(rng_seed 1 "$(dig "seed g001 other")")" ""
290end; save f003.trn; ok f003.trn 2 "$RUN1"; div f003.trn 1 omega-world
291# f004: crumb 2 used capability generation 8 instead of 9 (digest recomputed).
292C2X=$(crumb_canon 2 3 3 1 1 0 "$(h32 1)$(objv 5 1 3 255)" "$(h32 1)$(capv 4 8 1)" "$(h32 1)$(objv 6 1 1 1)" 0 "$(h32 1)$(h64 1)$C1D")
293start $SUB_WORLD "$RUN1"
294rec 4 $SUB_WORLD "$(rng_seed 1 "$(dig "seed g001")")" ""
295rec 2 $SUB_JSPACE "$(branch_create 7 0 1)" ""
296rec 1 $SUB_WORLD "$(sched 1 3 0 0)" "$(sched_annot 2 1000)"
297rec 8 $SUB_CORTEX "$(cortex_read 5 1 3 255 "$(dig "cortex obj5 v3")")" ""
298rec 15 $SUB_WORLD "$(rx_crumb "$C1")" "$(crumb_annot 1 2000 2100 1)"
299rec 15 $SUB_WORLD "$(rx_crumb "$C2X")" "$(crumb_annot 2 2200 2900 1)"
300end; save f004.trn; ok f004.trn 7 "$RUN1"; div f004.trn 6 omega-world
301# f005: one extra clock read before END.
302g001; rec 12 $SUB_WORLD "$(clock_read 1 99)" ""; end; save f005.trn; ok f005.trn 12 "$RUN1"; div f005.trn 11 transcript
303# f006: run stopped early (END after record 5).
304start $SUB_WORLD "$RUN1"
305rec 4 $SUB_WORLD "$(rng_seed 1 "$(dig "seed g001")")" ""
306rec 2 $SUB_JSPACE "$(branch_create 7 0 1)" ""
307rec 1 $SUB_WORLD "$(sched 1 3 0 0)" "$(sched_annot 2 1000)"
308rec 8 $SUB_CORTEX "$(cortex_read 5 1 3 255 "$(dig "cortex obj5 v3")")" ""
309rec 15 $SUB_WORLD "$(rx_crumb "$C1")" "$(crumb_annot 1 2000 2100 1)"
310end; save f006.trn; ok f006.trn 6 "$RUN1"; div f006.trn 6 omega-world
311
312# ===========================================================================
313# Byte-level mutants of g001 (damage after writing: nothing rechained).
314# ===========================================================================
315g001 >/dev/null; end # refresh OFF/LEN for g001
316mb() { bin "$1" >"$OUT/$2"; }
317R() { printf '%s' "${OFF[$1]}"; }
318# m001 omission: record 3 removed.
319mb "${G1:0:$(($(R 3) * 2))}${G1:$(($(R 4) * 2))}" m001.trn; refuse m001.trn -7 3
320# m002 reorder: records 3 and 4 swapped.
321mb "${G1:0:$(($(R 3) * 2))}$(cut_hex "$G1" "$(R 4)" "${LEN[4]}")$(cut_hex "$G1" "$(R 3)" "${LEN[3]}")${G1:$(($(R 5) * 2))}" m002.trn; refuse m002.trn -7 3
322# m003 bit flip in record 4 identity (cortex read digest): next record's prev breaks.
323mb "$(flip "$G1" $(($(R 4) + 56 + 30)))" m003.trn; refuse m003.trn -8 5
324# m004 bit flip in record 3 annotation (worker id): annotations are chained too.
325mb "$(flip "$G1" $(($(R 3) + 56 + 32)))" m004.trn; refuse m004.trn -8 4
326# m005 bit flip in record 2 prev field.
327mb "$(flip "$G1" $(($(R 2) + 24 + 5)))" m005.trn; refuse m005.trn -8 2
328# m006 bit flip in record 6 seq.
329mb "$(flip "$G1" $(($(R 6) + 16)))" m006.trn; refuse m006.trn -7 6
330# m007 bit flip in header run id.
331mb "$(flip "$G1" 9)" m007.trn; refuse m007.trn -8 1
332# m008 bit flip in magic.
333mb "$(flip "$G1" 0)" m008.trn; refuse m008.trn -1 0
334# m009 truncation inside record 5.
335mb "${G1:0:$((($(R 5) + 70) * 2))}" m009.trn; refuse m009.trn -3 5
336# m010 truncation at a record boundary: END lost.
337mb "${G1:0:$(($(R 11) * 2))}" m010.trn; refuse m010.trn -10 11
338# m011 truncation inside the file header.
339mb "${G1:0:40}" m011.trn; refuse m011.trn -3 0
340# m012 empty file.
341: >"$OUT/m012.trn"; refuse m012.trn -3 0
342# m013 truncation inside END.
343mb "${G1:0:$((${#G1} - 6))}" m013.trn; refuse m013.trn -3 11
344# m014 trailing byte after END.
345mb "${G1}00" m014.trn; refuse m014.trn -3 12
346# m015 duplicate: record 3 written twice.
347mb "${G1:0:$(($(R 4) * 2))}$(cut_hex "$G1" "$(R 3)" "${LEN[3]}")${G1:$(($(R 4) * 2))}" m015.trn; refuse m015.trn -7 4
348# m016 bit flip inside crumb 1 canonical bytes (record 5): its own crumb digest no longer matches.
349mb "$(flip "$G1" $(($(R 5) + 56 + 32 + 12)))" m016.trn; refuse m016.trn -9 5
350# m017 bit flip in END prev.
351mb "$(flip "$G1" $(($(R 11) + 24)))" m017.trn; refuse m017.trn -8 11
352# m018 bit flip in END record count.
353mb "$(flip "$G1" $(($(R 11) + 56)))" m018.trn; refuse m018.trn -7 11
354
355# ===========================================================================
356# Built mutants: rechained, so only the named check can catch them.
357# ===========================================================================
358H() { start "${1:-$SUB_WORLD}" "$(dig "run $2")" "${3:-1}" "${4:-0}" "${5:-}"; }
359# Header checks.
360H $SUB_WORLD m020 2; end; save m020.trn; refuse m020.trn -2 0 # unknown future schema
361H $SUB_WORLD m021 0; end; save m021.trn; refuse m021.trn -2 0 # schema 0
362H $SUB_WORLD m022 1 1; end; save m022.trn; refuse m022.trn -4 0 # header flags set
363H 0 m023; end; save m023.trn; refuse m023.trn -5 0 # producer 0
364H 11 m024; end; save m024.trn; refuse m024.trn -5 0 # producer unknown
365H $SUB_WORLD m025 1 0 "000000000100"; end; save m025.trn; refuse m025.trn -4 0 # header reserved
366# Record header checks.
367H $SUB_WORLD m030; rec 17 $SUB_WORLD "$(clock_read 1 1)" ""; end; save m030.trn; refuse m030.trn -5 1 # unknown type
368H $SUB_WORLD m031; rec 12 11 "$(clock_read 1 1)" ""; end; save m031.trn; refuse m031.trn -5 1 # unknown subsystem
369H $SUB_WORLD m032; rec 12 $SUB_WORLD "$(clock_read 1 1)" "" "" "" 1; end; save m032.trn; refuse m032.trn -4 1 # record reserved
370H $SUB_WORLD m033; rec 12 $SUB_WORLD "$(clock_read 1 1)" "" 2; end; save m033.trn; refuse m033.trn -7 1 # seq skips (omission at start)
371H $SUB_WORLD m034; rec 12 $SUB_WORLD "$(clock_read 1 1)" "" "" "$(dig other)"; end; save m034.trn; refuse m034.trn -8 1 # wrong prev
372# Check order: unknown type wins over a bad seq.
373H $SUB_WORLD m035; rec 17 $SUB_WORLD "$(clock_read 1 1)" "" 9; end; save m035.trn; refuse m035.trn -5 1
374# Check order: a bad seq wins over a bad prev.
375H $SUB_WORLD m036; rec 12 $SUB_WORLD "$(clock_read 1 1)" "" 9 "$(dig other)"; end; save m036.trn; refuse m036.trn -7 1
376# Identity longer than the limit, fully present: LENGTH, not SHAPE.
377HUGE=$(head -c 65537 /dev/zero | od -An -v -tx1 | tr -d ' \n')
378H $SUB_WORLD m037; rec 1 $SUB_WORLD "$HUGE" ""; end; save m037.trn; refuse m037.trn -3 1
379# Shape checks.
380H $SUB_WORLD m040; rec 1 $SUB_WORLD "$(sched 1 3 0 0 | cut -c1-62)" ""; end; save m040.trn; refuse m040.trn -6 1 # SCHED 31 bytes
381H $SUB_WORLD m041; rec 65535 $SUB_WORLD "$(h64 1)$(zeros 8)" ""; save m041.trn; refuse m041.trn -6 1 # END not subsystem 0
382H $SUB_WORLD m042; rec 12 $SUB_TRANSCRIPT "$(clock_read 1 1)" ""; end; save m042.trn; refuse m042.trn -6 1 # subsystem 0 off END
383H $SUB_WORLD m043; rec 7 $SUB_KERNEL "$(cap_transition 4 7 9 10 3 1)" ""; end; save m043.trn; refuse m043.trn -6 1 # cap op 7
384H $SUB_WORLD m044; rec 13 $SUB_RUNTIME "$(crash_boundary 2 1 "$(dig x)")" ""; end; save m044.trn; refuse m044.trn -6 1 # last durable >= own seq
385H $SUB_WORLD m045; rec 11 $SUB_EXTERNAL "$(external_input 1 1 "$BIG"00)" ""; end; save m045.trn; refuse m045.trn -6 1 # content 4097
386H $SUB_WORLD m046; rec 15 $SUB_WORLD "$(dig short | cut -c1-40)" ""; end; save m046.trn; refuse m046.trn -6 1 # crumb identity < 32 bytes
387CB9=$(crumb_canon 3 3 1 1 0 0 "$(h32 9)$(for i in 1 2 3 4 5 6 7 8 9; do objv "$i" 1 1 1; done)" "$(h32 0)" "$(h32 0)" 0 "$(h32 0)")
388H $SUB_WORLD m047; rec 15 $SUB_WORLD "$(rx_crumb "$CB9")" ""; end; save m047.trn; refuse m047.trn -6 1 # 9 inputs (digest valid)
389CBP=$(crumb_canon 3 3 1 1 0 0 "$(h32 0)" "$(h32 0)" "$(h32 0)" 0 "$(h32 1)$(h64 1)")
390H $SUB_WORLD m048; rec 15 $SUB_WORLD "$(rx_crumb "$CBP")" ""; end; save m048.trn; refuse m048.trn -6 1 # parent 1 < id 3 without its digest
391H $SUB_ARGUS m049; rec 16 $SUB_ARGUS "$(argus_rec "$E1" 2 "$Z32" "$(sha "$Z32$E1")")" ""; end; save m049.trn; refuse m049.trn -6 1 # chained flag 2
392H $SUB_WORLD m050; end "00"; save m050.trn; refuse m050.trn -6 1 # END with annotation
393# Reserved fields inside identities.
394H $SUB_WORLD m055; rec 7 $SUB_KERNEL "$(cap_transition 4 2 9 10 3 1 000100)" ""; end; save m055.trn; refuse m055.trn -4 1
395H $SUB_WORLD m056; rec 65535 $SUB_TRANSCRIPT "$(h64 1)$(h64 1)" ""; save m056.trn; refuse m056.trn -4 1
396H $SUB_ARGUS m057; rec 16 $SUB_ARGUS "$(argus_rec "$E1" 1 "$Z32" "" 00000000000001)" ""; end; save m057.trn; refuse m057.trn -4 1
397# END count.
398H $SUB_WORLD m058; rec 12 $SUB_WORLD "$(clock_read 1 1)" ""; rec 65535 $SUB_TRANSCRIPT "$(h64 5)$(zeros 8)" ""; save m058.trn; refuse m058.trn -7 2
399# Embedded digests.
400CBAD=$(crumb_canon 1 1 4294967295 0 0 0 "$(h32 0)" "$(h32 0)" "$(h32 1)$(objv 5 1 3 254)" 0 "$(h32 0)")
401H $SUB_WORLD m060; rec 15 $SUB_WORLD "$(rx_crumb "$CBAD" "$C1D")" ""; end; save m060.trn; refuse m060.trn -9 1 # crumb digest stale
402H $SUB_WORLD m061; rec 11 $SUB_EXTERNAL "$(external_input 1 1 "$(txt "hello transcripT")" "$(sha "$IN1")")" ""; end; save m061.trn; refuse m061.trn -9 1 # input content altered
403H $SUB_ARGUS m062; rec 16 $SUB_ARGUS "$(argus_rec "$E1" 1 "$Z32" "$(dig wrong)")" ""; end; save m062.trn; refuse m062.trn -9 1 # chain_after wrong
404H $SUB_ARGUS m063; rec 16 $SUB_ARGUS "$(argus_rec "$E1" 1 "$Z32")" ""; rec 16 $SUB_ARGUS "$(argus_rec "$E2" 1 "$Z32")" ""; end; save m063.trn; refuse m063.trn -9 2 # ARGUS event dropped between records 1 and 2
405H $SUB_ARGUS m064; rec 16 $SUB_ARGUS "$(argus_rec "$E3" 0 "$Z32" "$A1")" ""; end; save m064.trn; refuse m064.trn -9 1 # unchained event moved the chain
406# ARGUS stream with an event omitted, then rechained by the writer: the ARGUS
407# continuity check still catches it (g002 without record 2).
408start $SUB_ARGUS "$RUN2"
409rec 16 $SUB_ARGUS "$(argus_rec "$E1" 1 "$Z32")" ""
410rec 16 $SUB_ARGUS "$(argus_rec "$E3" 0 "$A2")" ""
411end; save m065.trn; refuse m065.trn -9 2
412
413# Compare against refused files.
414pair g001.trn m001.trn "refuse actual -7 event=3"
415pair m008.trn g001.trn "refuse expected -1 event=0"
416
417
418# ===========================================================================
419# Contract 0.2.0 (wire schema 3): causal and resource records, types 17, 18,
420# 19 and 21 (section 5.5). Type 20 is reserved and still refused. Sources:
421# aien-architecture docs/hardening/causal-id-join-v0.md (fa46a26) sections
422# 2.1, 3.1 to 3.3, 3.5 and 4; docs/hardening/resource-contract-v0.md
423# (ddc17b7) section 4. Everything below is appended, so every 0.1.0 vector
424# and manifest line above keeps its bytes.
425# ===========================================================================
426V2=3 # wire schema of contract 0.2.x
427{
428 echo "# Contract 0.2.0 (wire schema 3) vectors: causal and resource records, types 17 to 21."
429} >>"$OUT/expected.txt"
430{
431 echo "# Contract 0.2.0 (wire schema 3) pairs."
432} >>"$OUT/compare.txt"
433{
434 echo "# TRN1 0.2.0 join expectations (causal-id-join-v0 section 4, aien-architecture fa46a26)."
435 echo "# Every file here VERIFIES under TRN1 (see expected.txt); the join must refuse it."
436 echo "# Line: <file> JOIN_REFUSED reason=<CODE> run=<64 hex> event=<record position>"
437 echo "# The join set is that one file alone. No join implementation lives in this"
438 echo "# repository: these lines are NOT_RUN until a joiner (omega cut O3/O4,"
439 echo "# sovereign-core cut C1) checks them. The reference verifier does not read this file."
440 echo "# Generated by tools/make-corpus.sh; do not edit by hand."
441} >"$OUT/join.txt"
442jrefuse() { echo "$1 JOIN_REFUSED reason=$2 run=$3 event=$4" >>"$OUT/join.txt"; }
443
444# cause_id SUBSYSTEM LOCAL_KIND LOCAL ROOT_HEX (causal-id-join-v0 section 2.1)
445cause_id() { sha "$(txt AIEN_CAUSE_V0)$(h16 "$1")$(h32 "$2")$(h64 "$3")$4"; }
446# cause_rec CAUSE MODE LOCAL_KIND LOCAL ROOT_HEX (type 17, 80 bytes)
447cause_rec() { printf '%s' "$1$(h32 "$2")$(h32 "$3")$(h64 "$4")$5"; }
448# receipt_bind CAUSE FORMAT [RESERVED] (type 18, 40 bytes)
449receipt_bind() { printf '%s' "$1$(h32 "$2")$(h32 "${3:-0}")"; }
450# run_link RELATION PARENT_BRANCH PARENT_CREATE_CMP [RESERVED] (type 19, 48 bytes)
451run_link() { printf '%s' "$(h32 "$1")$(h32 "${4:-0}")$(h64 "$2")$3"; }
452# resource OP REASON FIELD UNIT CAUSE CONTRACT DECLARED USED [RESERVED] (type 21, 96 bytes)
453resource() { printf '%s' "$(h8 "$1")$(h8 "$2")$(h16 "$3")$(h32 "${9:-0}")$(h64 "$4")$5$6$(h64 "$7")$(h64 "$8")"; }
454MINT=1 ADOPT=2 CREF=3
455
456ROOT6=$(dig "sovcore request 1 bytes")
457CA=$(cause_id $SUB_RUNTIME 3 1 "$ROOT6") # minted by sovcore-runtime, local_kind 3, local 1
458CON6=$(dig "contract reaction 1")
459
460# g006: one sovcore request, start to receipt (producer sovcore-runtime).
461# MINT, a charge, a referenced branch, a referenced effect, a refund, and a
462# receipt bind whose receipt digest is in the annotation.
463RUN6=$(dig "run g006")
464g006() { # g006 RUN_ID RECEIPT_DIGEST
465 start $SUB_RUNTIME "$1" $V2
466 rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""
467 rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0)" ""
468 rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 0 0 "$Z32")" ""
469 rec 2 $SUB_KV "$(branch_create 2 0 1)" ""
470 rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 0 0 "$Z32")" ""
471 rec 9 $SUB_RUNTIME "$(effect_intent 1 2 4 10 "$(dig "effect g006 request")")" ""
472 rec 10 $SUB_RUNTIME "$(effect_commit 1 0 "$(dig "effect g006 result")")" ""
473 rec 21 $SUB_RUNTIME "$(resource 2 0 0 1 "$CA" "$CON6" 0 0)" ""
474 rec 18 $SUB_RUNTIME "$(receipt_bind "$CA" 3)" "$2"
475}
476g006 "$RUN6" "$(dig "receipt g006")"; end; save g006.trn; ok g006.trn 10 "$RUN6"
477G6=$T
478G6CMP=(); for i in $(seq 1 10); do G6CMP[i]=$(cmpd "$i"); done
479pair g006.trn g006.trn "MATCH through 10"
480
481# g008: replay of g006: other run id, other receipt digest (annotation). MATCHes.
482RUN8=$(dig "run g008 replay of g006")
483g006 "$RUN8" "$(dig "receipt g008")"; end; save g008.trn; ok g008.trn 10 "$RUN8"
484pair g006.trn g008.trn "MATCH through 10"
485
486# g007: a child World transcript. RUN_LINK as record 1 names g006's
487# BRANCH_CREATE (record 4, branch 2); the cause is ADOPTed (annotation: origin
488# run id, origin seq), then a cancel because the parent was cancelled.
489RUN7=$(dig "run g007 child of g006")
490start $SUB_RUNTIME "$RUN7" $V2
491rec 19 $SUB_RUNTIME "$(run_link 1 2 "${G6CMP[4]}")" "$RUN6$(h64 4)"
492rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $ADOPT 3 1 "$Z32")" "$RUN6$(h64 1)"
493rec 21 $SUB_RUNTIME "$(resource 4 2 1 2 "$CA" "$(dig "contract reaction 2")" 5 0)" ""
494end; save g007.trn; ok g007.trn 4 "$RUN7"
495
496# p003: top of every valid range: local_kind 4 (train run), REFUSE reason 4,
497# CANCEL reason 3, OVERRUN, OVER_OBSERVED on field 10 with a measured value in
498# the annotation, receipt format 1.
499CB=$(cause_id $SUB_SCHED 4 7 "$(dig "generation 0 digest")")
500start $SUB_SCHED "$(dig "run p003")" $V2
501rec 17 $SUB_SCHED "$(cause_rec "$CB" $MINT 4 7 "$(dig "generation 0 digest")")" ""
502rec 21 $SUB_SCHED "$(resource 3 4 7 3 "$CB" "$(dig "contract p003")" 8 0)" ""
503rec 21 $SUB_SCHED "$(resource 4 3 1 3 "$CB" "$(dig "contract p003")" 9 0)" ""
504rec 21 $SUB_SCHED "$(resource 5 0 9 3 "$CB" "$(dig "contract p003")" 16 17)" ""
505rec 21 $SUB_SCHED "$(resource 6 0 10 3 "$CB" "$(dig "contract p003")" 100 0)" "$(h64 140)"
506rec 18 $SUB_SCHED "$(receipt_bind "$CB" 1)" "$(dig "receipt p003")"
507end; save p003.trn; ok p003.trn 7 "$(dig "run p003")"
508
509# Forged 0.2 histories: valid chains (accepted alone), caught by comparison
510# with g006 and by the join (join.txt).
511div6() { pair g006.trn "$1" "DIVERGENCE event=$2 expected=${G6CMP[$2]} actual=$(cmpd "$2") subsystem=$3"; }
512CAX=$(flip "$CA" 0)
513# f007 cause bit flip in the charge (record 2), rechained.
514start $SUB_RUNTIME "$RUN6" $V2
515rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""
516rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CAX" "$CON6" 0 0)" ""
517end; save f007.trn; ok f007.trn 3 "$RUN6"; div6 f007.trn 2 sovcore-runtime
518jrefuse f007.trn REF_UNKNOWN "$RUN6" 2
519# f008 reorder: the charge written before its MINT, rechained.
520start $SUB_RUNTIME "$RUN6" $V2
521rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0)" ""
522rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""
523end; save f008.trn; ok f008.trn 3 "$RUN6"; div6 f008.trn 1 sovcore-runtime
524# The MINT comes after a record that names its cause: CAUSE_PLACEMENT at the
525# MINT (step 4 runs before step 7; aien-architecture#102 Q7).
526jrefuse f008.trn CAUSE_PLACEMENT "$RUN6" 2
527# f009 omission: g006 without its CAUSE MINT, renumbered, rechained.
528start $SUB_RUNTIME "$RUN6" $V2
529rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0)" ""
530rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 0 0 "$Z32")" ""
531rec 2 $SUB_KV "$(branch_create 2 0 1)" ""
532end; save f009.trn; ok f009.trn 4 "$RUN6"; div6 f009.trn 1 sovcore-runtime
533jrefuse f009.trn REF_UNKNOWN "$RUN6" 1
534
535# Join-only refusals (single file, TRN1 accepts each).
536J() { start $SUB_RUNTIME "$(dig "run $1")" $V2; }
537jr() { jrefuse "$1.trn" "$2" "$(dig "run $1")" "$3"; }
538J j001; rec 17 $SUB_RUNTIME "$(cause_rec "$CAX" $MINT 3 1 "$ROOT6")" ""; rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CAX" "$CON6" 0 0)" ""
539end; save j001.trn; ok j001.trn 3 "$(dig "run j001")"; jr j001 CAUSE_DIGEST 1 # minted cause does not recompute
540J j002; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""; rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0)" ""
541rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""; rec 21 $SUB_RUNTIME "$(resource 2 0 0 1 "$CA" "$CON6" 0 0)" ""
542end; save j002.trn; ok j002.trn 5 "$(dig "run j002")"; jr j002 DOUBLE_MINT 3 # same cause minted twice
543J j003; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""; rec 9 $SUB_RUNTIME "$(effect_intent 1 2 4 10 "$(dig "effect g006 request")")" ""
544end; save j003.trn; ok j003.trn 3 "$(dig "run j003")"; jr j003 REF_MISSING 2 # effect intent with no CAUSE REF before it
545J j004; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""; rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0)" ""
546rec 10 $SUB_RUNTIME "$(effect_commit 9 0 "$(dig "effect 9 result")")" ""
547end; save j004.trn; ok j004.trn 4 "$(dig "run j004")"; jr j004 COMMIT_ORPHAN 3 # commit with no intent
548J j005; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 1 "$ROOT6")" ""; rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0)" ""
549rec 18 $SUB_RUNTIME "$(receipt_bind "$CAX" 3)" "$(dig "receipt j005")"
550end; save j005.trn; ok j005.trn 4 "$(dig "run j005")"; jr j005 RECEIPT_CAUSE 3 # receipt bound to a cause not open
551
552# Built 0.2 refusals: rechained, so only the named check can catch them.
553V() { H "${1:-$SUB_RUNTIME}" "$2" $V2; }
554CM=$(cause_rec "$CA" $MINT 3 1 "$ROOT6")
555RS=$(resource 1 0 0 1 "$CA" "$CON6" 0 0)
556H $SUB_RUNTIME m070; rec 17 $SUB_RUNTIME "$CM" ""; end; save m070.trn; refuse m070.trn -5 1 # valid 0.2 CAUSE under a schema 1 header
557V "" m071; rec 20 $SUB_RUNTIME "$(zeros 160)" ""; end; save m071.trn; refuse m071.trn -5 1 # type 20 reserved in 0.2.0
558V "" m072; rec 17 $SUB_RUNTIME "${CM:0:158}" ""; end; save m072.trn; refuse m072.trn -6 1 # CAUSE 79 bytes
559V "" m073; rec 21 $SUB_RUNTIME "$(h8 1)$(h8 0)$(h16 0)$(h32 0)$(h64 1)$(h64 7)$CON6$(h64 0)$(h64 0)" ""; end; save m073.trn; refuse m073.trn -6 1 # RESOURCE with the old 8-byte cause (72 bytes)
560V "" m074; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" 4 3 1 "$ROOT6")" ""; end; save m074.trn; refuse m074.trn -6 1 # mode 4
561V "" m075; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 0 1 "$ROOT6")" ""; end; save m075.trn; refuse m075.trn -6 1 # MINT local_kind 0
562V "" m076; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $ADOPT 5 1 "$Z32")" ""; end; save m076.trn; refuse m076.trn -6 1 # ADOPT local_kind 5
563V "" m077; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $MINT 3 0 "$ROOT6")" ""; end; save m077.trn; refuse m077.trn -6 1 # MINT local 0
564V "" m078; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $ADOPT 3 1 "$ROOT6")" ""; end; save m078.trn; refuse m078.trn -4 1 # ADOPT root digest not zero
565V "" m079; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 0 0 "$(flip "$Z32" 31)")" ""; end; save m079.trn; refuse m079.trn -4 1 # REF root digest not zero
566V "" m080; rec 18 $SUB_RUNTIME "$(receipt_bind "$CA" 4)" ""; end; save m080.trn; refuse m080.trn -6 1 # receipt format 4
567V "" m081; rec 18 $SUB_RUNTIME "$(receipt_bind "$CA" 3 1)" ""; end; save m081.trn; refuse m081.trn -4 1 # receipt bind reserved
568V "" m082; rec 19 $SUB_RUNTIME "$(run_link 2 2 "${G6CMP[4]}")" ""; end; save m082.trn; refuse m082.trn -6 1 # relation 2
569V "" m083; rec 19 $SUB_RUNTIME "$(run_link 1 2 "${G6CMP[4]}" 1)" ""; end; save m083.trn; refuse m083.trn -4 1 # run link reserved
570V "" m084; rec 17 $SUB_RUNTIME "$CM" ""; rec 19 $SUB_RUNTIME "$(run_link 1 2 "${G6CMP[4]}")" ""; end; save m084.trn; refuse m084.trn -6 2 # RUN_LINK not record 1
571V "" m085; rec 21 $SUB_RUNTIME "$(resource 7 0 0 1 "$CA" "$CON6" 0 0)" ""; end; save m085.trn; refuse m085.trn -6 1 # op 7
572V "" m086; rec 21 $SUB_RUNTIME "$(resource 3 5 0 1 "$CA" "$CON6" 0 0)" ""; end; save m086.trn; refuse m086.trn -6 1 # REFUSE reason 5
573V "" m087; rec 21 $SUB_RUNTIME "$(resource 1 1 0 1 "$CA" "$CON6" 0 0)" ""; end; save m087.trn; refuse m087.trn -6 1 # CHARGE with a reason
574V "" m088; rec 21 $SUB_RUNTIME "$(resource 5 0 11 1 "$CA" "$CON6" 0 0)" ""; end; save m088.trn; refuse m088.trn -6 1 # field 11
575V "" m089; rec 21 $SUB_RUNTIME "$(resource 1 0 0 1 "$CA" "$CON6" 0 0 1)" ""; end; save m089.trn; refuse m089.trn -4 1 # resource reserved
576V "" m090; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 9 0 "$ROOT6")" ""; end; save m090.trn; refuse m090.trn -6 1 # check order: SHAPE before NONCANONICAL
577
578# Byte damage on g006 (not rechained).
579g006 "$RUN6" "$(dig "receipt g006")" >/dev/null; end # refresh OFF/LEN for g006
580# m091 cause bit flip inside the charge (record 2): record 3's prev breaks.
581mb "$(flip "$G6" $(($(R 2) + 56 + 16)))" m091.trn; refuse m091.trn -8 3
582# m092 reorder: records 1 (MINT) and 2 (charge) swapped.
583mb "${G6:0:$(($(R 1) * 2))}$(cut_hex "$G6" "$(R 2)" "${LEN[2]}")$(cut_hex "$G6" "$(R 1)" "${LEN[1]}")${G6:$(($(R 3) * 2))}" m092.trn; refuse m092.trn -7 1
584# CAUSE REF carries local_kind 0 and local 0 exactly (aien-architecture#102 Q3).
585V "" m093; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 3 0 "$Z32")" ""; end; save m093.trn; refuse m093.trn -6 1 # REF local_kind 3
586V "" m094; rec 17 $SUB_RUNTIME "$(cause_rec "$CA" $CREF 0 5 "$Z32")" ""; end; save m094.trn; refuse m094.trn -6 1 # REF local 5
587echo "corpus written to $OUT: $(ls "$OUT"/*.trn | wc -l) transcripts"