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 / tests / si19 / run-omexp.sh

204 lines · 9630 bytes Raw Blame History
1#!/bin/sh
2# SPDX-License-Identifier: AGPL-3.0-only
3# aien-train#24 ORIG-1 host glue (POSIX sh, disclosed): materialize the pinned sources,
4# verify SHA-256, build the omexp test and driver with the pinned seeded compiler, run the
5# admission/refusal tests, generate the SYNTHETIC fixture, admit it, and (when RECORDS is
6# set) admit the local owner dataset. Every check and verdict is in the .om units.
7# Host CPU only. No GPU, network, service or model process is touched.
8set -u
9ROOT=$(cd "$(dirname "$0")/../.." && pwd)
10OUT=${OUT:-$ROOT/evidence/SI19-ORIG1/run}
11OMC=${OMC:-$HOME/workspace/omega-toc/seed/out/omc}
12OMC2=${OMC2:-$HOME/workspace/omega-seedqual-20261025/seed/out/omc}
13BRIDGE=${OMEGA_BRIDGE_GIT:-$HOME/workspace/omega-bridge}
14OMEGA=${OMEGA_MV_GIT:-$HOME/workspace/omega}
15QUIET=${QUIET:-quiet-build}
16BUILD=${BUILD:-$(mktemp -d "${TMPDIR:-/tmp}/si19orig1.XXXXXX")}
17RECORDS=${RECORDS:-}
18OMC_SHA=191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9
19mkdir -p "$OUT" "$BUILD/deps"
20SUM="$OUT/summary.txt"
21: > "$SUM"
22note() { echo "$*" | tee -a "$SUM"; }
23fail() { note "SI19_ORIG1_RUN_FAIL $*"; exit 1; }
24
25note "build_dir=$BUILD"
26note "source_commit=$(git -C "$ROOT" rev-parse HEAD)"
27note "host=$(uname -srm)"
28git -C "$BRIDGE" show 7e1d0d61755ec1a0bbf20941a18379861b5b9d0d:native/ref32/add32.om > "$BUILD/deps/add32.om" || fail materialize add32
29git -C "$BRIDGE" show 7e1d0d61755ec1a0bbf20941a18379861b5b9d0d:native/ref32/mul32.om > "$BUILD/deps/mul32.om" || fail materialize mul32
30git -C "$OMEGA" show 3a995ba8dace538c1532c747d829ca6e4a73582d:native/ecosystem663/metadata.om > "$BUILD/deps/metadata.om" || fail materialize metadata
31git -C "$ROOT" show c9782bfdcf1885082d1fa6c483473f2a514096ad:native/ecosystem6/affine.om > "$BUILD/deps/affine.om" || fail materialize affine
32(cd "$BUILD/deps" && sha256sum -c "$ROOT/docs/si19/deps.sha256") > "$OUT/deps-check.txt" 2>&1 || fail dependency hash
33set -- $(sha256sum "$OMC")
34[ "$1" = "$OMC_SHA" ] || fail "compiler hash $1"
35note "compiler_sha256=$1"
36
37LIB="$BUILD/deps/add32.om $BUILD/deps/mul32.om $BUILD/deps/metadata.om $BUILD/deps/affine.om $ROOT/native/si19/fixture.om $ROOT/native/si19/world.om $ROOT/native/si19/omexp.om $ROOT/native/si19/omexpfix.om"
38
39# build NAME CALLER [LIBRARY...]: compile one concatenated unit; status in OUT.
40build() {
41 name=$1; caller=$2; shift 2
42 [ $# -gt 0 ] || set -- $LIB
43 cat "$@" "$caller" > "$BUILD/$name.om"
44 "$QUIET" "$OMC" < "$BUILD/$name.om" > "$BUILD/$name.elf" 2> "$OUT/$name.compile.stderr"
45 rc=$?
46 echo "$rc" > "$OUT/$name.compile.rc"
47 [ "$rc" -eq 0 ] || return "$rc"
48 head -c 4 "$BUILD/$name.elf" | od -An -c | grep -q 'E L F' || return 70
49 chmod 700 "$BUILD/$name.elf"
50}
51
52ms() { date +%s%N; }
53
54build omexp-test "$ROOT/tests/si19/omexp-test.om" || fail compile omexp-test
55build omexp "$ROOT/native/si19/omexpmain.om" || fail compile omexp
56if [ -x "$OMC2" ]; then
57 "$QUIET" "$OMC2" < "$BUILD/omexp-test.om" > "$BUILD/omexp-test-r6.elf" 2> "$OUT/omexp-test-r6.compile.stderr"
58 echo $? > "$OUT/omexp-test-r6.compile.rc"
59 chmod 700 "$BUILD/omexp-test-r6.elf"
60 note "r6_compiler_sha256=$(sha256sum "$OMC2" | cut -c1-64) compile_rc=$(cat "$OUT/omexp-test-r6.compile.rc")"
61fi
62
63t0=$(ms)
64"$BUILD/omexp-test.elf" > "$OUT/omexp-test.stdout" 2> "$OUT/omexp-test.stderr"
65rc=$?; t1=$(ms)
66echo "$rc" > "$OUT/omexp-test.rc"
67note "omexp-test rc=$rc wall_ms=$(( (t1 - t0) / 1000000 )) $(cat "$OUT/omexp-test.stdout")"
68[ "$rc" -eq 0 ] || fail omexp-test
69if [ -x "$BUILD/omexp-test-r6.elf" ]; then
70 "$BUILD/omexp-test-r6.elf" > "$OUT/omexp-test-r6.stdout" 2> "$OUT/omexp-test-r6.stderr"
71 echo $? > "$OUT/omexp-test-r6.rc"
72 note "omexp-test-r6 rc=$(cat "$OUT/omexp-test-r6.rc") $(cat "$OUT/omexp-test-r6.stdout")"
73fi
74
75ALLOW=${ALLOW:-$ROOT/docs/si19/orig1-datasets.txt}
76allow_block() { { cat "$ALLOW"; head -c 4096 /dev/zero; } | head -c 4096; }
77
78# gen SEED COUNT NAME: the SYNTHETIC fixture to BUILD/NAME.bin
79gen() {
80 { printf 'G'; le8 "$1"; le8 "$2"; } | "$BUILD/omexp.elf" 3> "$BUILD/$3.bin" > "$OUT/gen-$3.stdout" 2> "$OUT/gen-$3.stderr"
81 rc=$?
82 echo "$rc" > "$OUT/gen-$3.rc"
83 note "gen-$3 rc=$rc $(tr '\n' ' ' < "$OUT/gen-$3.stdout")"
84 return "$rc"
85}
86# le8 N: 8 little-endian bytes of N using only POSIX tools.
87le8() {
88 v=$1; i=0
89 while [ $i -lt 8 ]; do
90 printf "\\$(printf '%03o' $((v % 256)))"
91 v=$((v / 256)); i=$((i + 1))
92 done
93}
94
95# inspect NAME FILE: admit a record file and print the baselines.
96inspect() {
97 t0=$(ms)
98 { printf 'I'; allow_block; cat "$2"; } | "$BUILD/omexp.elf" > "$OUT/inspect-$1.stdout" 2> "$OUT/inspect-$1.stderr"
99 rc=$?; t1=$(ms)
100 echo "$rc" > "$OUT/inspect-$1.rc"
101 note "inspect-$1 rc=$rc wall_ms=$(( (t1 - t0) / 1000000 ))"
102 return "$rc"
103}
104# v2 NAME FILE: v2 admission (ORIG1-CONTRACT-v2.md) with counted refusal reasons and splits.
105v2() {
106 t0=$(ms)
107 { printf 'V'; allow_block; cat "$2"; } | "$BUILD/omexp.elf" > "$OUT/v2-$1.stdout" 2> "$OUT/v2-$1.stderr"
108 rc=$?; t1=$(ms)
109 echo "$rc" > "$OUT/v2-$1.rc"
110 note "v2-$1 rc=$rc wall_ms=$(( (t1 - t0) / 1000000 ))"
111 return "$rc"
112}
113
114gen 7 780 fixture-7-780 || fail gen
115inspect fixture "$BUILD/fixture-7-780.bin" || fail inspect fixture
116cat "$OUT/inspect-fixture.stdout" | tee -a "$SUM"
117v2 fixture "$BUILD/fixture-7-780.bin" || fail v2 fixture
118cat "$OUT/v2-fixture.stdout" | tee -a "$SUM"
119printf 'S' | "$BUILD/omexp.elf" > "$OUT/splits.txt" 2> "$OUT/splits.stderr" || fail splits
120cmp -s "$OUT/splits.txt" "$ROOT/docs/si19/orig1-v2-splits.txt" || fail "split table differs from docs/si19/orig1-v2-splits.txt"
121note "v2_split_table=$(sha256sum "$OUT/splits.txt" | cut -c1-64) families=$(wc -l < "$OUT/splits.txt") identical_to_docs=yes"
122
123# Refusals through the process path: a foreign file and a damaged record.
124head -c 256 /dev/zero > "$BUILD/zero.bin"
125inspect zero "$BUILD/zero.bin"
126[ "$?" -eq 66 ] || fail zero file admitted
127{ cat "$BUILD/fixture-7-780.bin"; head -c 256 /dev/zero; } > "$BUILD/unlisted.bin"
128inspect unlisted "$BUILD/unlisted.bin"
129[ "$?" -eq 66 ] || fail unlisted damaged file admitted
130cp "$BUILD/fixture-7-780.bin" "$BUILD/forged.bin"
131printf '\001' | dd of="$BUILD/forged.bin" bs=1 seek=248 conv=notrunc 2> /dev/null
132inspect forged "$BUILD/forged.bin"
133[ "$?" -eq 66 ] || fail forged mismatch admitted
134printf '\001' | dd of="$BUILD/forged.bin" bs=1 seek=248 conv=notrunc 2> /dev/null
135cp "$BUILD/fixture-7-780.bin" "$BUILD/unauth.bin"
136printf '\001' | dd of="$BUILD/unauth.bin" bs=1 seek=88 conv=notrunc 2> /dev/null
137inspect unauth "$BUILD/unauth.bin"
138[ "$?" -eq 67 ] || fail unlisted hash admitted
139cat "$OUT/inspect-zero.stdout" "$OUT/inspect-unlisted.stdout" "$OUT/inspect-forged.stdout" "$OUT/inspect-unauth.stdout" | tee -a "$SUM"
140
141if [ -n "$RECORDS" ]; then
142 note "owner_records=$RECORDS sha256=$(sha256sum "$RECORDS" | cut -c1-64) bytes=$(wc -c < "$RECORDS")"
143 inspect owner "$RECORDS" || fail inspect owner
144 cat "$OUT/inspect-owner.stdout" | tee -a "$SUM"
145 v2 owner "$RECORDS" || fail v2 owner
146 cat "$OUT/v2-owner.stdout" | tee -a "$SUM"
147else
148 note "owner_records=NOT_RUN (RECORDS unset)"
149fi
150
151# Leakage audit (mode A, local analysis): AUDIT_A = the earlier file, AUDIT_B = the later one.
152if [ -n "${AUDIT_A:-}" ] && [ -n "${AUDIT_B:-}" ]; then
153 na=$(( $(wc -c < "$AUDIT_A") / 256 ))
154 { printf 'A'; le8 "$na"; cat "$AUDIT_A" "$AUDIT_B"; } | "$BUILD/omexp.elf" > "$OUT/audit.stdout" 2> "$OUT/audit.stderr"
155 rc=$?; echo "$rc" > "$OUT/audit.rc"
156 note "audit rc=$rc a_sha256=$(sha256sum "$AUDIT_A" | cut -c1-64) b_sha256=$(sha256sum "$AUDIT_B" | cut -c1-64)"
157 cat "$OUT/audit.stdout" | tee -a "$SUM"
158 [ "$rc" -eq 0 ] || fail audit
159else
160 note "audit=NOT_RUN (AUDIT_A/AUDIT_B unset)"
161fi
162
163# Fault injection: each altered unit must compile and fail the unchanged test.
164i=0
165while IFS='|' read -r file orig alt; do
166 [ -n "$file" ] || continue
167 i=$((i + 1))
168 src="$ROOT/native/si19/$file"
169 n=$(grep -c -x -F -- "$orig" "$src")
170 [ "$n" -eq 1 ] || fail "mutant$i matches $n"
171 mdir="$BUILD/mutant$i"; mkdir -p "$mdir"
172 awk -v o="$orig" -v a="$alt" '$0 == o { print a; next } { print }' "$src" > "$mdir/$file"
173 mlib=""
174 for f in $LIB; do
175 if [ "$(basename "$f")" = "$file" ]; then mlib="$mlib $mdir/$file"; else mlib="$mlib $f"; fi
176 done
177 build "mutant$i" "$ROOT/tests/si19/omexp-test.om" $mlib || fail "mutant$i compile"
178 "$BUILD/mutant$i.elf" > "$OUT/mutant$i.stdout" 2> "$OUT/mutant$i.stderr"
179 rc=$?
180 echo "$rc" > "$OUT/mutant$i.rc"
181 note "mutant$i $file rc=$rc $(cat "$OUT/mutant$i.stdout") :: $alt"
182 [ "$rc" -eq 1 ] || fail "mutant$i survived"
183done <<'EOF'
184omexp.om|if ne oxword r 31 0|if ne oxword r 31 1
185omexp.om|if ne oxword r add 24 a 1|if ne oxword r add 24 a 0
186omexp.om|ret -11|ret 0
187omexp.om|if le oxseq r oxseq sub r 1|if lt oxseq r oxseq sub r 1
188omexp.om|if and eq b 82 eq k 7|if and eq b 82 eq k 8
189omexp.om|put XF 3 long shr mul lm ln 8|put XF 3 long shr mul lm lm 8
190omexp.om|if ne oxword r 12 31|if eq oxword r 12 0
191omexp.om|d = true|d = false
192omexp.om|if or gt oxfam r 5 gt oxcore r 1|if or gt oxfam r 5 gt oxcore r 2
193omexp.om|ret oxhspl oxfl oxm r oxfl oxn r|ret rem oxfam r 3
194omexp.om|if ge oxword r add 16 a 1099511627776|if ge oxword r add 16 a 1099511627777
195omexp.om|ret int -11|ret 0
196omexp.om|if ge oxseq sub r 1 oxseq r|if gt oxseq sub r 1 oxseq r
197omexp.om|ret eq oxpress q p|ret true
198omexp.om|ret and eq oxcore q oxcore r eq oxpress q oxpress r|ret eq oxcore q oxcore r
199omexp.om|if eq oxbest q oxbest r|if ne oxbest q oxbest r
200EOF
201
202(cd "$OUT" && sha256sum -- *.stdout *.rc *.compile.stderr deps-check.txt) > "$OUT/raw.sha256"
203(cd "$BUILD" && sha256sum -- *.bin omexp.elf omexp-test.elf omexp.om omexp-test.om) > "$OUT/build.sha256"
204note "SI19_ORIG1_RUN_PASS"