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/aien-protocols-mv/blob/main/specs/microjob/collective-fixtures/run-host.sh # aien-protocols-mv Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem 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 `aien-protocols-mv / specs / microjob / collective-fixtures / run-host.sh` 164 lines ยท 10990 bytes Raw Blame History 1 #!/bin/bash 2 # Host-only conformance run of the matmul_u32 fixture packet. No network, no GPU, no service. 3 # OMEGA_MV_GIT bare omega-mv repository (default ~/git/omega-mv.git). The compiler and the SHA-256 unit are 4 # taken from its `main` at run time, so no pin is typed here; the head and hashes are printed. 5 # RUST_PROBE optional executable: reads "pdec HEX" / "ddec HEX" / "admit HEX KEYSEED NOW" lines (reference probe). 6 # Exit: 0 all agree and every control was discriminating; 1 disagreement or non-discriminating control; 3 NOT_RUN. 7 # Run it as: flock -n QUEEN_POOL_LOCK taskset -c CORE ./run-host.sh 8 set -u 9 set -o pipefail 10 export LC_ALL=C 11 HERE=$(cd "$(dirname "$0")" && pwd) 12 ROOT=$(cd "$HERE/../../.." && pwd) 13 MV=${OMEGA_MV_GIT:-$HOME/git/omega-mv.git} 14 T=$(mktemp -d); trap 'rm -rf "$T"' EXIT 15 fail=0; pass=0 16 ok() { pass=$((pass+1)); } 17 bad() { fail=$((fail+1)); echo "FAIL $*"; } 18 notrun() { echo "NOT_RUN: $*"; exit 3; } 19 for t in xxd python3 gcc git sha256sum; do command -v $t >/dev/null || notrun "missing $t"; done 20 21 HEAD=$(git --git-dir="$MV" rev-parse main) || notrun "no omega-mv main" 22 git --git-dir="$MV" show "$HEAD":seed/out/omc > "$T/omc" && chmod +x "$T/omc" || notrun "no omc on main" 23 git --git-dir="$MV" show "$HEAD":om/sha256/sha256-om2.om > "$T/sha.om" || notrun "no SHA unit on main" 24 echo "omega-mv main=$HEAD omc_sha256=$(sha256sum < "$T/omc" | cut -c1-64) sha_unit_sha256=$(sha256sum < "$T/sha.om" | cut -c1-64)" 25 echo "protocols_head=$(git -C "$ROOT" rev-parse HEAD)" 26 echo "protocols_diff_sha256=$(git -C "$ROOT" diff --binary HEAD -- specs/microjob specs/aienet/jobpath crates/aien-microjob | sha256sum | cut -c1-64)" 27 git -C "$ROOT" ls-files -- specs/microjob/collective-fixtures specs/microjob/tools/check-collective.sh | while IFS= read -r file; do sha256sum "$ROOT/$file"; done 28 python3 --version 29 python3 -c 'import cryptography; print("cryptography=" + cryptography.__version__)' || notrun "missing cryptography oracle dependency" 30 gcc --version | head -n 1 31 echo "microjob SPEC.md sha256=$(sha256sum < "$ROOT/specs/microjob/SPEC.md" | cut -c1-64) consumer .om sha256=$(sha256sum < "$ROOT/specs/aienet/jobpath/matmul_u32_recompute.om" | cut -c1-64)" 32 sed 's/^export fn /fn /' "$T/sha.om" > "$T/unit.om" # program mode has no exports; the only edit, as jobpath/build.sh does 33 34 build() { # $1 consumer source, $2 out 35 cat "$T/unit.om" "$1" > "$T/src.om" && "$T/omc" < "$T/src.om" > "$2" && chmod +x "$2" 36 } 37 build "$ROOT/specs/aienet/jobpath/matmul_u32_recompute.om" "$T/mm" || notrun "consumer did not compile" 38 echo "consumer binary sha256=$(sha256sum < "$T/mm" | cut -c1-64)" 39 gcc -std=c99 -O2 -Wall -Wextra -Werror -pedantic -o "$T/mjb_verify" "$ROOT/specs/microjob/tools/mjb_verify.c" || notrun "C checker did not build" 40 41 V=${VECTORS:-$HERE/vectors} 42 for input in "$V"/*.tsv; do sha256sum "$input" || notrun "missing vector input"; done 43 if [ -n "${RUST_PROBE:-}" ]; then sha256sum "$RUST_PROBE" || notrun "missing Rust reference executable"; fi 44 sha256sum "$T/mjb_verify" "$ROOT/specs/microjob/tools/mjb_verify.c" 45 run_payloads() { # $1 binary, $2 vectors dir; prints mismatch count of positives+negatives 46 local mis=0 id hex exp got rc 47 while IFS=$'\t' read -r id m k n seed hex dig w mem note; do 48 case $id in \#*|"") continue;; esac 49 got=$(printf '%s' "$hex" | xxd -r -p | "$1"); rc=$? 50 [ "$rc" = 0 ] && [ "$got" = "$dig" ] || { mis=$((mis+1)); echo " payload-positive $id rc=$rc got=$got want=$dig" >&2; } 51 done < "$2/payload-positive.tsv" 52 while IFS=$'\t' read -r id hex omx rust note; do 53 case $id in \#*|"") continue;; esac 54 [ "$hex" = "-" ] && hex="" 55 got=$(printf '%s' "$hex" | xxd -r -p | "$1"); rc=$? 56 case $omx in exit*) want=${omx#exit}; [ "$rc" = "$want" ] && [ -z "$got" ] || { mis=$((mis+1)); echo " payload-negative $id rc=$rc out=$got want=$omx" >&2; };; *) mis=$((mis+1));; esac 57 done < "$2/payload-negative.tsv" 58 echo $mis 59 } 60 echo "== oracle self-check" 61 python3 "$HERE/oracle/oracle.py" check "$V" && ok || bad "oracle check" 62 63 echo "== Omega consumer vs vectors" 64 n=$(run_payloads "$T/mm" "$V"); [ "$n" = 0 ] && ok || bad "omega consumer: $n mismatches" 65 echo "payload rows: $(grep -vc '^#' "$V/payload-positive.tsv") positive, $(grep -vc '^#' "$V/payload-negative.tsv") negative; mismatches=$n" 66 67 echo "== historical Core #662 digests (evidence/aienet0-`20261028`/xcheck662.log) vs oracle and Omega consumer" 68 H=$ROOT/evidence/aienet0-`20261028`/xcheck662.log; hm=0; hn=0 69 if [ -f "$H" ]; then 70 while read -r m k n seed rest; do 71 case $m in *[!0-9]*|"") continue;; esac 72 want=$(printf '%s' "$rest" | sed -n 's/^core662=\([0-9a-f]*\) .*/\1/p'); [ -n "$want" ] || continue 73 pay=$(python3 -c "import struct,sys;print(struct.pack('>BHHHQ',1,$m,$k,$n,$seed).hex())") 74 got=$(printf '%s' "$pay" | xxd -r -p | "$T/mm"); rc=$?; hn=$((hn+1)) 75 [ "$rc" = 0 ] && [ "$got" = "$want" ] || { hm=$((hm+1)); echo " historical $m $k $n $seed want=$want got=$got"; } 76 done < "$H" 77 echo "historical rows=$hn mismatches=$hm"; [ "$hn" -ge 1 ] && [ "$hm" = 0 ] && ok || bad "historical digests" 78 else notrun "historical log absent"; fi 79 80 doc_check() { # $1 vectors dir; prints "rows mismatches" 81 local mis=0 rows=0 id hex exp dg note line rc 82 while IFS=$'\t' read -r id hex exp dg note; do 83 case $id in \#*|"") continue;; esac 84 rows=$((rows+1)); [ "$hex" = "-" ] && hex="" 85 printf '%s' "$hex" | xxd -r -p > "$T/doc.bin" 86 line=$("$T/mjb_verify" "$T/doc.bin" 2>/dev/null); rc=$? 87 if [ "$exp" = ok ]; then [ "$rc" = 0 ] || mis=$((mis+1)); else [ "$rc" = 1 ] || mis=$((mis+1)); fi 88 case $exp in 89 ok) case $line in "ok nodes="*"digest=$dg "*|"ok nodes="*"digest=$dg") ;; *) mis=$((mis+1)); echo " doc $id want ok digest=$dg got: $line" >&2;; esac;; 90 *) [ "$line" = "refuse $exp" ] || { mis=$((mis+1)); echo " doc $id want $exp got: $line" >&2; };; 91 esac 92 done < "$1/document.tsv" 93 echo "$rows $mis" 94 } 95 echo "== C checker vs document vectors" 96 set -- $(doc_check "$V"); echo "document rows: $1; mismatches=$2"; [ "$1" -ge 1 ] && [ "$2" = 0 ] && ok || bad "C checker: $2 mismatches" 97 98 rust_check() { # $1 vectors dir; prints mismatch count 99 local mis=0 id hex omx rust note exp dg pin now got want m k n seed w mem 100 while IFS=$'\t' read -r id m k n seed hex dg w mem note; do case $id in \#*|"") continue;; esac 101 got=$(echo "pdec ${hex}" | "$RUST_PROBE"); [ "$?" = 0 ] || { mis=$((mis+1)); continue; } 102 [ "$got" = "OK in_bounds=true work=$w memory=$mem digest=$dg" ] || { mis=$((mis+1)); echo " rust digest $id got=$got want=$dg" >&2; } 103 done < "$1/payload-positive.tsv" 104 while IFS=$'\t' read -r id hex omx rust note; do case $id in \#*|"") continue;; esac 105 [ "$hex" = "-" ] && hex="" 106 got=$(echo "pdec ${hex}" | "$RUST_PROBE" | cut -d' ' -f1); [ "$?" = 0 ] || { mis=$((mis+1)); continue; } 107 want=$rust; [ "$want" = decode_ok_then_AN0_OVER_BUDGET ] && want=OK; [ "$want" = decode_ok ] && want=OK 108 [ "$got" = "$want" ] || { mis=$((mis+1)); echo " rust decode $id got=$got want=$want" >&2; } 109 done < "$1/payload-negative.tsv" 110 while IFS=$'\t' read -r id hex exp dg note; do case $id in \#*|"") continue;; esac 111 got=$(echo "ddec ${hex}" | "$RUST_PROBE"); [ "$?" = 0 ] || { mis=$((mis+1)); continue; }; [ "$got" = "OK dag_digest=$dg" ] && got=ok 112 [ "$got" = "$exp" ] || { mis=$((mis+1)); echo " rust document $id got=$got want=$exp" >&2; } 113 done < "$1/document.tsv" 114 while IFS=$'\t' read -r id hex pin now exp note; do case $id in \#*|"") continue;; esac 115 [ "$hex" = "-" ] && hex="" 116 got=$(echo "admitkey ${hex} ${pin} ${now}" | "$RUST_PROBE" | sed 's/^OK /ok /'); [ "$?" = 0 ] || { mis=$((mis+1)); continue; } 117 [ "$got" = "$exp" ] || { mis=$((mis+1)); echo " rust bundle $id got=$got want=$exp" >&2; } 118 done < "$1/bundle.tsv" 119 echo $mis 120 } 121 if [ -n "${RUST_PROBE:-}" ]; then 122 echo "== Rust reference probe (RUST_PROBE=$RUST_PROBE)" 123 mis=$(rust_check "$V"); echo "rust probe mismatches=$mis"; [ "$mis" = 0 ] && ok || bad "rust probe: $mis mismatches" 124 else 125 echo "== Rust reference probe: NOT_RUN (RUST_PROBE unset)" 126 fi 127 128 echo "== discriminating controls (each must be detected)" 129 # C1: a wrong expected digest in a copy of the vectors must be caught by the Omega consumer. 130 mkdir -p "$T/v1"; cp "$V"/* "$T/v1/" 131 awk 'BEGIN{FS=OFS="\t"} !/^#/ && !d {sub(/^./,(substr($7,1,1)=="0"?"1":"0"),$7); d=1} {print}' "$T/v1/payload-positive.tsv" > "$T/v1/p" && mv "$T/v1/p" "$T/v1/payload-positive.tsv" 132 n=$(run_payloads "$T/mm" "$T/v1" 2>/dev/null); [ "$n" -ge 1 ] && ok || bad "control C1 not detected" 133 # C2: a wrong expected refusal in a copy of the document vectors must be caught by the same comparison. 134 cp "$V/document.tsv" "$T/v1/document.tsv"; sed -i '0,/\tMJB_BAD_MAGIC\t/s//\tMJB_BAD_COUNT\t/' "$T/v1/document.tsv" 135 set -- $(doc_check "$T/v1" 2>/dev/null); [ "$2" -ge 1 ] && ok || bad "control C2 not detected" 136 # C3/C4: mutated consumers (domain string; splitmix64 shift; wrapping loop order irrelevant) must fail the positives. 137 S=$ROOT/specs/aienet/jobpath/matmul_u32_recompute.om 138 sed 's/AIEN-HETJOB-MATMUL-U32-V1/AIEN-HETJOB-MATMUL-U32-V2/' "$S" > "$T/m3.om" 139 sed 's/z = xor z shr z 27/z = xor z shr z 28/' "$S" > "$T/m4.om" 140 sed 's/gt m 256/gt m 255/' "$S" > "$T/m5.om" 141 for c in 3 4 5; do 142 [ "$(cmp -s "$S" "$T/m$c.om" && echo same)" = same ] && { bad "control C$c mutation did not apply"; continue; } 143 if build "$T/m$c.om" "$T/mm$c"; then n=$(run_payloads "$T/mm$c" "$V" 2>/dev/null); [ "$n" -ge 1 ] && ok || bad "control C$c mutant consumer not detected"; else bad "control C$c mutant did not compile"; fi 144 done 145 if [ -n "${RUST_PROBE:-}" ]; then # C6: the Rust comparison must notice a wrong expectation 146 cp "$V/bundle.tsv" "$T/v1/bundle.tsv"; sed -i '0,/\tok dag_digest=/s//\tAN0_BAD_BUNDLE_X /' "$T/v1/bundle.tsv" 147 cp "$V/payload-positive.tsv" "$T/v1/payload-positive.tsv"; cp "$V/document.tsv" "$T/v1/document.tsv"; cp "$V/payload-negative.tsv" "$T/v1/payload-negative.tsv" 148 n=$(rust_check "$T/v1" 2>/dev/null); [ "$n" -ge 1 ] && ok || bad "control C6 not detected" 149 fi 150 # Missing or duplicated cases must not turn a reduced packet into a successful full run. 151 for control in missing duplicate; do 152 mkdir -p "$T/$control"; cp "$V"/* "$T/$control/" 153 if [ "$control" = missing ]; then 154 awk '!/^#/ && !d {d=1; next} {print}' "$V/payload-negative.tsv" > "$T/$control/payload-negative.tsv" 155 else 156 awk '{print} !/^#/ && !d {print; d=1}' "$V/payload-negative.tsv" > "$T/$control/payload-negative.tsv" 157 fi 158 python3 "$HERE/oracle/oracle.py" check "$T/$control" > "$T/$control.out" 2>&1; rc=$? 159 [ "$rc" = 1 ] && grep -q 'ORACLE_FAIL coverage payload-negative.tsv' "$T/$control.out" && ok || bad "control $control coverage not detected" 160 done 161 echo "RESULT pass=$pass fail=$fail" 162 [ "$fail" = 0 ] || exit 1 163 # Fail closed: bundle admission is otherwise checked only by the oracle that generated the rows. 164 [ -n "${RUST_PROBE:-}" ] || { echo "NOT_RUN: Rust reference probe absent; bundle rows are not independently checked (exit 3)"; exit 3; }