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 / r15_receipt_test.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 | # r15_receipt_test.sh -- host test for tools/r15_receipt.sh. Runs the writer on |
| 18 | # the recorded attempt-1 raw data (evidence/R15/raw/20260929T020536Z-...) into |
| 19 | # build/, then checks: every §12/§13 required field is present, outcome is |
| 20 | # FAIL (G10 failed, aienos_commit blank, no correctness reruns), the failed |
| 21 | # gate is listed under regressions, historical runs without build provenance |
| 22 | # are not candidate-bound, and the file is named by its own SHA-256. |
| 23 | set -u |
| 24 | HERE=$(cd "$(dirname "$0")/.." && pwd) |
| 25 | RAW=$HERE/evidence/R15/raw/20260929T020536Z-ad8e1f2ea4e4-silicon |
| 26 | OUT=$HERE/build/r15-receipt-test |
| 27 | rm -rf "$OUT"; mkdir -p "$OUT" |
| 28 | FAILS=0 |
| 29 | check() { if eval "$2"; then echo "ok $1"; else echo "FAIL $1"; FAILS=$((FAILS + 1)); fi; } |
| 30 | |
| 31 | R=$("$HERE/tools/r15_receipt.sh" "$RAW" "$OUT" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a) |
| 32 | rc=$? |
| 33 | check "writer exits 1 (FAIL outcome)" '[ $rc = 1 ]' |
| 34 | check "receipt file written" '[ -s "$R" ]' |
| 35 | check "named by its own SHA-256" '[ "$(basename "$R" .json)" = "$(sha256sum "$R" | cut -d" " -f1)" ]' |
| 36 | |
| 37 | for k in schema run_id outcome outcome_reasons candidate_commit run_commit candidate_bound \ |
| 38 | tree_dirty silicon_observed aienos_commit physics_commit benchmark_binaries_sha256 \ |
| 39 | provenance_digest_sha256 provenance_files_verified build_provenance final_state \ |
| 40 | raw_digest_sha256 reducer_source_sha256 legacy_status seq_selector_symbol nodigest_macro \ |
| 41 | gates correctness_reruns regressions limits not_claimed hardware_identity summary \ |
| 42 | hostname machine_id_sha256 kernel midr governor_freq mem_kb gpu secure_boot lockdown \ |
| 43 | perf_event_paranoid thermal_mc compiler binaries metrics comparisons all_gates_pass; do |
| 44 | check "field $k present" 'grep -q "\"$k\":" "$R"' |
| 45 | done |
| 46 | for m in m1_ m2_ m3_ m4_ m5_ m6_ m7_ m8_ m9_ m10_ m11_ m12_13_14_15_ m16_ m17_; do # the reducer reports 12-15 together |
| 47 | check "metric ${m%_} present" 'grep -q "\"$m[a-z0-9_]*\":" "$R"' |
| 48 | done |
| 49 | check "schema AIEN_RX_R15_REACTION_PERFORMANCE_V1" 'grep -q "\"schema\": \"AIEN_RX_R15_REACTION_PERFORMANCE_V1\"" "$R"' |
| 50 | check "outcome == FAIL" 'grep -q "\"outcome\": \"FAIL\"" "$R"' |
| 51 | check "reason names G10" 'grep -q "gate G10 FAIL" "$R"' |
| 52 | check "reason names blank aienos_commit" 'grep -q "aienos_commit not recorded" "$R"' |
| 53 | check "reason names missing reruns" 'grep -q "correctness reruns (§14) not recorded" "$R"' |
| 54 | check "G10 listed under regressions" 'grep -o "\"regressions\": \[.*\"id\":\"G10\"" "$R" >/dev/null' |
| 55 | check "historical run is not provenance-bound" 'grep -q "\"run_commit\": \"ad8e1f2ea4e4906ed810c6bd696cc905b801d69a\"" "$R" && grep -q "\"candidate_bound\": false" "$R" && grep -q "PROVENANCE_SHA256SUMS missing" "$R"' |
| 56 | check "raw digest matches reducer" 'grep -q "\"raw_digest_matches_reducer\": true" "$R" && grep -q "\"raw_files_verified\": true" "$R"' |
| 57 | check "16 gates present" 'grep -q "\"gates_present\": 16" "$R"' |
| 58 | if command -v jq >/dev/null; then |
| 59 | check "valid JSON (jq)" 'jq -e .outcome "$R" >/dev/null' |
| 60 | else |
| 61 | echo "note jq not installed: JSON validity not checked" |
| 62 | fi |
| 63 | |
| 64 | # A PASS needs everything: flip only the inputs the writer judges and check it |
| 65 | # still refuses without reruns and accepts with them (synthetic copy, build/ only). |
| 66 | SYN=$OUT/syn; mkdir -p "$SYN"; cp "$RAW"/* "$SYN"/ |
| 67 | sed -i 's/"outcome":"FAIL"/"outcome":"PASS"/; s/"all_gates_pass":false/"all_gates_pass":true/' "$SYN/summary.json" |
| 68 | sed -i 's/"aienos_commit":""/"aienos_commit":"c8ab65e3ba2fddbe99245f747fdfdb99f6042fd3"/' "$SYN/machine.json" |
| 69 | mkdir "$SYN/bin" |
| 70 | printf 'synthetic trial executable\n' > "$SYN/bin/rx_r15_perf_silicon" |
| 71 | printf 'synthetic nodigest executable\n' > "$SYN/bin/rx_r15_perf_silicon_nodigest" |
| 72 | printf 'synthetic reducer executable\n' > "$SYN/bin/r15_reduce" |
| 73 | chmod 0555 "$SYN/bin/"* |
| 74 | TRIAL_SHA=$(sha256sum "$SYN/bin/rx_r15_perf_silicon" | cut -d' ' -f1) |
| 75 | ND_SHA=$(sha256sum "$SYN/bin/rx_r15_perf_silicon_nodigest" | cut -d' ' -f1) |
| 76 | RED_SHA=$(sha256sum "$SYN/bin/r15_reduce" | cut -d' ' -f1) |
| 77 | BINARIES="{\"trial\":\"$TRIAL_SHA\",\"nodigest\":\"$ND_SHA\",\"reducer\":\"$RED_SHA\"}" |
| 78 | sed -i "s/\"binaries\":{[^}]*}/\"binaries\":$BINARIES/" "$SYN/machine.json" |
| 79 | printf 'synthetic isolated build log\n' > "$SYN/build.log" |
| 80 | BUILD_LOG_SHA=$(sha256sum "$SYN/build.log" | cut -d' ' -f1) |
| 81 | PHYSICS=$(grep -o '"physics_commit":"[^"]*"' "$SYN/machine.json" | sed 's/.*:"//; s/"$//') |
| 82 | H1=$(printf '%064x' 1); H2=$(printf '%064x' 2); H3=$(printf '%064x' 3) |
| 83 | H4=$(printf '%064x' 4); H5=$(printf '%064x' 5) |
| 84 | cat > "$SYN/build-provenance.json" <<EOF |
| 85 | {"schema":"AIEN_RX_R15_BUILD_PROVENANCE_V1","candidate_commit":"ad8e1f2ea4e4906ed810c6bd696cc905b801d69a","candidate_archive_sha256":"$H1","physics_commit":"$PHYSICS","physics_archive_sha256":"$H2","aienos_commit":"c8ab65e3ba2fddbe99245f747fdfdb99f6042fd3","aienos_archive_sha256":"$H3","build_command":"synthetic isolated make","compiler_path":"/usr/bin/gcc","compiler_sha256":"$H4","compiler_version":"synthetic gcc","make_path":"/usr/bin/make","make_sha256":"$H5","make_version":"synthetic make","build_log_sha256":"$BUILD_LOG_SHA","binaries":$BINARIES} |
| 86 | EOF |
| 87 | cat > "$SYN/final-state.json" <<EOF |
| 88 | {"schema":"AIEN_RX_R15_FINAL_STATE_V1","candidate_commit":"ad8e1f2ea4e4906ed810c6bd696cc905b801d69a","final_head":"ad8e1f2ea4e4906ed810c6bd696cc905b801d69a","tracked_tree_dirty":false,"head_unchanged":true,"binaries_unchanged":true,"binaries":$BINARIES} |
| 89 | EOF |
| 90 | (cd "$SYN" && sha256sum build.log build-provenance.json final-state.json \ |
| 91 | bin/rx_r15_perf_silicon bin/rx_r15_perf_silicon_nodigest bin/r15_reduce > PROVENANCE_SHA256SUMS) |
| 92 | # machine.json is covered by SHA256SUMS, and the reducer's raw digest covers |
| 93 | # SHA256SUMS: re-seal both so only the judged inputs differ. |
| 94 | sed -i "s/^[0-9a-f]* machine.json\$/$(sha256sum "$SYN/machine.json" | cut -d' ' -f1) machine.json/" "$SYN/SHA256SUMS" |
| 95 | sed -i "s/\"raw_digest_sha256_of_SHA256SUMS\":\"[0-9a-f]*\"/\"raw_digest_sha256_of_SHA256SUMS\":\"$(sha256sum "$SYN/SHA256SUMS" | cut -d' ' -f1)\"/" "$SYN/summary.json" |
| 96 | printf '{' > "$OUT/reruns.json" |
| 97 | for k in R3 R7 R8 R9 R10 R11 R12_host R12_silicon R13_host R13_silicon R14_host R14_silicon R15_SEQ_parity; do |
| 98 | printf '"%s":"PASS",' "$k" >> "$OUT/reruns.json"; done |
| 99 | sed -i 's/,$/}/' "$OUT/reruns.json" |
| 100 | "$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a >/dev/null 2>&1 |
| 101 | check "all gates PASS but no reruns -> still FAIL" '[ $? = 1 ]' |
| 102 | P=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns.json") |
| 103 | check "all gates PASS + provenance + reruns PASS -> PASS" '[ $? = 0 ] && grep -q "\"outcome\": \"PASS\"" "$P" && grep -q "\"candidate_bound\": true" "$P" && grep -q "\"provenance_files_verified\": true" "$P"' |
| 104 | |
| 105 | printf '{\n' > "$OUT/reruns-formatted.json" |
| 106 | first=1 |
| 107 | for k in R15_SEQ_parity R14_silicon R14_host R13_silicon R13_host R12_silicon R12_host R11 R10 R9 R8 R7 R3; do |
| 108 | [ $first = 1 ] || printf ',\n' >> "$OUT/reruns-formatted.json" |
| 109 | first=0 |
| 110 | printf ' "%s" : "PASS"' "$k" >> "$OUT/reruns-formatted.json" |
| 111 | done |
| 112 | printf '\n}\n' >> "$OUT/reruns-formatted.json" |
| 113 | F=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns-formatted.json") |
| 114 | check "reordered whitespace-formatted reruns -> PASS" '[ $? = 0 ] && grep -q "\"outcome\": \"PASS\"" "$F"' |
| 115 | |
| 116 | # The rerun input is a security boundary: only the exact root object is |
| 117 | # accepted. The structural fixtures retain enough PASS substrings for the old |
| 118 | # grep loop to accept them; the value fixtures exercise the exact schema. |
| 119 | bad_reruns() { # label file |
| 120 | label=$1; file=$2 |
| 121 | Q=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$file") |
| 122 | qrc=$? |
| 123 | check "$label -> FAIL" '[ $qrc = 1 ] && grep -q "correctness reruns must be one exact root object" "$Q"' |
| 124 | check "$label -> untrusted JSON not embedded" 'grep -Fq "\"correctness_reruns\": {\"status\":\"invalid\"}" "$Q"' |
| 125 | } |
| 126 | |
| 127 | printf '{"reported":' > "$OUT/reruns-nested.json" |
| 128 | cat "$OUT/reruns.json" >> "$OUT/reruns-nested.json" |
| 129 | printf '}' >> "$OUT/reruns-nested.json" |
| 130 | bad_reruns "nested decoy PASS keys" "$OUT/reruns-nested.json" |
| 131 | |
| 132 | sed 's/}$/,"R3":"FAIL"}/' "$OUT/reruns.json" > "$OUT/reruns-duplicate.json" |
| 133 | bad_reruns "duplicate conflicting key" "$OUT/reruns-duplicate.json" |
| 134 | |
| 135 | sed 's/}$/,"R\\u0033":"FAIL"}/' "$OUT/reruns.json" > "$OUT/reruns-escaped-duplicate.json" |
| 136 | bad_reruns "escaped duplicate key" "$OUT/reruns-escaped-duplicate.json" |
| 137 | |
| 138 | sed 's/"R7":"PASS"/"R\\u0033":"FAIL"/' "$OUT/reruns.json" > "$OUT/reruns-escaped-duplicate-13.json" |
| 139 | bad_reruns "decoded duplicate among thirteen keys" "$OUT/reruns-escaped-duplicate-13.json" |
| 140 | |
| 141 | sed 's/}$/,"extra":"PASS"}/' "$OUT/reruns.json" > "$OUT/reruns-extra.json" |
| 142 | bad_reruns "extra root key" "$OUT/reruns-extra.json" |
| 143 | |
| 144 | sed 's/"R3":"PASS"/"R3":true/' "$OUT/reruns.json" > "$OUT/reruns-nonstring.json" |
| 145 | bad_reruns "non-string PASS value" "$OUT/reruns-nonstring.json" |
| 146 | |
| 147 | sed 's/"R3":"PASS"/"R3":"FAIL"/' "$OUT/reruns.json" > "$OUT/reruns-fail.json" |
| 148 | bad_reruns "non-PASS string value" "$OUT/reruns-fail.json" |
| 149 | |
| 150 | sed 's/"R3":"PASS",//' "$OUT/reruns.json" > "$OUT/reruns-missing.json" |
| 151 | bad_reruns "missing required key" "$OUT/reruns-missing.json" |
| 152 | |
| 153 | sed 's/}$//' "$OUT/reruns.json" > "$OUT/reruns-malformed.json" |
| 154 | bad_reruns "malformed JSON" "$OUT/reruns-malformed.json" |
| 155 | |
| 156 | printf '%s{"injected":true}\n' "$(cat "$OUT/reruns.json")" > "$OUT/reruns-trailing.json" |
| 157 | bad_reruns "trailing second value" "$OUT/reruns-trailing.json" |
| 158 | |
| 159 | sed 's/"R3":"PASS"/"R3":"\\u0050ASS"/' "$OUT/reruns.json" > "$OUT/reruns-pass-escape.json" |
| 160 | E=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-pass-escape" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns-pass-escape.json") |
| 161 | check "decoded PASS escape -> PASS" '[ $? = 0 ] && grep -q "\"outcome\": \"PASS\"" "$E"' |
| 162 | |
| 163 | "$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" 0000000000000000000000000000000000000000 "$OUT/reruns.json" >/dev/null |
| 164 | check "wrong candidate -> FAIL" '[ $? = 1 ]' |
| 165 | check "nodigest flag checked from raw" 'grep -q "\"checked_from_raw\": true, \"nodigest_processes_digest_off\": 12, \"production_processes_digest_on\": 46" "$R"' |
| 166 | |
| 167 | # Replacing a sealed executable after the run invalidates provenance and can |
| 168 | # never retain candidate_bound, even though machine.json still has the initial digest. |
| 169 | MUT=$OUT/replaced-bin; mkdir -p "$MUT"; cp -a "$SYN"/. "$MUT"/ |
| 170 | chmod u+w "$MUT/bin/rx_r15_perf_silicon"; printf 'replacement\n' > "$MUT/bin/rx_r15_perf_silicon" |
| 171 | M=$($HERE/tools/r15_receipt.sh "$MUT" "$OUT/replaced-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns.json") |
| 172 | check "replaced executable -> FAIL, not candidate-bound" '[ $? = 1 ] && grep -q "build provenance files do not verify" "$M" && grep -q "\"candidate_bound\": false" "$M"' |
| 173 | |
| 174 | # human-written notes: a regression and a limit are copied into the receipt |
| 175 | printf '# test notes\nregression\tL1-A p50 ns\t7376\t4688\ttest justification\nlimit\ttest limit text\n' > "$OUT/notes.tsv" |
| 176 | N=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-notes" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns.json" "$OUT/notes.tsv") |
| 177 | check "notes: still PASS" '[ $? = 0 ]' |
| 178 | check "notes: regression listed" 'grep -q "\"metric\":\"L1-A p50 ns\",\"resident\":\"7376\",\"seq\":\"4688\",\"justification\":\"test justification\"" "$N"' |
| 179 | check "notes: limit listed" 'grep -q "\"limits\": \[\"test limit text\"\]" "$N"' |
| 180 | |
| 181 | # a NODIGEST process that kept digests on must fail the receipt (re-sealed) |
| 182 | ND=$OUT/nd; mkdir -p "$ND"; cp -a "$SYN"/. "$ND"/ |
| 183 | f=$(ls "$ND"/trial-RES1ND-*.jsonl | head -1); sed -i 's/"causal_digest":0/"causal_digest":1/' "$f" |
| 184 | sed -i "s/^[0-9a-f]* $(basename "$f")\$/$(sha256sum "$f" | cut -d' ' -f1) $(basename "$f")/" "$ND/SHA256SUMS" |
| 185 | sed -i "s/\"raw_digest_sha256_of_SHA256SUMS\":\"[0-9a-f]*\"/\"raw_digest_sha256_of_SHA256SUMS\":\"$(sha256sum "$ND/SHA256SUMS" | cut -d' ' -f1)\"/" "$ND/summary.json" |
| 186 | Q=$("$HERE/tools/r15_receipt.sh" "$ND" "$OUT/nd-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns.json") |
| 187 | check "NODIGEST process with digests on -> FAIL" '[ $? = 1 ] && grep -q "causal_digest values .1., expected 0" "$Q" && grep -q "\"raw_files_verified\": true" "$Q"' |
| 188 | |
| 189 | echo "r15 receipt test: $FAILS failure(s)" |
| 190 | [ $FAILS = 0 ] |