interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / tests / r15_receipt_test.sh

190 lines · 12753 bytes Raw Blame History
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.
23set -u
24HERE=$(cd "$(dirname "$0")/.." && pwd)
25RAW=$HERE/evidence/R15/raw/20260929T020536Z-ad8e1f2ea4e4-silicon
26OUT=$HERE/build/r15-receipt-test
27rm -rf "$OUT"; mkdir -p "$OUT"
28FAILS=0
29check() { if eval "$2"; then echo "ok $1"; else echo "FAIL $1"; FAILS=$((FAILS + 1)); fi; }
30
31R=$("$HERE/tools/r15_receipt.sh" "$RAW" "$OUT" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a)
32rc=$?
33check "writer exits 1 (FAIL outcome)" '[ $rc = 1 ]'
34check "receipt file written" '[ -s "$R" ]'
35check "named by its own SHA-256" '[ "$(basename "$R" .json)" = "$(sha256sum "$R" | cut -d" " -f1)" ]'
36
37for 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"'
45done
46for 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"'
48done
49check "schema AIEN_RX_R15_REACTION_PERFORMANCE_V1" 'grep -q "\"schema\": \"AIEN_RX_R15_REACTION_PERFORMANCE_V1\"" "$R"'
50check "outcome == FAIL" 'grep -q "\"outcome\": \"FAIL\"" "$R"'
51check "reason names G10" 'grep -q "gate G10 FAIL" "$R"'
52check "reason names blank aienos_commit" 'grep -q "aienos_commit not recorded" "$R"'
53check "reason names missing reruns" 'grep -q "correctness reruns (§14) not recorded" "$R"'
54check "G10 listed under regressions" 'grep -o "\"regressions\": \[.*\"id\":\"G10\"" "$R" >/dev/null'
55check "historical run is not provenance-bound" 'grep -q "\"run_commit\": \"ad8e1f2ea4e4906ed810c6bd696cc905b801d69a\"" "$R" && grep -q "\"candidate_bound\": false" "$R" && grep -q "PROVENANCE_SHA256SUMS missing" "$R"'
56check "raw digest matches reducer" 'grep -q "\"raw_digest_matches_reducer\": true" "$R" && grep -q "\"raw_files_verified\": true" "$R"'
57check "16 gates present" 'grep -q "\"gates_present\": 16" "$R"'
58if command -v jq >/dev/null; then
59 check "valid JSON (jq)" 'jq -e .outcome "$R" >/dev/null'
60else
61 echo "note jq not installed: JSON validity not checked"
62fi
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).
66SYN=$OUT/syn; mkdir -p "$SYN"; cp "$RAW"/* "$SYN"/
67sed -i 's/"outcome":"FAIL"/"outcome":"PASS"/; s/"all_gates_pass":false/"all_gates_pass":true/' "$SYN/summary.json"
68sed -i 's/"aienos_commit":""/"aienos_commit":"c8ab65e3ba2fddbe99245f747fdfdb99f6042fd3"/' "$SYN/machine.json"
69mkdir "$SYN/bin"
70printf 'synthetic trial executable\n' > "$SYN/bin/rx_r15_perf_silicon"
71printf 'synthetic nodigest executable\n' > "$SYN/bin/rx_r15_perf_silicon_nodigest"
72printf 'synthetic reducer executable\n' > "$SYN/bin/r15_reduce"
73chmod 0555 "$SYN/bin/"*
74TRIAL_SHA=$(sha256sum "$SYN/bin/rx_r15_perf_silicon" | cut -d' ' -f1)
75ND_SHA=$(sha256sum "$SYN/bin/rx_r15_perf_silicon_nodigest" | cut -d' ' -f1)
76RED_SHA=$(sha256sum "$SYN/bin/r15_reduce" | cut -d' ' -f1)
77BINARIES="{\"trial\":\"$TRIAL_SHA\",\"nodigest\":\"$ND_SHA\",\"reducer\":\"$RED_SHA\"}"
78sed -i "s/\"binaries\":{[^}]*}/\"binaries\":$BINARIES/" "$SYN/machine.json"
79printf 'synthetic isolated build log\n' > "$SYN/build.log"
80BUILD_LOG_SHA=$(sha256sum "$SYN/build.log" | cut -d' ' -f1)
81PHYSICS=$(grep -o '"physics_commit":"[^"]*"' "$SYN/machine.json" | sed 's/.*:"//; s/"$//')
82H1=$(printf '%064x' 1); H2=$(printf '%064x' 2); H3=$(printf '%064x' 3)
83H4=$(printf '%064x' 4); H5=$(printf '%064x' 5)
84cat > "$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}
86EOF
87cat > "$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}
89EOF
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.
94sed -i "s/^[0-9a-f]* machine.json\$/$(sha256sum "$SYN/machine.json" | cut -d' ' -f1) machine.json/" "$SYN/SHA256SUMS"
95sed -i "s/\"raw_digest_sha256_of_SHA256SUMS\":\"[0-9a-f]*\"/\"raw_digest_sha256_of_SHA256SUMS\":\"$(sha256sum "$SYN/SHA256SUMS" | cut -d' ' -f1)\"/" "$SYN/summary.json"
96printf '{' > "$OUT/reruns.json"
97for 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
99sed -i 's/,$/}/' "$OUT/reruns.json"
100"$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a >/dev/null 2>&1
101check "all gates PASS but no reruns -> still FAIL" '[ $? = 1 ]'
102P=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns.json")
103check "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
105printf '{\n' > "$OUT/reruns-formatted.json"
106first=1
107for 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"
111done
112printf '\n}\n' >> "$OUT/reruns-formatted.json"
113F=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns-formatted.json")
114check "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.
119bad_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
127printf '{"reported":' > "$OUT/reruns-nested.json"
128cat "$OUT/reruns.json" >> "$OUT/reruns-nested.json"
129printf '}' >> "$OUT/reruns-nested.json"
130bad_reruns "nested decoy PASS keys" "$OUT/reruns-nested.json"
131
132sed 's/}$/,"R3":"FAIL"}/' "$OUT/reruns.json" > "$OUT/reruns-duplicate.json"
133bad_reruns "duplicate conflicting key" "$OUT/reruns-duplicate.json"
134
135sed 's/}$/,"R\\u0033":"FAIL"}/' "$OUT/reruns.json" > "$OUT/reruns-escaped-duplicate.json"
136bad_reruns "escaped duplicate key" "$OUT/reruns-escaped-duplicate.json"
137
138sed 's/"R7":"PASS"/"R\\u0033":"FAIL"/' "$OUT/reruns.json" > "$OUT/reruns-escaped-duplicate-13.json"
139bad_reruns "decoded duplicate among thirteen keys" "$OUT/reruns-escaped-duplicate-13.json"
140
141sed 's/}$/,"extra":"PASS"}/' "$OUT/reruns.json" > "$OUT/reruns-extra.json"
142bad_reruns "extra root key" "$OUT/reruns-extra.json"
143
144sed 's/"R3":"PASS"/"R3":true/' "$OUT/reruns.json" > "$OUT/reruns-nonstring.json"
145bad_reruns "non-string PASS value" "$OUT/reruns-nonstring.json"
146
147sed 's/"R3":"PASS"/"R3":"FAIL"/' "$OUT/reruns.json" > "$OUT/reruns-fail.json"
148bad_reruns "non-PASS string value" "$OUT/reruns-fail.json"
149
150sed 's/"R3":"PASS",//' "$OUT/reruns.json" > "$OUT/reruns-missing.json"
151bad_reruns "missing required key" "$OUT/reruns-missing.json"
152
153sed 's/}$//' "$OUT/reruns.json" > "$OUT/reruns-malformed.json"
154bad_reruns "malformed JSON" "$OUT/reruns-malformed.json"
155
156printf '%s{"injected":true}\n' "$(cat "$OUT/reruns.json")" > "$OUT/reruns-trailing.json"
157bad_reruns "trailing second value" "$OUT/reruns-trailing.json"
158
159sed 's/"R3":"PASS"/"R3":"\\u0050ASS"/' "$OUT/reruns.json" > "$OUT/reruns-pass-escape.json"
160E=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-pass-escape" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns-pass-escape.json")
161check "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
164check "wrong candidate -> FAIL" '[ $? = 1 ]'
165check "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.
169MUT=$OUT/replaced-bin; mkdir -p "$MUT"; cp -a "$SYN"/. "$MUT"/
170chmod u+w "$MUT/bin/rx_r15_perf_silicon"; printf 'replacement\n' > "$MUT/bin/rx_r15_perf_silicon"
171M=$($HERE/tools/r15_receipt.sh "$MUT" "$OUT/replaced-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns.json")
172check "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
175printf '# test notes\nregression\tL1-A p50 ns\t7376\t4688\ttest justification\nlimit\ttest limit text\n' > "$OUT/notes.tsv"
176N=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-notes" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns.json" "$OUT/notes.tsv")
177check "notes: still PASS" '[ $? = 0 ]'
178check "notes: regression listed" 'grep -q "\"metric\":\"L1-A p50 ns\",\"resident\":\"7376\",\"seq\":\"4688\",\"justification\":\"test justification\"" "$N"'
179check "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)
182ND=$OUT/nd; mkdir -p "$ND"; cp -a "$SYN"/. "$ND"/
183f=$(ls "$ND"/trial-RES1ND-*.jsonl | head -1); sed -i 's/"causal_digest":0/"causal_digest":1/' "$f"
184sed -i "s/^[0-9a-f]* $(basename "$f")\$/$(sha256sum "$f" | cut -d' ' -f1) $(basename "$f")/" "$ND/SHA256SUMS"
185sed -i "s/\"raw_digest_sha256_of_SHA256SUMS\":\"[0-9a-f]*\"/\"raw_digest_sha256_of_SHA256SUMS\":\"$(sha256sum "$ND/SHA256SUMS" | cut -d' ' -f1)\"/" "$ND/summary.json"
186Q=$("$HERE/tools/r15_receipt.sh" "$ND" "$OUT/nd-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns.json")
187check "NODIGEST process with digests on -> FAIL" '[ $? = 1 ] && grep -q "causal_digest values .1., expected 0" "$Q" && grep -q "\"raw_files_verified\": true" "$Q"'
188
189echo "r15 receipt test: $FAILS failure(s)"
190[ $FAILS = 0 ]