omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tests / fabric / fabric_receipt.sh
| 1 | #!/bin/bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | # fabric_receipt.sh -- receipt for the Fabric F5-0 exit gate (mk/fabric.mk, |
| 18 | # pure seeded OM-2). |
| 19 | # |
| 20 | # tests/fabric/fabric_receipt.sh [out-dir] (default: evidence/F5-0) |
| 21 | # |
| 22 | # Refuses a dirty tree. Runs `make test-fabric` twice from a clean build dir; |
| 23 | # both runs must compile bit-identical pure-OM binaries, pass with zero |
| 24 | # failures and matching check counts, and print identical transcript, state, |
| 25 | # and replay digests. Writes a NEW file named by the SHA-256 of its own bytes. |
| 26 | # Never rewrites an existing receipt. Host-only, loopback only: this receipt |
| 27 | # qualifies nothing physical and no real transport. Shell + coreutils only. |
| 28 | set -u |
| 29 | HERE=$(cd "$(dirname "$0")/../.." && pwd) |
| 30 | cd "$HERE" || exit 2 |
| 31 | OUTDIR=${1:-evidence/F5-0} |
| 32 | BUILD_OUT=${OUT_DIR:-build} |
| 33 | FAB_OMC=${FAB_OMC:-seed/out/omc} |
| 34 | |
| 35 | if [ -n "$(git status --porcelain)" ]; then |
| 36 | echo "fabric_receipt: refusing: working tree is dirty (commit first)" >&2 |
| 37 | exit 3 |
| 38 | fi |
| 39 | head0=$(git rev-parse HEAD) |
| 40 | tree0=$(git rev-parse 'HEAD^{tree}') |
| 41 | run_id=$(date -u +%Y%m%dT%H%M%SZ) |
| 42 | W=$(mktemp -d) |
| 43 | trap 'rm -rf "$W"' EXIT |
| 44 | |
| 45 | run() { # $1 = label |
| 46 | rm -rf "$BUILD_OUT/fabric" |
| 47 | make --no-print-directory OUT_DIR="$BUILD_OUT" FAB_OMC="$FAB_OMC" \ |
| 48 | PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-fabric > "$W/$1.log" 2>&1 |
| 49 | local rc=$? |
| 50 | if [ -f "$BUILD_OUT/fabric/fabric_test" ]; then |
| 51 | sha256sum "$BUILD_OUT/fabric/fabric_test" | awk '{print $1}' > "$W/$1.bin.sha256" |
| 52 | fi |
| 53 | echo $rc |
| 54 | } |
| 55 | rc1=$(run run1) |
| 56 | rc2=$(run run2) |
| 57 | dig() { awk -v k="$2" '$1 == k {print $2}' "$W/$1.log" | tail -n 1; } |
| 58 | is_hex64() { case "$1" in [0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]) return 0 ;; *) return 1 ;; esac; } |
| 59 | |
| 60 | d1=$(dig run1 replay_digest); d2=$(dig run2 replay_digest) |
| 61 | t1=$(dig run1 transcript); t2=$(dig run2 transcript) |
| 62 | sa1=$(dig run1 state_A); sa2=$(dig run2 state_A) |
| 63 | sb1=$(dig run1 state_B); sb2=$(dig run2 state_B) |
| 64 | sc1=$(dig run1 state_C); sc2=$(dig run2 state_C) |
| 65 | v1=$(grep -c '^F5_0_FABRIC_LOOPBACK_PASS$' "$W/run1.log") |
| 66 | v2=$(grep -c '^F5_0_FABRIC_LOOPBACK_PASS$' "$W/run2.log") |
| 67 | f_lines=$(grep -c '^F5_0_FABRIC_LOOPBACK_FAIL$' "$W/run1.log" "$W/run2.log" | awk -F: '{s+=$2} END{print s+0}') |
| 68 | checks1=$(awk '$1 == "checks" {print $2; exit}' "$W/run1.log") |
| 69 | checks2=$(awk '$1 == "checks" {print $2; exit}' "$W/run2.log") |
| 70 | fails1=$(awk '$1 == "checks" {for (i=1;i<=NF;i++) if ($i=="failures") {print $(i+1); exit}}' "$W/run1.log") |
| 71 | fails2=$(awk '$1 == "checks" {for (i=1;i<=NF;i++) if ($i=="failures") {print $(i+1); exit}}' "$W/run2.log") |
| 72 | bin1=$(cat "$W/run1.bin.sha256" 2>/dev/null || true) |
| 73 | bin2=$(cat "$W/run2.bin.sha256" 2>/dev/null || true) |
| 74 | head1=$(git rev-parse HEAD) |
| 75 | dirty1=$(git status --porcelain | grep -v "^?? ${BUILD_OUT}/" || true) |
| 76 | |
| 77 | reasons="" |
| 78 | [ "$rc1" = 0 ] && [ "$rc2" = 0 ] || reasons="$reasons make-failed($rc1,$rc2)" |
| 79 | [ "$v1" = 1 ] && [ "$v2" = 1 ] && [ "$f_lines" = 0 ] || reasons="$reasons verdict-line-missing($v1,$v2,fail=$f_lines)" |
| 80 | [ -n "$checks1" ] && [ "$checks1" -gt 0 ] 2>/dev/null && [ "$checks1" = "$checks2" ] || reasons="$reasons checks-missing-or-differs($checks1,$checks2)" |
| 81 | [ "$fails1" = 0 ] && [ "$fails2" = 0 ] || reasons="$reasons nonzero-failures($fails1,$fails2)" |
| 82 | is_hex64 "$d1" && [ "$d1" = "$d2" ] || reasons="$reasons replay-digest-differs" |
| 83 | is_hex64 "$t1" && [ "$t1" = "$t2" ] || reasons="$reasons transcript-differs" |
| 84 | is_hex64 "$sa1" && [ "$sa1" = "$sa2" ] && is_hex64 "$sb1" && [ "$sb1" = "$sb2" ] && is_hex64 "$sc1" && [ "$sc1" = "$sc2" ] || reasons="$reasons state-digests-differ" |
| 85 | is_hex64 "$bin1" && [ "$bin1" = "$bin2" ] || reasons="$reasons binary-digest-differs" |
| 86 | [ "$head0" = "$head1" ] || reasons="$reasons head-moved" |
| 87 | [ -z "$dirty1" ] || reasons="$reasons tree-dirty-after" |
| 88 | verdict=PASS; [ -z "$reasons" ] || verdict=FAIL |
| 89 | |
| 90 | log_sha=$(cat "$W/run1.log" "$W/run2.log" | sha256sum | awk '{print $1}') |
| 91 | src_sha=$(cat seed/ng/sha256.om src/runtime/aien_machine_id.om src/fabric/fab_hmac.om src/fabric/fab_loopback.om src/fabric/fabric.om tests/fabric/fabric_test.om mk/fabric.mk | sha256sum | awk '{print $1}') |
| 92 | omc_sha=$(sha256sum "$FAB_OMC" 2>/dev/null | awk '{print $1}') |
| 93 | mkdir -p "$OUTDIR" |
| 94 | cat > "$W/receipt.json" <<JSON |
| 95 | { |
| 96 | "schema": "omega.f5-0.fabric-loopback.receipt.v2", |
| 97 | "gate": "F5_0_FABRIC_LOOPBACK", |
| 98 | "build_mode": "pure-om2", |
| 99 | "verdict": "$verdict", |
| 100 | "reasons": "$(echo $reasons)", |
| 101 | "scope": "host-only, pure seeded OM-2 binary compiled by seed/out/omc, in-process loopback transport, HMAC stand-in authenticator; no real network, no TRUST-1 signature, no hardware qualification", |
| 102 | "commit": "$head0", |
| 103 | "tree": "$tree0", |
| 104 | "run_id": "$run_id", |
| 105 | "command": "make test-fabric (twice, clean OUT_DIR/fabric each time)", |
| 106 | "checks_per_binary_run": "${checks1:-null}", |
| 107 | "failures_per_binary_run": "${fails1:-null}", |
| 108 | "replay_digest_run1": "${d1:-null}", |
| 109 | "replay_digest_run2": "${d2:-null}", |
| 110 | "transcript": "${t1:-null}", |
| 111 | "state_A": "${sa1:-null}", |
| 112 | "state_B": "${sb1:-null}", |
| 113 | "state_C": "${sc1:-null}", |
| 114 | "binary_sha256_run1": "${bin1:-null}", |
| 115 | "binary_sha256_run2": "${bin2:-null}", |
| 116 | "omc_sha256": "${omc_sha:-null}", |
| 117 | "fabric_sources_sha256": "$src_sha", |
| 118 | "logs_sha256": "$log_sha", |
| 119 | "host": "$(uname -srm)" |
| 120 | } |
| 121 | JSON |
| 122 | name=$(sha256sum "$W/receipt.json" | awk '{print $1}') |
| 123 | if [ -e "$OUTDIR/$name.json" ]; then |
| 124 | echo "fabric_receipt: $OUTDIR/$name.json already exists; not rewritten" >&2 |
| 125 | else |
| 126 | cp "$W/receipt.json" "$OUTDIR/$name.json" |
| 127 | fi |
| 128 | echo "$verdict $OUTDIR/$name.json" |
| 129 | [ "$verdict" = PASS ] |