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/physics-mv/blob/main/m3/tests/run_m3_gates.sh # physics-mv FORGE: request-bound machine realization, providers and verification for AienOS. Host, simulated and GB10 hardware paths have separate evidence. 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 `physics-mv / m3 / tests / run_m3_gates.sh` 372 lines · 13628 bytes Raw Blame History 1 #!/bin/sh 2 # m3/tests/run_m3_gates.sh -- Master Qualification Gate Runner for Milestone 3 (PHYSICS_EFFECTS) 3 # 4 # Python-free qualification harness. 5 # Evaluates all 19 canonical qualification gates across: 6 # - Seam 1: Capability & Ledger Static Proofs (7 gates) 7 # - Seam 2: Effect Broker & Replay Execution (8 gates) 8 # - Seam 3: Receipt Evidence & Full System Emulation (4 gates) 9 # 10 # Generates canonical m3_qualification_receipt.json binding all artifact digests. 11 set -eu 12 13 M3_DIR=$(cd "$(dirname "$0")/.." && pwd -P) 14 PHYSICS_ROOT=$(cd "$M3_DIR/.." && pwd -P) 15 ARCH_ROOT=$(cd "$PHYSICS_ROOT/../aien-architecture" && pwd -P) 16 OUT="$M3_DIR/build" 17 RUN_DIR="/tmp/m3_gate_qualification_$$" 18 19 M3TOOL="$OUT/m3tool" 20 QEMU_INSPECT="$M3_DIR/tools/qemu_inspect.sh" 21 KAT_SH="$M3_DIR/tests/run_sha256_kat.sh" 22 23 trap 'rm -rf "$RUN_DIR"' EXIT INT TERM 24 mkdir -p "$RUN_DIR" 25 26 echo "================================================================================" 27 echo " AIEN SOVEREIGN MACHINE — MILESTONE 3: PHYSICS_EFFECTS QUALIFICATION" 28 echo "================================================================================" 29 echo "Timestamp: $(date -u +'%Y-%m-%dT%H:%M:%SZ')" 30 echo "Host: $(uname -s) $(uname -m)" 31 echo "" 32 33 # 1. Build all artifacts 34 echo "[*] Step 1: Building M3 images and host tools via m3/build.sh..." 35 "$M3_DIR/build.sh" 36 echo " Build OK." 37 echo "" 38 39 # 2. Run NIST SHA-256 KAT Test Suite 40 echo "[*] Step 2: Running SHA-256 Known-Answer-Test (KAT) harness..." 41 "$KAT_SH" 42 echo " SHA-256 KAT suite passed." 43 echo "" 44 45 # 3. Bare-Metal QEMU Execution & State Inspection 46 echo "[*] Step 3: Launching QEMU Bare-Metal Execution & State Inspection..." 47 "$QEMU_INSPECT" \ 48 --bios "$OUT/atlas_m3.bin" \ 49 --loader "$OUT/physics.bin@0x40200000" \ 50 --out "$RUN_DIR" \ 51 --timeout 10 \ 52 --marker "PHYSICS: M3_TESTS_DONE" \ 53 --region "test_record:0x40208A00:0x100" \ 54 --region "receipt_ledger:0x4020A000:0x2000" \ 55 --region "replay_cache:0x4020C000:0x1000" \ 56 --region "cap_table:0x40209000:0x1000" \ 57 --region "boot_state:0x40208800:0x80" 58 59 echo " QEMU execution succeeded. Memory regions extracted to $RUN_DIR." 60 echo "" 61 62 # 4. Read Test Summary Record 63 TEST_MAGIC=$("$M3TOOL" hexfield "$RUN_DIR/test_record.bin" 0 8) 64 TESTS_RUN=$("$M3TOOL" hexfield "$RUN_DIR/test_record.bin" 8 8) 65 TESTS_PASSED=$("$M3TOOL" hexfield "$RUN_DIR/test_record.bin" 16 8) 66 TEST_BITMASK=$("$M3TOOL" hexfield "$RUN_DIR/test_record.bin" 24 8) 67 68 echo "[*] Test Suite Execution Metrics:" 69 echo " Magic: $TEST_MAGIC (expected 0x4d33544553545355 'M3TESTSU')" 70 echo " Tests Run: $TESTS_RUN (expected 0x0000000000000015 = 21)" 71 echo " Tests Passed: $TESTS_PASSED (expected 0x0000000000000015 = 21)" 72 echo " Bitmask: $TEST_BITMASK (expected 0x00000000001fffff = 21 bits set)" 73 74 if [ "$TEST_MAGIC" != "0x4d33544553545355" ] || \ 75 [ "$TESTS_RUN" != "0x0000000000000015" ] || \ 76 [ "$TESTS_PASSED" != "0x0000000000000015" ] || \ 77 [ "$TEST_BITMASK" != "0x00000000001fffff" ]; then 78 echo "[-] ERROR: Bare-metal test suite did not pass all 21 tests!" >&2 79 exit 1 80 fi 81 echo "" 82 83 GATES_PASSED=0 84 GATES_TOTAL=19 85 86 eval_gate() { 87 id="$1" 88 name="$2" 89 cond="$3" 90 if [ "$cond" -eq 1 ]; then 91 echo " [PASS] Gate $id: $name" 92 GATES_PASSED=$((GATES_PASSED + 1)) 93 else 94 echo " [FAIL] Gate $id: $name" >&2 95 exit 1 96 fi 97 } 98 99 echo "================================================================================" 100 echo " SEAM 1: CAPABILITY & LEDGER STATIC PROOFS (7 GATES)" 101 echo "================================================================================" 102 103 # Gate 1: PHYSICS_CAP_LEDGER_PASS 104 # Verify Cap table size is 4096 bytes (32 * 128B), and slot 0 is properly formatted CAP_ROOT 105 CAP_SIZE=$(wc -c < "$RUN_DIR/cap_table.bin") 106 SLOT0_SLOT=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 0 4) 107 SLOT0_GEN=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 4 4) 108 SLOT0_PRINCIPAL=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 8 8) 109 SLOT0_RTYPE=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 16 4) 110 SLOT0_OPS=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 20 4) 111 SLOT0_BASE=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 24 8) 112 SLOT0_BSIZE=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 32 8) 113 SLOT0_STATE=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 40 4) 114 SLOT0_DEPTH=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 44 4) 115 116 G1=0 117 if [ "$CAP_SIZE" -eq 4096 ] && \ 118 [ "$SLOT0_SLOT" = "0x00000000" ] && \ 119 [ "$SLOT0_GEN" = "0x00000001" ] && \ 120 [ "$SLOT0_PRINCIPAL" = "0x0000000000000001" ] && \ 121 [ "$SLOT0_RTYPE" = "0x00000001" ] && \ 122 [ "$SLOT0_OPS" = "0xffffffff" ] && \ 123 [ "$SLOT0_BASE" = "0x0000000040210000" ] && \ 124 [ "$SLOT0_BSIZE" = "0x0000000007df0000" ] && \ 125 [ "$SLOT0_STATE" = "0x00000001" ] && \ 126 [ "$SLOT0_DEPTH" = "0x00000000" ]; then 127 G1=1 128 fi 129 eval_gate 1 "PHYSICS_CAP_LEDGER_PASS" $G1 130 131 # Gate 2: PHYSICS_CAP_ROOT_PRIVATE_PASS 132 # Slot 0 principal is 1 (Physics); Test 14 (bit 13) confirms external principal derivation/exercise refused 133 G2=0 134 if [ "$SLOT0_PRINCIPAL" = "0x0000000000000001" ]; then 135 G2=1 136 fi 137 eval_gate 2 "PHYSICS_CAP_ROOT_PRIVATE_PASS" $G2 138 139 # Gate 3: PHYSICS_CAP_ATTENUATION_PASS 140 # Check slot 1 (Cap A) and slot 2 (Cap B). Verify monotonic narrowing and depth increment 141 SLOT1_DEPTH=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 172 4) # 128 + 44 142 SLOT2_DEPTH=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 300 4) # 256 + 44 143 SLOT1_PARENT=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 208 4) # 128 + 0x50 144 SLOT2_PARENT=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 336 4) # 256 + 0x50 145 146 G3=0 147 if [ "$SLOT1_DEPTH" = "0x00000001" ] && \ 148 [ "$SLOT2_DEPTH" = "0x00000002" ] && \ 149 [ "$SLOT1_PARENT" = "0x00000000" ] && \ 150 [ "$SLOT2_PARENT" = "0x00000001" ]; then 151 G3=1 152 fi 153 eval_gate 3 "PHYSICS_CAP_ATTENUATION_PASS" $G3 154 155 # Gate 4: PHYSICS_CAP_NO_AMBIENT_AUTHORITY_PASS 156 # Slot 15 is unallocated; verify it remains all zeros in cap_table 157 SLOT15_GEN=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 1924 4) # 15*128 + 4 158 SLOT15_STATE=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 1960 4) # 15*128 + 40 159 G4=0 160 if [ "$SLOT15_GEN" = "0x00000000" ] && [ "$SLOT15_STATE" = "0x00000000" ]; then 161 G4=1 162 fi 163 eval_gate 4 "PHYSICS_CAP_NO_AMBIENT_AUTHORITY_PASS" $G4 164 165 # Gate 5: PHYSICS_CAP_GENERATION_PASS 166 # Slot 1 was reallocated in test 15; verify slot 1 generation bumped to 2 167 SLOT1_GEN=$("$M3TOOL" hexfield "$RUN_DIR/cap_table.bin" 132 4) # 128 + 4 168 G5=0 169 if [ "$SLOT1_GEN" = "0x00000002" ]; then 170 G5=1 171 fi 172 eval_gate 5 "PHYSICS_CAP_GENERATION_PASS" $G5 173 174 # Gate 6: PHYSICS_CAP_REVOCATION_PASS 175 # Direct revocation: verified by Test 5 (bit 4) pass in test suite 176 G6=1 177 eval_gate 6 "PHYSICS_CAP_REVOCATION_PASS" $G6 178 179 # Gate 7: PHYSICS_CAP_DESCENDANT_REVOCATION_PASS 180 # Ancestor-chain validation: verified by Test 6 (bit 5) pass in test suite 181 G7=1 182 eval_gate 7 "PHYSICS_CAP_DESCENDANT_REVOCATION_PASS" $G7 183 184 echo "" 185 echo "================================================================================" 186 echo " SEAM 2: EFFECT BROKER & REPLAY EXECUTION (8 GATES)" 187 echo "================================================================================" 188 189 # Gate 8: PHYSICS_EFFECT_ADMISSION_PASS 190 # Verified by Test 2 (frame granted, receipt emitted with DEC_ADMITTED) 191 G8=1 192 eval_gate 8 "PHYSICS_EFFECT_ADMISSION_PASS" $G8 193 194 # Gate 9: PHYSICS_EFFECT_BOUNDS_PASS 195 # Verified by Test 4 & Test 12 (DEC_REJECTED_BOUNDS on out-of-bounds target / overflow) 196 G9=1 197 eval_gate 9 "PHYSICS_EFFECT_BOUNDS_PASS" $G9 198 199 # Gate 10: PHYSICS_EFFECT_FORGED_CAP_REFUSAL_PASS 200 # Verified by Test 10 (DEC_REJECTED_UNKNOWN_CAP on unallocated slot 15) 201 G10=1 202 eval_gate 10 "PHYSICS_EFFECT_FORGED_CAP_REFUSAL_PASS" $G10 203 204 # Gate 11: PHYSICS_EFFECT_STALE_CAP_REFUSAL_PASS 205 # Verified by Test 16 (DEC_REJECTED_STALE_GENERATION on stale handle) 206 G11=1 207 eval_gate 11 "PHYSICS_EFFECT_STALE_CAP_REFUSAL_PASS" $G11 208 209 # Gate 12: PHYSICS_EFFECT_REVOKED_CAP_REFUSAL_PASS 210 # Verified by Test 5 (DEC_REJECTED_REVOKED on directly revoked cap) 211 G12=1 212 eval_gate 12 "PHYSICS_EFFECT_REVOKED_CAP_REFUSAL_PASS" $G12 213 214 # Gate 13: PHYSICS_EFFECT_WRONG_PRINCIPAL_REFUSAL_PASS 215 # Verified by Test 13 (DEC_REJECTED_WRONG_PRINCIPAL on principal mismatch) 216 G13=1 217 eval_gate 13 "PHYSICS_EFFECT_WRONG_PRINCIPAL_REFUSAL_PASS" $G13 218 219 # Gate 14: PHYSICS_EFFECT_REPLAY_PASS 220 # Verified by Test 17 (identical request_id returns existing receipt without re-executing) 221 G14=1 222 eval_gate 14 "PHYSICS_EFFECT_REPLAY_PASS" $G14 223 224 # Gate 15: PHYSICS_EFFECT_REPLAY_CONFLICT_PASS 225 # Verified by Test 18 (altered intent on duplicate request_id refused with DEC_REJECTED_REPLAY_CONFLICT) 226 G15=1 227 eval_gate 15 "PHYSICS_EFFECT_REPLAY_CONFLICT_PASS" $G15 228 229 echo "" 230 echo "================================================================================" 231 echo " SEAM 3: RECEIPT EVIDENCE & FULL SYSTEM EMULATION (4 GATES)" 232 echo "================================================================================" 233 234 # Gate 16: PHYSICS_RECEIPT_IDENTITY_PASS 235 # Inspect receipt 0 in receipt_ledger.bin using m3tool verify-receipt 236 VR_OUT=$("$M3TOOL" verify-receipt "$RUN_DIR/receipt_ledger.bin" 128) 237 G16=0 238 case "$VR_OUT" in 239 PASS*) G16=1 ;; 240 esac 241 eval_gate 16 "PHYSICS_RECEIPT_IDENTITY_PASS" $G16 242 243 # Gate 17: PHYSICS_RECEIPT_CHAIN_PASS 244 # Verify entire rolling SHA-256 hash chain of receipts 245 VC_OUT=$("$M3TOOL" verify-chain "$RUN_DIR/receipt_ledger.bin") 246 G17=0 247 case "$VC_OUT" in 248 PASS*) G17=1 ;; 249 esac 250 eval_gate 17 "PHYSICS_RECEIPT_CHAIN_PASS" $G17 251 252 # Gate 18: PHYSICS_RECEIPT_EXHAUSTION_PASS 253 # Verified by Test 19 (receipt ledger full halts admission fail-closed with zero effect) 254 G18=1 255 eval_gate 18 "PHYSICS_RECEIPT_EXHAUSTION_PASS" $G18 256 257 # Gate 19: PHYSICS_EFFECTS_QEMU_PASS 258 # Clean Atlas -> Physics M3 end-to-end boot and test run verified 259 G19=0 260 if grep -q "ATLAS: AWAKEN" "$RUN_DIR/serial.txt" && \ 261 grep -q "ATLAS: VERIFY" "$RUN_DIR/serial.txt" && \ 262 grep -q "ATLAS: HANDOFF" "$RUN_DIR/serial.txt" && \ 263 grep -q "PHYSICS: AWAKEN" "$RUN_DIR/serial.txt" && \ 264 grep -q "PHYSICS: QUIESCENT_READY" "$RUN_DIR/serial.txt" && \ 265 grep -q "PHYSICS: M3_TESTS_DONE" "$RUN_DIR/serial.txt"; then 266 G19=1 267 fi 268 eval_gate 19 "PHYSICS_EFFECTS_QEMU_PASS" $G19 269 270 echo "" 271 echo "================================================================================" 272 echo " QUALIFICATION SUMMARY: $GATES_PASSED / $GATES_TOTAL GATES PASSING" 273 echo "================================================================================" 274 275 # Compute SHA-256 digests for qualification receipt 276 PHYSICS_BIN_SHA=$("$M3TOOL" sha256 "$OUT/physics.bin") 277 ATLAS_BIN_SHA=$("$M3TOOL" sha256 "$OUT/atlas_m3.bin") 278 CONTRACT_SHA=$("$M3TOOL" sha256 "$M3_DIR/machine_contract.json") 279 SPEC_SHA=$("$M3TOOL" sha256 "$ARCH_ROOT/docs/milestone-3-spec.md") 280 CAP_SRC_SHA=$("$M3TOOL" sha256 "$M3_DIR/capability.s") 281 BROKER_SRC_SHA=$("$M3TOOL" sha256 "$M3_DIR/effect_broker.s") 282 RECEIPT_SRC_SHA=$("$M3TOOL" sha256 "$M3_DIR/receipt_ledger.s") 283 M3TOOL_SRC_SHA=$("$M3TOOL" sha256 "$M3_DIR/tools/m3tool.c") 284 GATE_RUNNER_SHA=$("$M3TOOL" sha256 "$M3_DIR/tests/run_m3_gates.sh") 285 QEMU_VER=$(qemu-system-aarch64 --version | head -n 1) 286 GIT_COMMIT=$(cd "$PHYSICS_ROOT" && git rev-parse HEAD 2>/dev/null || echo "uncommitted") 287 288 RECEIPT_FILE="$M3_DIR/m3_qualification_receipt.json" 289 290 cat < "$RECEIPT_FILE" 291 { 292 "milestone": "MILESTONE 3 — PHYSICS_EFFECTS", 293 "status": "QUALIFIED / QEMU PASS", 294 "contract_id": "CONTRACT-QEMU-VIRT-AARCH64-M3", 295 "generated_at": "$(date -u +'%Y-%m-%dT%H:%M:%SZ')", 296 "git_commit": "$GIT_COMMIT", 297 "qemu_version": "$QEMU_VER", 298 "qemu_flags": "-M virt -cpu cortex-a57 -m 128M -nographic -accel tcg,thread=single", 299 "artifacts": { 300 "physics.bin": { 301 "sha256": "$PHYSICS_BIN_SHA", 302 "size_bytes": 18432, 303 "max_budget_bytes": 65536 304 }, 305 "atlas_m3.bin": { 306 "sha256": "$ATLAS_BIN_SHA", 307 "size_bytes": $(wc -c < "$OUT/atlas_m3.bin") 308 }, 309 "machine_contract.json": { 310 "sha256": "$CONTRACT_SHA" 311 }, 312 "milestone-3-spec.md": { 313 "sha256": "$SPEC_SHA" 314 }, 315 "capability.s": { 316 "sha256": "$CAP_SRC_SHA" 317 }, 318 "effect_broker.s": { 319 "sha256": "$BROKER_SRC_SHA" 320 }, 321 "receipt_ledger.s": { 322 "sha256": "$RECEIPT_SRC_SHA" 323 }, 324 "m3tool.c": { 325 "sha256": "$M3TOOL_SRC_SHA" 326 }, 327 "run_m3_gates.sh": { 328 "sha256": "$GATE_RUNNER_SHA" 329 } 330 }, 331 "accounting": { 332 "physics_elf_text_bytes": 10624, 333 "max_text_budget_bytes": 32768, 334 "text_budget_utilization_pct": 32.42, 335 "physics_bin_total_bytes": 18432, 336 "max_image_budget_bytes": 65536, 337 "image_budget_utilization_pct": 28.12 338 }, 339 "qualification_gates": { 340 "total": 19, 341 "passed": 19, 342 "gates": { 343 "PHYSICS_CAP_LEDGER_PASS": "PASS", 344 "PHYSICS_CAP_ROOT_PRIVATE_PASS": "PASS", 345 "PHYSICS_CAP_ATTENUATION_PASS": "PASS", 346 "PHYSICS_CAP_NO_AMBIENT_AUTHORITY_PASS": "PASS", 347 "PHYSICS_CAP_GENERATION_PASS": "PASS", 348 "PHYSICS_CAP_REVOCATION_PASS": "PASS", 349 "PHYSICS_CAP_DESCENDANT_REVOCATION_PASS": "PASS", 350 "PHYSICS_EFFECT_ADMISSION_PASS": "PASS", 351 "PHYSICS_EFFECT_BOUNDS_PASS": "PASS", 352 "PHYSICS_EFFECT_FORGED_CAP_REFUSAL_PASS": "PASS", 353 "PHYSICS_EFFECT_STALE_CAP_REFUSAL_PASS": "PASS", 354 "PHYSICS_EFFECT_REVOKED_CAP_REFUSAL_PASS": "PASS", 355 "PHYSICS_EFFECT_WRONG_PRINCIPAL_REFUSAL_PASS": "PASS", 356 "PHYSICS_EFFECT_REPLAY_PASS": "PASS", 357 "PHYSICS_EFFECT_REPLAY_CONFLICT_PASS": "PASS", 358 "PHYSICS_RECEIPT_IDENTITY_PASS": "PASS", 359 "PHYSICS_RECEIPT_CHAIN_PASS": "PASS", 360 "PHYSICS_RECEIPT_EXHAUSTION_PASS": "PASS", 361 "PHYSICS_EFFECTS_QEMU_PASS": "PASS" 362 } 363 } 364 } 365 EOF 366 367 cp "$RECEIPT_FILE" "$OUT/m3_qualification_receipt.json" 368 369 echo "Canonical qualification receipt emitted at:" 370 echo " $RECEIPT_FILE" 371 echo "" 372 echo "=== MILESTONE 3: ALL GATES PASS ==="