physics-mv
FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence.
Brought by drakestapleton
physics-mv / tests / run_forge_aegis_host_gates.sh
| 1 | #!/bin/bash |
| 2 | # tests/run_forge_aegis_host_gates.sh -- host-only checks of the FORGE AEGIS |
| 3 | # verifier and the submit-side refusals (physics #53). No GPU, no NVRM calls, |
| 4 | # no GPU lock: every submit in the test is refused before hardware access. |
| 5 | # Exit code 0 only when every check passes. |
| 6 | set -uo pipefail |
| 7 | |
| 8 | SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) |
| 9 | REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd -P) |
| 10 | cd "$REPO_ROOT" || exit 1 |
| 11 | |
| 12 | BUILD_DIR="$REPO_ROOT/build" |
| 13 | BIN="$BUILD_DIR/test_forge_aegis_host" |
| 14 | mkdir -p "$BUILD_DIR" |
| 15 | |
| 16 | # Same flags and sources as the GB10 seam build in tests/run_forge_gates.sh. |
| 17 | CFLAGS="-O2 -Wall -Wextra -Werror \ |
| 18 | -I./forge -I./nvrm -I./m16 \ |
| 19 | -I./third_party/nvidia-open-580.173.02/src/common/sdk/nvidia/inc \ |
| 20 | -I./third_party/nvidia-open-580.173.02/kernel-open/common/inc \ |
| 21 | -I./third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm \ |
| 22 | -I./third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include" |
| 23 | SRCS="forge/forge_descriptor.c forge/forge_realize.c sha256_clean.c nvrm/nvrm.c m16/m16_native.c" |
| 24 | |
| 25 | echo "=== FORGE AEGIS host gates ===" |
| 26 | # shellcheck disable=SC2086 |
| 27 | if ! gcc $CFLAGS $SRCS tests/test_forge_aegis_host.c -o "$BIN"; then |
| 28 | echo "FAIL build test_forge_aegis_host" |
| 29 | exit 1 |
| 30 | fi |
| 31 | echo "PASS build test_forge_aegis_host" |
| 32 | "$BIN" |
| 33 | rc=$? |
| 34 | |
| 35 | # DRA-176 mutant controls: a memcpy realization must not be able to count as a |
| 36 | # compiler effect. Each mutant is a build-dir copy of forge/forge_realize.c with |
| 37 | # one line changed (the tree is not touched); the checks above must fail on it. |
| 38 | # label forge_realize labels its IR copy COMPILED |
| 39 | # nocopy forge_realization_is_compiled skips the IR-copy check |
| 40 | # const0 forge_realization_is_compiled always answers 0 |
| 41 | # notlowered forge_realization_is_compiled ignores is_lowered |
| 42 | # offset0 the IR-copy check looks at offset 0 only |
| 43 | # relabel forge_submit_realization ignores a relabel after verification |
| 44 | # sealkind AEGIS seals the COMPILED label whatever the realization says |
| 45 | # executed the submission evidence claims the code buffer ran |
| 46 | # verifycompiled AEGIS verifies a COMPILED label without the compiled predicate |
| 47 | # verifyunknown AEGIS verifies a label outside NONE/SIMULATED/COMPILED |
| 48 | # tokenkind the verification token does not cover the sealed label |
| 49 | # evidenceconst the evidence label is a constant, not the sealed label |
| 50 | # prefix a code buffer that is a prefix of the IR is not a copy |
| 51 | # endbound the IR-copy check misses a copy that ends at the buffer end |
| 52 | # irdigest the request digest does not cover the IR bytes |
| 53 | # predlabel forge_realization_is_compiled tests the label against NONE only |
| 54 | # verifyge AEGIS refuses the COMPILED label itself as unknown |
| 55 | mutant() { # NAME SED-SCRIPT EXACT-LINE |
| 56 | total=$((total + 1)) |
| 57 | local name=$1 script=$2 line=$3 src="$BUILD_DIR/mutant_${1}_forge_realize.c" out |
| 58 | if [ "$(grep -cF -- "$line" forge/forge_realize.c)" != 1 ]; then |
| 59 | echo "FAIL mutant $name: its target line is not present exactly once" |
| 60 | return 1 |
| 61 | fi |
| 62 | sed -e "$script" forge/forge_realize.c > "$src" |
| 63 | if cmp -s "$src" forge/forge_realize.c; then |
| 64 | echo "FAIL mutant $name: sed changed nothing" |
| 65 | return 1 |
| 66 | fi |
| 67 | # shellcheck disable=SC2086 |
| 68 | if ! gcc $CFLAGS ${SRCS/forge\/forge_realize.c/$src} tests/test_forge_aegis_host.c -o "$BIN.mutant_$name"; then |
| 69 | echo "FAIL mutant $name: did not build" |
| 70 | return 1 |
| 71 | fi |
| 72 | if out=$("$BIN.mutant_$name"); then |
| 73 | echo "FAIL mutant $name: not caught (all checks passed)" |
| 74 | return 1 |
| 75 | fi |
| 76 | echo "PASS mutant $name caught:$(printf '%s\n' "$out" | sed -n 's/^\[FAIL\] / /p' | tr -d '\n')" |
| 77 | } |
| 78 | caught=0 total=0 |
| 79 | mutant label 's/out_res->lowering_kind = FORGE_LOWERING_SIMULATED;/out_res->lowering_kind = FORGE_LOWERING_COMPILED;/' \ |
| 80 | 'out_res->lowering_kind = FORGE_LOWERING_SIMULATED;' && caught=$((caught + 1)) |
| 81 | mutant nocopy 's/ if (code_contains_ir(res->machine_code/ if (0 \&\& code_contains_ir(res->machine_code/' \ |
| 82 | ' if (code_contains_ir(res->machine_code' && caught=$((caught + 1)) |
| 83 | mutant const0 's/ if (res->lowering_kind != FORGE_LOWERING_COMPILED) return 0;/ return 0;/' \ |
| 84 | ' if (res->lowering_kind != FORGE_LOWERING_COMPILED) return 0;' && caught=$((caught + 1)) |
| 85 | mutant notlowered 's/ if (!res->is_lowered || !res->machine_code || res->machine_code_size == 0) return 0;/ if (!res->machine_code || res->machine_code_size == 0) return 0;/' \ |
| 86 | ' if (!res->is_lowered || !res->machine_code || res->machine_code_size == 0) return 0;' && caught=$((caught + 1)) |
| 87 | mutant offset0 's/off + ir_size <= code_size; off++/off + ir_size <= code_size \&\& off == 0; off++/' \ |
| 88 | 'off + ir_size <= code_size; off++' && caught=$((caught + 1)) |
| 89 | mutant relabel 's/ if (verified_real->realization.lowering_kind != verified_real->sealed_lowering_kind) {/ if (0) {/' \ |
| 90 | ' if (verified_real->realization.lowering_kind != verified_real->sealed_lowering_kind) {' && caught=$((caught + 1)) |
| 91 | mutant sealkind 's/out_verified->sealed_lowering_kind = res->lowering_kind;/out_verified->sealed_lowering_kind = FORGE_LOWERING_COMPILED;/' \ |
| 92 | 'out_verified->sealed_lowering_kind = res->lowering_kind;' && caught=$((caught + 1)) |
| 93 | mutant executed 's/out_evidence->code_executed = false;/out_evidence->code_executed = true;/' \ |
| 94 | 'out_evidence->code_executed = false;' && caught=$((caught + 1)) |
| 95 | mutant verifycompiled 's/ if (res->lowering_kind == FORGE_LOWERING_COMPILED \&\& forge_realization_is_compiled(req, res) != 1) {/ if (0) {/' \ |
| 96 | ' if (res->lowering_kind == FORGE_LOWERING_COMPILED && forge_realization_is_compiled(req, res) != 1) {' && caught=$((caught + 1)) |
| 97 | mutant verifyunknown 's/ if (res->lowering_kind > FORGE_LOWERING_COMPILED) {/ if (0) {/' \ |
| 98 | ' if (res->lowering_kind > FORGE_LOWERING_COMPILED) {' && caught=$((caught + 1)) |
| 99 | mutant tokenkind 's/ memcpy(buf + 16 + 96, \&lowering_kind, 4);/ (void)lowering_kind; memset(buf + 16 + 96, 0, 4);/' \ |
| 100 | ' memcpy(buf + 16 + 96, &lowering_kind, 4);' && caught=$((caught + 1)) |
| 101 | mutant evidenceconst 's/out_evidence->lowering_kind = verified_real->sealed_lowering_kind;/out_evidence->lowering_kind = FORGE_LOWERING_SIMULATED;/' \ |
| 102 | 'out_evidence->lowering_kind = verified_real->sealed_lowering_kind;' && caught=$((caught + 1)) |
| 103 | mutant prefix 's/ if (ir_size >= code_size) return memcmp(code, ir, code_size) == 0;/ if (ir_size >= code_size) return false;/' \ |
| 104 | ' if (ir_size >= code_size) return memcmp(code, ir, code_size) == 0;' && caught=$((caught + 1)) |
| 105 | mutant endbound 's/off + ir_size <= code_size; off++/off + ir_size < code_size; off++/' \ |
| 106 | 'off + ir_size <= code_size; off++' && caught=$((caught + 1)) |
| 107 | mutant irdigest 's/ sha256_bytes(req->ir_payload ? req->ir_payload : req_buf, req->ir_payload ? req->ir_size : 0, req_buf + 76);/ memset(req_buf + 76, 0, 32);/' \ |
| 108 | ' sha256_bytes(req->ir_payload ? req->ir_payload : req_buf, req->ir_payload ? req->ir_size : 0, req_buf + 76);' && caught=$((caught + 1)) |
| 109 | mutant predlabel 's/ if (res->lowering_kind != FORGE_LOWERING_COMPILED) return 0;/ if (res->lowering_kind == FORGE_LOWERING_NONE) return 0;/' \ |
| 110 | ' if (res->lowering_kind != FORGE_LOWERING_COMPILED) return 0;' && caught=$((caught + 1)) |
| 111 | mutant verifyge 's/ if (res->lowering_kind > FORGE_LOWERING_COMPILED) {/ if (res->lowering_kind >= FORGE_LOWERING_COMPILED) {/' \ |
| 112 | ' if (res->lowering_kind > FORGE_LOWERING_COMPILED) {' && caught=$((caught + 1)) |
| 113 | echo "FORGE AEGIS mutant controls: CAUGHT=$caught OF=$total" |
| 114 | [ "$rc" -eq 0 ] && [ "$caught" -eq "$total" ] |