Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/cuda-crack/blob/main/check/check.sh # cuda-crack I broke CUDA: GB10 sm_121 machine code without the CUDA toolkit - method, encoder tables, receipts Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `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) 6 set -eu 7 OMC=${OMC:?set OMC to the pinned omega-mv seed compiler} 8 E3=receipts/cudapp/evidence/CUDAPP-OM-ENCODER/chip-20261027T080240Z 9 T=isa/sm121-forms.txt 10 tmp=$(mktemp -d) 11 trap 'rm -rf "$tmp"' EXIT 12 "$OMC" < check/reencode.om > "$tmp/reencode" 13 chmod +x "$tmp/reencode" 14 15 # rebuild every kernel from table $1 into directory $2; prints "kernels instructions unmatched" 16 rebuild() { 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) 29 tcheck() { 30 rc=0 31 { cat "$1"; printf 'E\n'; } | "$tmp/reencode" > /dev/null 2>&1 || rc=$? 32 echo "$rc" 33 } 34 35 echo "== real tables: $T sha256 $(sha256sum "$T" | cut -d' ' -f1)" 36 rc=$(tcheck "$T") 37 echo "D records vs F records: reencode exit $rc" 38 if [ "$rc" -eq 0 ]; then 39 echo "PASS: fields never overlap, field union = form mask, every width>0 field is exactly its bit span" 40 else 41 echo "FAIL: D records disagree with F records"; exit 1 42 fi 43 set -- $(rebuild "$T" "$tmp/out") 44 echo "kernels $1 instructions $2 unmatched $3" 45 (cd "$tmp/out" && sha256sum *.bin) > "$tmp/out.sha256" 46 if cmp -s "$tmp/out.sha256" "$E3/kernels-om.sha256"; then 47 echo "PASS: all $1 rebuilt kernels match kernels-om.sha256 byte for byte" 48 else 49 echo "FAIL: rebuilt kernels differ from kernels-om.sha256"; exit 1 50 fi 51 52 echo "== mutant 1: bit 0 of word 0 flipped in every form that has the NOP's fixed bits and mask" 53 nop=$(awk '$1=="F" && $3==255 {print $5,$6,$7,$8,$9,$10}' "$T") 54 awk -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" 55 echo "mutated forms: $(diff "$T" "$tmp/mut1.txt" | grep -c '^>' || true)" 56 set -- $(rebuild "$tmp/mut1.txt" "$tmp/mut1") 57 (cd "$tmp/mut1" && sha256sum *.bin) > "$tmp/mut1.sha256" 58 bad=$(diff "$tmp/mut1.sha256" "$E3/kernels-om.sha256" | grep -c '^<' || true) 59 echo "kernels $1 instructions $2 unmatched $3 sha-mismatched kernels $bad" 60 if [ "$bad" -gt 0 ]; then echo "PASS: mutant table caught"; else echo "FAIL: mutant table not caught"; exit 1; fi 61 62 echo "== mutant 2: bit 0 of word 0 flipped in the first instruction of the first kernel" 63 k=$(ls "$E3"/kernels-om/*.bin | head -1) 64 b0=$(od -An -tu1 -N1 "$k" | tr -d ' ') 65 printf "$(printf '\\%03o' $((b0 ^ 1)))" > "$tmp/mut2.bin" 66 tail -c +2 "$k" >> "$tmp/mut2.bin" 67 rc=0 68 { cat "$T"; printf 'E\n'; cat "$tmp/mut2.bin"; } | "$tmp/reencode" > /dev/null 2> "$tmp/err2" || rc=$? 69 echo "reencode exit $rc, instructions unmatched: $(cat "$tmp/err2")" 70 if [ "$rc" -eq 4 ]; then echo "PASS: corrupted instruction matches no form"; else echo "FAIL: corrupted instruction accepted"; exit 1; fi 71 72 echo "== mutant 3: width of the first D record with width > 1 reduced by one" 73 awk 'd == 0 && $1=="D" && $8 > 1 {$8 = $8 - 1; d = 1} {print}' "$T" > "$tmp/mut3.txt" 74 rc=$(tcheck "$tmp/mut3.txt") 75 echo "reencode exit $rc" 76 if [ "$rc" -eq 7 ]; then echo "PASS: wrong field width caught"; else echo "FAIL: wrong field width accepted"; exit 1; fi 77 78 echo "== mutant 4: lowest bit cleared in the mask of the first D record with width > 0" 79 awk 'd == 0 && $1=="D" && $8 > 0 {w = int($7 / 32); $(4 + w) = $(4 + w) - 2 ^ ($7 % 32); d = 1} {print}' "$T" > "$tmp/mut4.txt" 80 rc=$(tcheck "$tmp/mut4.txt") 81 echo "reencode exit $rc" 82 if [ "$rc" -eq 7 ]; then echo "PASS: wrong field mask caught"; else echo "FAIL: wrong field mask accepted"; exit 1; fi 83 echo "ALL CHECKS PASS"