interplane.Get Omega
Read in your language

sovereign-intelligence

Front door to Drake Stapleton's sovereign stack.

Brought by drakestapleton

branch main Branches Tags History

sovereign-intelligence / gpu / cuda-crack / check / check.sh

83 lines · 3963 bytes Raw Blame History
1#!/bin/sh
2# Rebuild the 70 chip-run kernels from isa/sm121-forms.txt alone and compare sha256 with the
3# chip receipt kernels-om.sha256, after checking the D (operand field) records against the F records.
4# Then four negative controls that must fail.
5# Usage: OMC=/path/to/omc check/check.sh (run from the repository root)
6set -eu
7OMC=${OMC:?set OMC to the pinned omega-mv seed compiler}
8E3=receipts/cudapp/evidence/CUDAPP-OM-ENCODER/chip-20261027T080240Z
9T=isa/sm121-forms.txt
10tmp=$(mktemp -d)
11trap 'rm -rf "$tmp"' EXIT
12"$OMC" < check/reencode.om > "$tmp/reencode"
13chmod +x "$tmp/reencode"
14
15# rebuild every kernel from table $1 into directory $2; prints "kernels instructions unmatched"
16rebuild() {
17 mkdir -p "$2"
18 n=0; i=0; u=0
19 for k in "$E3"/kernels-om/*.bin; do
20 b=$(basename "$k")
21 { cat "$1"; printf 'E\n'; cat "$k"; } | "$tmp/reencode" > "$2/$b" 2> "$tmp/err" || true
22 read ni nu < "$tmp/err"
23 n=$((n + 1)); i=$((i + ni)); u=$((u + nu))
24 done
25 echo "$n $i $u"
26}
27
28# check table $1's D records against its F records; prints reencode's exit code (0 consistent, 7 not)
29tcheck() {
30 rc=0
31 { cat "$1"; printf 'E\n'; } | "$tmp/reencode" > /dev/null 2>&1 || rc=$?
32 echo "$rc"
33}
34
35echo "== real tables: $T sha256 $(sha256sum "$T" | cut -d' ' -f1)"
36rc=$(tcheck "$T")
37echo "D records vs F records: reencode exit $rc"
38if [ "$rc" -eq 0 ]; then
39 echo "PASS: fields never overlap, field union = form mask, every width>0 field is exactly its bit span"
40else
41 echo "FAIL: D records disagree with F records"; exit 1
42fi
43set -- $(rebuild "$T" "$tmp/out")
44echo "kernels $1 instructions $2 unmatched $3"
45(cd "$tmp/out" && sha256sum *.bin) > "$tmp/out.sha256"
46if cmp -s "$tmp/out.sha256" "$E3/kernels-om.sha256"; then
47 echo "PASS: all $1 rebuilt kernels match kernels-om.sha256 byte for byte"
48else
49 echo "FAIL: rebuilt kernels differ from kernels-om.sha256"; exit 1
50fi
51
52echo "== mutant 1: bit 0 of word 0 flipped in every form that has the NOP's fixed bits and mask"
53nop=$(awk '$1=="F" && $3==255 {print $5,$6,$7,$8,$9,$10}' "$T")
54awk -v key="$nop" '$1=="F" && ($5" "$6" "$7" "$8" "$9" "$10)==key {if ($5 % 2 == 1) $5 = $5 - 1; else $5 = $5 + 1} {print}' "$T" > "$tmp/mut1.txt"
55echo "mutated forms: $(diff "$T" "$tmp/mut1.txt" | grep -c '^>' || true)"
56set -- $(rebuild "$tmp/mut1.txt" "$tmp/mut1")
57(cd "$tmp/mut1" && sha256sum *.bin) > "$tmp/mut1.sha256"
58bad=$(diff "$tmp/mut1.sha256" "$E3/kernels-om.sha256" | grep -c '^<' || true)
59echo "kernels $1 instructions $2 unmatched $3 sha-mismatched kernels $bad"
60if [ "$bad" -gt 0 ]; then echo "PASS: mutant table caught"; else echo "FAIL: mutant table not caught"; exit 1; fi
61
62echo "== mutant 2: bit 0 of word 0 flipped in the first instruction of the first kernel"
63k=$(ls "$E3"/kernels-om/*.bin | head -1)
64b0=$(od -An -tu1 -N1 "$k" | tr -d ' ')
65printf "$(printf '\\%03o' $((b0 ^ 1)))" > "$tmp/mut2.bin"
66tail -c +2 "$k" >> "$tmp/mut2.bin"
67rc=0
68{ cat "$T"; printf 'E\n'; cat "$tmp/mut2.bin"; } | "$tmp/reencode" > /dev/null 2> "$tmp/err2" || rc=$?
69echo "reencode exit $rc, instructions unmatched: $(cat "$tmp/err2")"
70if [ "$rc" -eq 4 ]; then echo "PASS: corrupted instruction matches no form"; else echo "FAIL: corrupted instruction accepted"; exit 1; fi
71
72echo "== mutant 3: width of the first D record with width > 1 reduced by one"
73awk 'd == 0 && $1=="D" && $8 > 1 {$8 = $8 - 1; d = 1} {print}' "$T" > "$tmp/mut3.txt"
74rc=$(tcheck "$tmp/mut3.txt")
75echo "reencode exit $rc"
76if [ "$rc" -eq 7 ]; then echo "PASS: wrong field width caught"; else echo "FAIL: wrong field width accepted"; exit 1; fi
77
78echo "== mutant 4: lowest bit cleared in the mask of the first D record with width > 0"
79awk 'd == 0 && $1=="D" && $8 > 0 {w = int($7 / 32); $(4 + w) = $(4 + w) - 2 ^ ($7 % 32); d = 1} {print}' "$T" > "$tmp/mut4.txt"
80rc=$(tcheck "$tmp/mut4.txt")
81echo "reencode exit $rc"
82if [ "$rc" -eq 7 ]; then echo "PASS: wrong field mask caught"; else echo "FAIL: wrong field mask accepted"; exit 1; fi
83echo "ALL CHECKS PASS"