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
aien-train / tests / omegese45 / demo / recheck-evidence.sh
| 1 | #!/bin/sh |
| 2 | # SPDX-License-Identifier: AGPL-3.0-only |
| 3 | # aien-train #45 demo: re-run the independent checker over committed demo receipts. |
| 4 | # |
| 5 | # sh tests/omegese45/demo/recheck-evidence.sh [RUN ...] |
| 6 | # |
| 7 | # RUN a directory under evidence/OMEGESE45/demo/ (default: the current receipts |
| 8 | # run-reference-v13 run-trained-v13, docs/omegese45/DEMO.md "Files"). |
| 9 | # For every checked case of every RUN (each cases/*/ and cases/tampered/{receipt,english}/ |
| 10 | # that holds check.out), the unchanged eval/omegese45/check-demo runs on the committed |
| 11 | # case directory; its stdout+stderr must equal the committed check.out byte for byte and |
| 12 | # its exit code must equal the committed check.rc. The committed runs were produced with |
| 13 | # the runtime identity pinned in check-demo, so a fresh clone can verify them without |
| 14 | # that runtime or any private key (EVAL-CONTRACT.md ยง10). |
| 15 | # Two negative controls run on scratch copies and must be detected: |
| 16 | # flip byte 200 of happy-mm's MJR1 receipt: check-demo must fail row1.mjr1.signature; |
| 17 | # edit one byte of a committed check.out: the byte comparison must report a difference. |
| 18 | # This re-verifies recorded receipts; it does not execute the demo (run-demo.sh does). |
| 19 | # Exits: 0 OE45_RECHECK_PASS, 1 OE45_RECHECK_FAIL, 68 checker not runnable, 2 usage. |
| 20 | set -u |
| 21 | export PYTHONDONTWRITEBYTECODE=1 # the checker leaves no bytecode in the tree |
| 22 | HERE=$(cd "$(dirname "$0")" && pwd) |
| 23 | REPO=$(cd "$HERE/../../.." && pwd) |
| 24 | EV=$REPO/evidence/OMEGESE45/demo |
| 25 | CHECK=$REPO/eval/omegese45/check-demo |
| 26 | [ $# -gt 0 ] || set -- run-reference-v13 run-trained-v13 |
| 27 | python3 -c 'import sys; sys.exit(0 if sys.version_info >= (3, 8) else 1)' 2>/dev/null \ |
| 28 | || { echo "OE45_RECHECK_NOT_RUN python3 >= 3.8 missing"; exit 68; } |
| 29 | [ -f "$CHECK" ] || { echo "OE45_RECHECK_NOT_RUN $CHECK missing"; exit 68; } |
| 30 | S=$(mktemp -d) || exit 68 |
| 31 | trap 'rm -rf "$S"' EXIT |
| 32 | |
| 33 | same() { # case dir -> 0 when check-demo reproduces check.out and check.rc |
| 34 | python3 "$CHECK" "$1" > "$S/out" 2>&1; r=$? |
| 35 | [ -f "$1/check.out" ] && [ -f "$1/check.rc" ] && [ "$r" = "$(cat "$1/check.rc")" ] && cmp -s "$S/out" "$1/check.out" |
| 36 | } |
| 37 | |
| 38 | n=0; bad="" |
| 39 | for run in "$@"; do |
| 40 | case $run in */*|.*|"") echo "recheck-evidence: RUN must be a directory name under $EV" >&2; exit 2 ;; esac |
| 41 | [ -d "$EV/$run/cases" ] || { echo "recheck-evidence: $EV/$run/cases missing" >&2; exit 2; } |
| 42 | m=0 |
| 43 | for out in "$EV/$run"/cases/*/check.out "$EV/$run"/cases/tampered/*/check.out; do |
| 44 | [ -f "$out" ] || continue |
| 45 | c=$(dirname "$out"); id=${c#"$EV/"} |
| 46 | m=$((m + 1)); n=$((n + 1)) |
| 47 | if same "$c"; then echo "RECHECK SAME $id rc=$(cat "$c/check.rc") $(tail -n 1 "$c/check.out")" |
| 48 | else echo "RECHECK DIFF $id rc=$(cat "$c/check.rc" 2>/dev/null)"; diff "$c/check.out" "$S/out" | sed 's/^/ /'; bad="$bad $id"; fi |
| 49 | done |
| 50 | [ "$m" -gt 0 ] || { echo "RECHECK EMPTY $run (no checked case)"; bad="$bad $run"; } |
| 51 | done |
| 52 | |
| 53 | # negative control 1: a flipped receipt byte must break the signature check |
| 54 | first=$EV/$1/cases/happy-mm |
| 55 | cp -R "$first" "$S/flip" |
| 56 | mj=$(ls "$S/flip/artifacts/"*.mjr1 2>/dev/null | head -n 1) |
| 57 | if [ -n "$mj" ]; then |
| 58 | b=$(od -An -tu1 -j 200 -N 1 "$mj" | tr -d ' ') |
| 59 | printf "$(printf '\\%03o' $(( (b + 1) % 256 )))" | dd of="$mj" bs=1 seek=200 conv=notrunc 2>/dev/null |
| 60 | python3 "$CHECK" "$S/flip" > "$S/flip.out" 2>&1; r=$? |
| 61 | if [ $r -eq 1 ] && grep -q '^CHECK row1.mjr1.signature FAIL' "$S/flip.out"; then echo "CONTROL flip CAUGHT rc=$r $(tail -n 1 "$S/flip.out")" |
| 62 | else echo "CONTROL flip MISSED rc=$r"; bad="$bad control-flip"; fi |
| 63 | else echo "CONTROL flip MISSED (no MJR1 receipt in $1/cases/happy-mm)"; bad="$bad control-flip"; fi |
| 64 | |
| 65 | # negative control 2: an edited committed check.out must not compare equal |
| 66 | cp -R "$first" "$S/edit" |
| 67 | sed '1s/PASS/PAS5/' "$S/edit/check.out" > "$S/edit.t" && mv "$S/edit.t" "$S/edit/check.out" |
| 68 | if cmp -s "$S/edit/check.out" "$first/check.out"; then echo "CONTROL edit MISSED (edit did not change check.out)"; bad="$bad control-edit" |
| 69 | elif same "$S/edit"; then echo "CONTROL edit MISSED (comparison accepted an edited check.out)"; bad="$bad control-edit" |
| 70 | else echo "CONTROL edit CAUGHT"; fi |
| 71 | |
| 72 | if [ -z "$bad" ]; then echo "OE45_RECHECK_PASS runs=$# cases=$n controls=2"; exit 0; fi |
| 73 | echo "OE45_RECHECK_FAIL$bad" |
| 74 | exit 1 |