Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
About Files History Releases Proposed changes Issues For developers
[Codex Security] R15 receipts bind a one-time snapshot but execute mutable prebuilt binaries
open fa0488efb839e059 #7 · opened 2026-11-15 17:07 UTC
Imported from GitHub drakestapleton/omega-mv#7, by drakestapleton
Base 91f88c287d7831784a808c5b054818fd9055afb5 · Head b9a8545a0776da2ddc7113086b0a4b9b711435e4
drakestapleton wrote on 2026-11-15 17:07 UTC
R15 now binds qualification to freshly built, sealed candidate artifacts.
Builds use verified Omega, Physics, and AIENOS commit archives in a private directory.
Trial and reducer copies are digest-checked around every execution, closing mutable-path replacement.
Receipt PASS requires sealed provenance, matching binary hashes, and unchanged final HEAD and tree state.
Host and silicon modes, trial ordering, reducer semantics, notes, and correctness reruns remain supported.
Static Verification Checks
Apply it
git checkout -b patch-fa0488efb839e059 91f88c287d7831784a808c5b054818fd9055afb5
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/fa0488efb839e059 .patch | git am
Raw patch (mbox) · Diff
Provenance
This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:
github-import 1
drakestapleton/omega-mv
7
b9a8545a0776da2ddc7113086b0a4b9b711435e4
{"kind":"github-import","owner":"drakestapleton","repo":"omega-mv","number":7,"url":"https://github.com/drakestapleton/omega-mv/pull/7","export_sha256":"7a4dc05cfaafc4ff4b6c7811f8b55128091a7d4d233c7761f900f26220660f83 ","imported_utc":"2026-11-18T16:39:50Z"}
Changes
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index aa4a7bd38 ..57469a1bb 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -7,6 +7,7 @@ The current development method is [Human-Directed Agentic Engineering (HDAE)](RE
| Model | What it did |
|---|---|
+| OpenAI Codex | Bound R15 qualification to fresh candidate/dependency archives, sealed executables, per-execution digest checks, final tree state and receipt-enforced build provenance. |
| Grok 4.7 (via Cursor Agent) | Merged main `fd3751b31 ` (#1020, carrying #1045 and #1050) into #1052. The only conflict was the generated root `.crumb` (child `last_commit` stamps, the `tests` digest, and the root digest). Recompiled with the crumb.lock tool (`d0f0b95d `); `crumb verify .` current. The #525/#962 pins were left as committed: `src/checker2/c2_check.c`, `src/compiler/osc_ir.c` and `src/compiler/osc_ir.h` still hash to the SHA-256s in `ACCEPTED`. |
| Claude Opus 5.5 (via omp) | #1020 (actions/cache-4.3.0 ->6.1.0): merged main `d3d1b1bc ` and recompiled the root crumb with the crumb.lock tool (`d0f0b95d `). The root crumb's source tree covers `.github/workflows/`, so the bump alone left it stale and `AIEN Checks` failed at `crumb verify .` (`1 of 188 crumbs stale`). |
| Claude Opus 5.5 (via omp) | #1018 (actions/upload-artifact-4 ->7): merged main `d3d1b1bc ` and recompiled the root crumb with the crumb.lock tool (`d0f0b95d `). The root crumb's source tree covers `.github/workflows/`, so the bump alone left it stale and `AIEN Checks` failed at `crumb verify .` (`1 of 188 crumbs stale`). |
diff --git a/docs/r15-handoff.md b/docs/r15-handoff.md
index c39e574e8 ..ce4eda41b 100644
--- a/docs/r15-handoff.md
+++ b/docs/r15-handoff.md
@@ -280,16 +280,18 @@ analysis was done first.
rig on X925.
- `l2 <RES1|SEQ>`: 256 closed-loop claims through `living.blackwell.add`;
chip `%globaltimer` pick/done from the heartbeat block.
- - Four binaries: `make r15-perf-host` / `make r15-perf-silicon` (production
- and `_nodigest`) plus `build/r15_reduce`.
+ - Four build targets: `r15-perf-host` / `r15-perf-silicon` (production and
+ `_nodigest`) plus `r15_reduce`. Qualification builds them from verified
+ candidate/dependency archives and stages digest-bound run copies; ignored
+ files under `build/` are never qualification inputs.
- `tools/r15_reduce.c`: verifies every file against SHA256SUMS, recomputes
metrics 1-17 and G1-G16, writes `summary.json`. Seed 0x15, 10,000
resamples, percentile CI; missing data = FAIL.
- `tools/r15_qualify.sh [--detach] <host|silicon> [rounds] [l1] [l2]`: balanced
Latin square, L1, L2, machine.json, paranoid 4 -> 1 -> 4, SHA256SUMS, reducer.
`--detach` = setsid nohup; progress in plain words in `progress.log`.
- Set `AIENOS_R7_DIR`/`PHYSICS_DIR` so the recorded commits are right, and
- `R15_OUT_BASE` for dry runs outside `evidence/`.
+ Set `AIENOS_LOCK_REPO`/`PHYSICS_DIR` to repositories holding the pinned
+ commits, and `R15_OUT_BASE` for dry runs outside `evidence/`.
Still blocking a real qualification: (1) the goal-margin decision above (R14
silicon and G1); (2) §9: LM Studio and Ollama were resident at 13:45 and must
diff --git a/docs/r16-production-entry-point.md b/docs/r16-production-entry-point.md
index 337d5aed4 ..f1e47d7b6 100644
--- a/docs/r16-production-entry-point.md
+++ b/docs/r16-production-entry-point.md
@@ -166,8 +166,9 @@ make $V test-r13-silicon
make $V test-r14-silicon
make $V test-r15-parity-silicon
make $V test-r16-authpath-silicon # G3 silicon
-make $V r15-perf-silicon # builds the R15 binaries and reducer
-PHYSICS_DIR=... AIENOS_R7_DIR=... tools/r15_qualify.sh --detach silicon
+PHYSICS_DIR=... AIENOS_LOCK_REPO=... tools/r15_qualify.sh --detach silicon
+# r15_qualify verifies the pinned Git objects, builds private archive copies,
+# and executes only the digest-bound copies stored in the new raw run directory.
make r15-receipt RUN=evidence/R15/raw/<run-id> CANDIDATE=<commit> RERUNS=<file> NOTES=<file>
```
diff --git a/spec/r15-performance-proof.md b/spec/r15-performance-proof.md
index cc0d69dfd ..db70d34e1 100644
--- a/spec/r15-performance-proof.md
+++ b/spec/r15-performance-proof.md
@@ -422,6 +422,12 @@ coverage, rerun the correctness gates, and repeat the entire qualification.
window, crumb-derived interval, counter snapshot, telemetry sample), each
with run id, configuration, round, trial, and monotonic timestamps; plus
`machine.json` (§13) and `SHA256SUMS`.
+- Build provenance: `build-provenance.json` names the exact omega, physics and
+ aienos archive commits and digests, compiler and make digests and versions,
+ build command/log digest, and source-to-binary hashes. `final-state.json`
+ records final HEAD/tree state and executable hashes after reduction.
+ `PROVENANCE_SHA256SUMS` covers both records, the build log and every staged
+ executable. Section 22 defines the required isolated build and checks.
- Reducer: `tools/r15_reduce.c` (C, no Python), deterministic, reads only the
raw directory, recomputes every summary number and every gate, and writes
`summary.json`. The receipt embeds the reducer source SHA-256 and the raw
@@ -430,7 +436,8 @@ coverage, rerun the correctness gates, and repeat the entire qualification.
`AIEN_RX_R15_REACTION_PERFORMANCE_V1`, named by the SHA-256 of its own
bytes: candidate_commit, run_commit, candidate_bound, tree_dirty,
silicon_observed, hardware identity, aienos and physics commits, benchmark
- binary SHA-256s, raw digest, reducer digest, all 17 metrics, legacy status
+ binary SHA-256s, source archives, toolchain/build provenance, final state,
+ raw digest, reducer digest, all 17 metrics, legacy status
(NOT DIRECTLY COMPARABLE, §2), resident and SEQ results, paired comparisons,
CIs, thresholds and outcomes, correctness reruns, regressions, `not_claimed`.
- No headline number is edited by hand. The receipt's metric values are
@@ -441,8 +448,9 @@ coverage, rerun the correctness gates, and repeat the entire qualification.
Host name, `/etc/machine-id` SHA-256, kernel release, CPU MIDR per core and
core-class map, governor and frequencies, memory size, GPU name and PCI id,
driver version, Secure Boot and lockdown state, `perf_event_paranoid` before
-and during, thermal readings, omega/aienos/physics commits, compiler version,
-benchmark binary SHA-256.
+and during, thermal readings, omega/aienos/physics commits, compiler version
+and digest, build command, source-archive SHA-256s, benchmark/reducer SHA-256s,
+and final HEAD/tree state.
## 14. Correctness reruns required before a PASS
@@ -820,3 +828,43 @@ path's intended advantage (one scan covering many completions). A
multi-claim-in-flight L2 phase (N > 1, e.g. 16, Option B) is deferred to a
later gate and is listed in the receipt's limits. Empty-poll spin cost is
a known host-side cost of both paths and is not claimed to be small.
+
+## 22. Amendment A2: candidate-to-executable provenance (2026-11-15)
+
+This strengthens candidate binding after qualification data existed. Earlier
+receipts remain historical records, but their one-time binary snapshots do not
+satisfy this amendment and are not a current candidate-bound qualification. A
+new PASS requires a complete R15 run under these controls; no prior result is
+relabelled. The workloads, metrics, G1–G16 thresholds and interleaving are
+unchanged.
+
+**Why.** The former runner hashed pre-existing ignored files under `build/`
+once, then resolved those mutable pathnames for every trial and reduction. It
+did not establish which candidate sources produced them or check the files and
+tree after use. A stale artifact, concurrent writer or self-replacement could
+therefore make a receipt attribute measurements to bytes not built from its
+named clean commit.
+
+**Required build boundary.** `tools/r15_qualify.sh` reads the omega candidate
+and dependency locks from Git objects with replace refs and grafts disabled,
+re-hashes and checks their object closures, and creates fresh archives of the
+candidate, the pinned physics commit and the pinned aienos capability source.
+It extracts omega and physics into a private directory, rebuilds
+`r15-perf-<mode>` there with repository flags and the pinned aienos source, and
+does not consume a pre-existing `build/` artifact. Compiler-affecting
+environment overrides are removed. The archive, toolchain, command, log and
+resulting binary digests are recorded in `build-provenance.json`.
+
+**Required execution boundary.** The two benchmark binaries and reducer are
+copied into the new run directory, made read-only, and executed only there.
+The runner compares each executable with its build digest immediately before
+and after every use and aborts on a mismatch. After reduction it checks all
+three again, records final HEAD and tracked-tree state, and seals those files
+and records in `PROVENANCE_SHA256SUMS`.
+
+**Receipt rule.** `candidate_bound` is true only when the initial candidate is
+clean and matches the requested commit, both checksum manifests verify, the
+build/final schemas and source-to-binary hashes agree, dependency commits equal
+the candidate locks, final HEAD is unchanged, the final tracked tree is clean,
+and every executable retained its staged digest. Missing provenance is a FAIL,
+not an inference from the old initial snapshot.
diff --git a/tests/r15_receipt_test.sh b/tests/r15_receipt_test.sh
index bb0fa15f9 ..8062fec22 100755
--- a/tests/r15_receipt_test.sh
+++ b/tests/r15_receipt_test.sh
@@ -18,7 +18,8 @@
# the recorded attempt-1 raw data (evidence/R15/raw/20260929T020536Z-...) into
# build/, then checks: every §12/§13 required field is present, outcome is
# FAIL (G10 failed, aienos_commit blank, no correctness reruns), the failed
-# gate is listed under regressions, and the file is named by its own SHA-256.
+# gate is listed under regressions, historical runs without build provenance
+# are not candidate-bound, and the file is named by its own SHA-256.
set -u
HERE=$(cd "$(dirname "$0")/.." && pwd)
RAW=$HERE/evidence/R15/raw/20260929T020536Z-ad8e1f2ea4e4 -silicon
@@ -35,6 +36,7 @@ check "named by its own SHA-256" '[ "$(basename "$R" .json)" = "$(sha256sum "$R"
for k in schema run_id outcome outcome_reasons candidate_commit run_commit candidate_bound \
tree_dirty silicon_observed aienos_commit physics_commit benchmark_binaries_sha256 \
+ provenance_digest_sha256 provenance_files_verified build_provenance final_state \
raw_digest_sha256 reducer_source_sha256 legacy_status seq_selector_symbol nodigest_macro \
gates correctness_reruns regressions limits not_claimed hardware_identity summary \
hostname machine_id_sha256 kernel midr governor_freq mem_kb gpu secure_boot lockdown \
@@ -50,7 +52,7 @@ check "reason names G10" 'grep -q "gate G10 FAIL" "$R"'
check "reason names blank aienos_commit" 'grep -q "aienos_commit not recorded" "$R"'
check "reason names missing reruns" 'grep -q "correctness reruns (§14) not recorded" "$R"'
check "G10 listed under regressions" 'grep -o "\"regressions\": \[.*\"id\":\"G10\"" "$R" >/dev/null'
-check "run commit ad8e1f2 , candidate-bound" 'grep -q "\"run_commit\": \"ad8e1f2ea4e4906ed810c6bd696cc905b801d69a \"" "$R" && grep -q "\"candidate_bound\": true" "$R"'
+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"'
check "raw digest matches reducer" 'grep -q "\"raw_digest_matches_reducer\": true" "$R" && grep -q "\"raw_files_verified\": true" "$R"'
check "16 gates present" 'grep -q "\"gates_present\": 16" "$R"'
if command -v jq >/dev/null; then
@@ -64,6 +66,29 @@ fi
SYN=$OUT/syn; mkdir -p "$SYN"; cp "$RAW"/* "$SYN"/
sed -i 's/"outcome":"FAIL"/"outcome":"PASS"/; s/"all_gates_pass":false/"all_gates_pass":true/' "$SYN/summary.json"
sed -i 's/"aienos_commit":""/"aienos_commit":"c8ab65e3ba2fddbe99245f747fdfdb99f6042fd3 "/' "$SYN/machine.json"
+mkdir "$SYN/bin"
+printf 'synthetic trial executable\n' > "$SYN/bin/rx_r15_perf_silicon"
+printf 'synthetic nodigest executable\n' > "$SYN/bin/rx_r15_perf_silicon_nodigest"
+printf 'synthetic reducer executable\n' > "$SYN/bin/r15_reduce"
+chmod 0555 "$SYN/bin/"*
+TRIAL_SHA=$(sha256sum "$SYN/bin/rx_r15_perf_silicon" | cut -d' ' -f1)
+ND_SHA=$(sha256sum "$SYN/bin/rx_r15_perf_silicon_nodigest" | cut -d' ' -f1)
+RED_SHA=$(sha256sum "$SYN/bin/r15_reduce" | cut -d' ' -f1)
+BINARIES="{\"trial\":\"$TRIAL_SHA\",\"nodigest\":\"$ND_SHA\",\"reducer\":\"$RED_SHA\"}"
+sed -i "s/\"binaries\":{[^}]*}/\"binaries\":$BINARIES/" "$SYN/machine.json"
+printf 'synthetic isolated build log\n' > "$SYN/build.log"
+BUILD_LOG_SHA=$(sha256sum "$SYN/build.log" | cut -d' ' -f1)
+PHYSICS=$(grep -o '"physics_commit":"[^"]*"' "$SYN/machine.json" | sed 's/.*:"//; s/"$//')
+H1=$(printf '%064x' 1); H2=$(printf '%064x' 2); H3=$(printf '%064x' 3)
+H4=$(printf '%064x' 4); H5=$(printf '%064x' 5)
+cat > "$SYN/build-provenance.json" <<EOF
+{"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}
+EOF
+cat > "$SYN/final-state.json" <<EOF
+{"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}
+EOF
+(cd "$SYN" && sha256sum build.log build-provenance.json final-state.json \
+ bin/rx_r15_perf_silicon bin/rx_r15_perf_silicon_nodigest bin/r15_reduce > PROVENANCE_SHA256SUMS)
# machine.json is covered by SHA256SUMS, and the reducer's raw digest covers
# SHA256SUMS: re-seal both so only the judged inputs differ.
sed -i "s/^[0-9a-f]* machine.json\$/$(sha256sum "$SYN/machine.json" | cut -d' ' -f1) machine.json/" "$SYN/SHA256SUMS"
@@ -75,11 +100,18 @@ sed -i 's/,$/}/' "$OUT/reruns.json"
"$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a >/dev/null 2>&1
check "all gates PASS but no reruns -> still FAIL" '[ $? = 1 ]'
P=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns.json")
-check "all gates PASS + reruns PASS -> PASS" '[ $? = 0 ] && grep -q "\"outcome\": \"PASS\"" "$P"'
+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"'
"$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-out" 0000000000000000000000000000000000000000 "$OUT/reruns.json" >/dev/null
check "wrong candidate -> FAIL" '[ $? = 1 ]'
check "nodigest flag checked from raw" 'grep -q "\"checked_from_raw\": true, \"nodigest_processes_digest_off\": 12, \"production_processes_digest_on\": 46" "$R"'
+# Replacing a sealed executable after the run invalidates provenance and can
+# never retain candidate_bound, even though machine.json still has the initial digest.
+MUT=$OUT/replaced-bin; mkdir -p "$MUT"; cp -a "$SYN"/. "$MUT"/
+chmod u+w "$MUT/bin/rx_r15_perf_silicon"; printf 'replacement\n' > "$MUT/bin/rx_r15_perf_silicon"
+M=$($HERE/tools/r15_receipt.sh "$MUT" "$OUT/replaced-out" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns.json")
+check "replaced executable -> FAIL, not candidate-bound" '[ $? = 1 ] && grep -q "build provenance files do not verify" "$M" && grep -q "\"candidate_bound\": false" "$M"'
+
# human-written notes: a regression and a limit are copied into the receipt
printf '# test notes\nregression\tL1-A p50 ns\t7376\t4688\ttest justification\nlimit\ttest limit text\n' > "$OUT/notes.tsv"
N=$("$HERE/tools/r15_receipt.sh" "$SYN" "$OUT/syn-notes" ad8e1f2ea4e4906ed810c6bd696cc905b801d69a "$OUT/reruns.json" "$OUT/notes.tsv")
@@ -88,7 +120,7 @@ check "notes: regression listed" 'grep -q "\"metric\":\"L1-A p50 ns\",\"resident
check "notes: limit listed" 'grep -q "\"limits\": \[\"test limit text\"\]" "$N"'
# a NODIGEST process that kept digests on must fail the receipt (re-sealed)
-ND=$OUT/nd; mkdir -p "$ND"; cp "$SYN"/* "$ND"/
+ND=$OUT/nd; mkdir -p "$ND"; cp -a "$SYN"/. "$ND"/
f=$(ls "$ND"/trial-RES1ND-*.jsonl | head -1); sed -i 's/"causal_digest":0/"causal_digest":1/' "$f"
sed -i "s/^[0-9a-f]* $(basename "$f")\$/$(sha256sum "$f" | cut -d' ' -f1) $(basename "$f")/" "$ND/SHA256SUMS"
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"
diff --git a/tools/r15_qualify.sh b/tools/r15_qualify.sh
index 1b0970609 ..b671aa0de 100755
--- a/tools/r15_qualify.sh
+++ b/tools/r15_qualify.sh
@@ -18,13 +18,15 @@
# §9, §10, §12, §13, §16 C1 item 7).
#
# tools/r15_qualify.sh [--detach] <host|silicon> [rounds=12] [l1_runs=5] [l2_runs=5]
-# (env: AIENOS_R7_DIR, PHYSICS_DIR for the recorded commits; R15_OUT_BASE to
-# write a dry run outside evidence/)
+# (env: AIENOS_LOCK_REPO or AIENOS_R7_DIR, PHYSICS_DIR repositories holding
+# the pinned commits; CC; R15_OUT_BASE to write a dry run outside evidence/)
#
# Runs, in order: W-EPISODE trials (rounds x RES-4/RES-1/SEQ/RES-1-NODIGEST,
# balanced Latin square), Level 1 (A,C,D,E,G,W0,W1 for RES-1 and SEQ
# interleaved, B for RES-1), Level 2 (RES-1/SEQ interleaved). Every process
# writes its own raw file; a failed process is recorded and NEVER rerun (§10).
+# The benchmark and reducer are rebuilt from verified Git archives in a private
+# directory. Only digest-bound copies under the run directory are executed.
# Then SHA256SUMS and the reducer. Output: evidence/R15/raw/<run-id>/.
#
# --detach re-launches this script in its own session (setsid nohup), so an
@@ -35,6 +37,7 @@
# the run, restored to 4 on every exit path, and the run fails if it does not
# read back 4. No systemd.
set -u
+set -o pipefail
if [ "${1:-}" = "--detach" ]; then
shift
@@ -52,24 +55,171 @@ case "$MODE" in host|silicon) ;; *) echo "mode must be host or silicon" >&2; exi
HERE=$(cd "$(dirname "$0")/.." && pwd)
cd "$HERE" || exit 1
-COMMIT=$(git rev-parse HEAD)
-DIRTY=$([ -z "$(git status --porcelain --untracked-files=no)" ] && echo false || echo true)
+export GIT_NO_REPLACE_OBJECTS=1 GIT_GRAFT_FILE=/nonexistent/r15-qualify-grafts
+COMMIT=$(git rev-parse HEAD) || { echo "r15_qualify: cannot read candidate HEAD" >&2; exit 2; }
+INITIAL_STATUS=$(git status --porcelain --untracked-files=no) || { echo "r15_qualify: cannot read initial tree state" >&2; exit 2; }
+DIRTY=$([ -z "$INITIAL_STATUS" ] && echo false || echo true)
RUN_ID=$(date -u +%Y%m%dT%H%M%SZ)-${COMMIT:0:12}-$MODE
-OUT=${R15_OUT_BASE:-$HERE/evidence/R15/raw}/$RUN_ID
-mkdir -p "$OUT" || exit 1
+OUT_BASE=${R15_OUT_BASE:-$HERE/evidence/R15/raw}
+mkdir -p "$OUT_BASE" || exit 1
+OUT=$OUT_BASE/$RUN_ID
+mkdir -m 0755 "$OUT" || { echo "r15_qualify: run directory already exists or cannot be created: $OUT" >&2; exit 1; }
LOG=$OUT/progress.log
say() { echo "$(date '+%H:%M:%S') $*" >> "$LOG"; }
+jstr() { printf '"%s"' "$(printf '%s' "$1" | tr -d '"\\' | tr '\n' ' ')"; }
+sha_file() { sha256sum "$1" | cut -d' ' -f1; }
+full_commit() { [[ "$1" =~ ^[0-9a-f]{40}$ ]]; }
+plain_path() { [[ "$1" =~ ^[A-Za-z0-9/._+-]+$ ]]; }
+
+BUILD_LOG=$OUT/build.log
+: > "$BUILD_LOG"
+prepare_fail() {
+ say "PREPARATION FAILED: $*"
+ echo "r15_qualify: $*" >&2
+ exit 2
+}
+verify_commit() { # <repository> <commit> <label>
+ local repo=$1 commit=$2 label=$3 got tree
+ full_commit "$commit" || prepare_fail "$label commit is not one full lower-case SHA-1: $commit"
+ got=$(git -C "$repo" rev-parse --verify "$commit^{commit}" 2>/dev/null) || prepare_fail "$label commit $commit is unavailable in $repo"
+ [ "$got" = "$commit" ] || prepare_fail "$label resolved to $got, not $commit"
+ got=$(git -C "$repo" cat-file commit "$commit" 2>/dev/null | git hash-object -t commit --stdin 2>/dev/null) || prepare_fail "cannot re-hash $label commit $commit"
+ [ "$got" = "$commit" ] || prepare_fail "$label commit object does not hash to $commit"
+ tree=$(git -C "$repo" rev-parse --verify "$commit^{tree}" 2>/dev/null) || prepare_fail "cannot read $label tree"
+ got=$(git -C "$repo" cat-file tree "$tree" 2>/dev/null | git hash-object -t tree --stdin 2>/dev/null) || prepare_fail "cannot re-hash $label tree $tree"
+ [ "$got" = "$tree" ] || prepare_fail "$label tree object does not hash to $tree"
+ git -C "$repo" fsck --strict --no-dangling "$commit" >> "$BUILD_LOG" 2>&1 || prepare_fail "$label object closure fails git fsck"
+}
-B=$HERE/build/rx_r15_perf_$MODE
-BND=$HERE/build/rx_r15_perf_${MODE}_nodigest
-RED=$HERE/build/r15_reduce
-for f in "$B" "$BND" "$RED"; do
- [ -x "$f" ] || { say "missing $f: build it first (make r15-perf-$MODE)"; exit 2; }
+TMP_BASE=${TMPDIR:-/tmp}
+plain_path "$TMP_BASE" || prepare_fail "TMPDIR contains characters outside [A-Za-z0-9/._+-]: $TMP_BASE"
+case "$TMP_BASE" in /*) ;; *) prepare_fail "TMPDIR must be absolute: $TMP_BASE";; esac
+[ "$TMP_BASE" != / ] || prepare_fail "TMPDIR may not be the filesystem root"
+BUILD_WORK=$(mktemp -d "$TMP_BASE/omega-r15-build.XXXXXX") || prepare_fail "cannot create private build directory"
+cleanup_build() {
+ case "$BUILD_WORK" in
+ "$TMP_BASE"/omega-r15-build.*)
+ chmod -R u+w "$BUILD_WORK" 2>/dev/null
+ rm -rf -- "$BUILD_WORK"
+ ;;
+ *) echo "r15_qualify: refusing to remove unexpected build path $BUILD_WORK" >&2 ;;
+ esac
+}
+RESTORE_NEEDED=false
+on_exit() {
+ [ "$RESTORE_NEEDED" != true ] || restore
+ cleanup_build
+}
+trap on_exit EXIT
+trap 'say "stopped by a signal"; exit 130' INT TERM HUP
+
+PHYSICS_LOCK=$(git show "$COMMIT:physics.lock" 2>/dev/null | tr -d '[:space:]')
+AIENOS_LOCK=$(git show "$COMMIT:aienos.lock" 2>/dev/null | tr -d '[:space:]')
+PHYSICS_INPUT=${PHYSICS_DIR:-$HERE/../physics}
+PHYSICS_REPO=$(git -C "$PHYSICS_INPUT" rev-parse --show-toplevel 2>/dev/null) || prepare_fail "PHYSICS_DIR must name a Git repository holding $PHYSICS_LOCK"
+if [ -n "${AIENOS_LOCK_REPO:-}" ]; then
+ AIENOS_INPUT=$AIENOS_LOCK_REPO
+elif [ -n "${AIENOS_R7_DIR:-}" ]; then
+ AIENOS_INPUT=$AIENOS_R7_DIR
+else
+ AIENOS_INPUT=$HERE/../aienos-argus-cap
+fi
+AIENOS_REPO=$(git -C "$AIENOS_INPUT" rev-parse --show-toplevel 2>/dev/null) || prepare_fail "AIENOS source must name a Git repository holding $AIENOS_LOCK"
+for path in "$HERE" "$PHYSICS_REPO" "$AIENOS_REPO" "$BUILD_WORK"; do
+ plain_path "$path" || prepare_fail "build path contains characters outside [A-Za-z0-9/._+-]: $path"
done
+verify_commit "$HERE" "$COMMIT" omega
+verify_commit "$PHYSICS_REPO" "$PHYSICS_LOCK" physics
+verify_commit "$AIENOS_REPO" "$AIENOS_LOCK" aienos
+
+CANDIDATE_TAR=$BUILD_WORK/omega.tar
+PHYSICS_TAR=$BUILD_WORK/physics.tar
+AIENOS_TAR=$BUILD_WORK/aienos-capability.tar
+git -C "$HERE" archive --format=tar "$COMMIT" > "$CANDIDATE_TAR" || prepare_fail "cannot archive omega candidate $COMMIT"
+git -C "$PHYSICS_REPO" archive --format=tar "$PHYSICS_LOCK" > "$PHYSICS_TAR" || prepare_fail "cannot archive physics commit $PHYSICS_LOCK"
+git -C "$AIENOS_REPO" archive --format=tar "$AIENOS_LOCK" native/capability > "$AIENOS_TAR" || prepare_fail "cannot archive aienos capability source at $AIENOS_LOCK"
+CANDIDATE_ARCHIVE_SHA=$(sha_file "$CANDIDATE_TAR") || prepare_fail "cannot hash omega candidate archive"
+PHYSICS_ARCHIVE_SHA=$(sha_file "$PHYSICS_TAR") || prepare_fail "cannot hash physics archive"
+AIENOS_ARCHIVE_SHA=$(sha_file "$AIENOS_TAR") || prepare_fail "cannot hash aienos archive"
+
+CANDIDATE_SRC=$BUILD_WORK/omega
+PHYSICS_SRC=$BUILD_WORK/physics
+BUILD_OUT=$BUILD_WORK/out
+mkdir "$CANDIDATE_SRC" "$PHYSICS_SRC" "$BUILD_OUT" || prepare_fail "cannot create isolated source/build directories"
+tar -xf "$CANDIDATE_TAR" -C "$CANDIDATE_SRC" || prepare_fail "cannot extract omega candidate archive"
+tar -xf "$PHYSICS_TAR" -C "$PHYSICS_SRC" || prepare_fail "cannot extract physics archive"
+
+CC_NAME=${CC:-gcc}
+case "$CC_NAME" in ''|*[!A-Za-z0-9_./+-]*) prepare_fail "CC must be one plain executable name or path";; esac
+CC_PATH=$(command -v -- "$CC_NAME" 2>/dev/null) || prepare_fail "compiler $CC_NAME is unavailable"
+CC_PATH=$(readlink -f "$CC_PATH") || prepare_fail "cannot resolve compiler $CC_NAME"
+MAKE_PATH=$(command -v -- make 2>/dev/null) || prepare_fail "make is unavailable"
+MAKE_PATH=$(readlink -f "$MAKE_PATH") || prepare_fail "cannot resolve make"
+plain_path "$CC_PATH" || prepare_fail "compiler path contains characters outside [A-Za-z0-9/._+-]: $CC_PATH"
+plain_path "$MAKE_PATH" || prepare_fail "make path contains characters outside [A-Za-z0-9/._+-]: $MAKE_PATH"
+CC_SHA=$(sha_file "$CC_PATH") || prepare_fail "cannot hash compiler $CC_PATH"
+MAKE_SHA=$(sha_file "$MAKE_PATH") || prepare_fail "cannot hash make $MAKE_PATH"
+CC_VERSION_ALL=$("$CC_PATH" --version 2>/dev/null) || prepare_fail "cannot read compiler version"
+CC_VERSION=${CC_VERSION_ALL%%$'\n'*}
+MAKE_VERSION_ALL=$("$MAKE_PATH" --version 2>/dev/null) || prepare_fail "cannot read make version"
+MAKE_VERSION=${MAKE_VERSION_ALL%%$'\n'*}
+BUILD_COMMAND="env -u build overrides make -C <omega-archive> OUT_DIR=<private> PHYSICS_DIR=<physics-archive> PHYSICS_LOCK_CHECK=0 AIENOS_LOCK_REPO=<verified-repository> CC=$CC_PATH r15-perf-$MODE"
+printf 'candidate=%s archive_sha256=%s\nphysics=%s archive_sha256=%s\naienos=%s capability_archive_sha256=%s\ncommand=%s\n' \
+ "$COMMIT" "$CANDIDATE_ARCHIVE_SHA" "$PHYSICS_LOCK" "$PHYSICS_ARCHIVE_SHA" \
+ "$AIENOS_LOCK" "$AIENOS_ARCHIVE_SHA" "$BUILD_COMMAND" >> "$BUILD_LOG"
+if ! env -u MAKEFLAGS -u MFLAGS -u MAKELEVEL -u CC -u CFLAGS -u CPPFLAGS -u LDFLAGS \
+ -u CPATH -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH -u LIBRARY_PATH \
+ -u GCC_EXEC_PREFIX -u COMPILER_PATH -u LD_PRELOAD \
+ GIT_NO_REPLACE_OBJECTS=1 GIT_GRAFT_FILE=/nonexistent/r15-qualify-grafts \
+ "CC=$CC_PATH" \
+ "$MAKE_PATH" -C "$CANDIDATE_SRC" "OUT_DIR=$BUILD_OUT" "PHYSICS_DIR=$PHYSICS_SRC" \
+ PHYSICS_LOCK_CHECK=0 "AIENOS_LOCK_REPO=$AIENOS_REPO" "r15-perf-$MODE" \
+ >> "$BUILD_LOG" 2>&1; then
+ prepare_fail "isolated make r15-perf-$MODE failed (see build.log)"
+fi
+[ "$(sha_file "$CC_PATH")" = "$CC_SHA" ] || prepare_fail "compiler changed during the isolated build"
+[ "$(sha_file "$MAKE_PATH")" = "$MAKE_SHA" ] || prepare_fail "make changed during the isolated build"
+
+BUILT_B=$BUILD_OUT/rx_r15_perf_$MODE
+BUILT_BND=$BUILD_OUT/rx_r15_perf_${MODE}_nodigest
+BUILT_RED=$BUILD_OUT/r15_reduce
+for f in "$BUILT_B" "$BUILT_BND" "$BUILT_RED"; do
+ [ -x "$f" ] || prepare_fail "isolated build did not produce executable $f"
+done
+BIN_DIR=$OUT/bin
+mkdir "$BIN_DIR" || prepare_fail "cannot create sealed binary directory"
+B=$BIN_DIR/rx_r15_perf_$MODE
+BND=$BIN_DIR/rx_r15_perf_${MODE}_nodigest
+RED=$BIN_DIR/r15_reduce
+cp -- "$BUILT_B" "$B" || prepare_fail "cannot stage trial binary"
+cp -- "$BUILT_BND" "$BND" || prepare_fail "cannot stage nodigest binary"
+cp -- "$BUILT_RED" "$RED" || prepare_fail "cannot stage reducer"
+chmod 0555 "$B" "$BND" "$RED" "$BIN_DIR" || prepare_fail "cannot make staged artifacts read-only"
+TRIAL_SHA=$(sha_file "$B") || prepare_fail "cannot hash staged trial binary"
+NODIGEST_SHA=$(sha_file "$BND") || prepare_fail "cannot hash staged nodigest binary"
+REDUCER_SHA=$(sha_file "$RED") || prepare_fail "cannot hash staged reducer"
+[ "$TRIAL_SHA" = "$(sha_file "$BUILT_B")" ] || prepare_fail "staged trial binary differs from isolated build output"
+[ "$NODIGEST_SHA" = "$(sha_file "$BUILT_BND")" ] || prepare_fail "staged nodigest binary differs from isolated build output"
+[ "$REDUCER_SHA" = "$(sha_file "$BUILT_RED")" ] || prepare_fail "staged reducer differs from isolated build output"
+BUILD_LOG_SHA=$(sha_file "$BUILD_LOG") || prepare_fail "cannot hash build log"
+{
+ printf '{"schema":"AIEN_RX_R15_BUILD_PROVENANCE_V1","candidate_commit":%s,' "$(jstr "$COMMIT")"
+ printf '"candidate_archive_sha256":%s,"physics_commit":%s,"physics_archive_sha256":%s,' \
+ "$(jstr "$CANDIDATE_ARCHIVE_SHA")" "$(jstr "$PHYSICS_LOCK")" "$(jstr "$PHYSICS_ARCHIVE_SHA")"
+ printf '"aienos_commit":%s,"aienos_archive_sha256":%s,"build_command":%s,' \
+ "$(jstr "$AIENOS_LOCK")" "$(jstr "$AIENOS_ARCHIVE_SHA")" "$(jstr "$BUILD_COMMAND")"
+ printf '"compiler_path":%s,"compiler_sha256":%s,"compiler_version":%s,' \
+ "$(jstr "$CC_PATH")" "$(jstr "$CC_SHA")" "$(jstr "$CC_VERSION")"
+ printf '"make_path":%s,"make_sha256":%s,"make_version":%s,"build_log_sha256":%s,' \
+ "$(jstr "$MAKE_PATH")" "$(jstr "$MAKE_SHA")" "$(jstr "$MAKE_VERSION")" "$(jstr "$BUILD_LOG_SHA")"
+ printf '"binaries":{"trial":%s,"nodigest":%s,"reducer":%s}}\n' \
+ "$(jstr "$TRIAL_SHA")" "$(jstr "$NODIGEST_SHA")" "$(jstr "$REDUCER_SHA")"
+} > "$OUT/build-provenance.json"
+
# ---- kernel.perf_event_paranoid 4 -> 1 -> 4 (C1 item 7) ---------------------
PARANOID_BEFORE=$(cat /proc/sys/kernel/perf_event_paranoid)
-STATE=$HERE/tools/r15_machine_state.sh
+STATE=$CANDIDATE_SRC/tools/r15_machine_state.sh
restore() {
"$STATE" stop "$OUT" 2>/dev/null
sudo -n sysctl -q kernel.perf_event_paranoid=4 >/dev/null 2>&1
@@ -77,13 +227,11 @@ restore() {
echo "$PARANOID_RESTORED" > "$OUT/paranoid-restored.txt"
if [ "$PARANOID_RESTORED" != 4 ]; then say "WARNING: perf_event_paranoid did not return to 4 (reads $PARANOID_RESTORED)"; fi
}
-trap restore EXIT
-trap 'say "stopped by a signal"; exit 130' INT TERM HUP
+RESTORE_NEEDED=true
sudo -n sysctl -q kernel.perf_event_paranoid=1 >/dev/null 2>&1
PARANOID_DURING=$(cat /proc/sys/kernel/perf_event_paranoid)
# ---- machine.json (§13) ------------------------------------------------------
-jstr() { printf '"%s"' "$(printf '%s' "$1" | tr -d '"\\' | tr '\n' ' ')"; }
midrs=$(for c in /sys/devices/system/cpu/cpu[0-9]*; do
printf '%s:%s ' "${c##*cpu}" "$(cat "$c/regs/identification/midr_el1" 2>/dev/null)"; done)
govs=$(for c in /sys/devices/system/cpu/cpu[0-9]*; do
@@ -93,8 +241,8 @@ temps=$(cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null | tr '\n' ' ')
spbm_ver=$(cat /sys/module/aien_spbm_readonly/srcversion 2>/dev/null)
top=$(ps -eo pcpu,comm --sort=-pcpu | sed -n 2,11p | awk '{printf "%s:%s ", $2, $1}')
servers=$(ps -eo comm,args | grep -i -E 'astrosage|lm-studio|lmstudio|llama|vllm|ollama' | grep -v grep | awk '{print $1}' | sort -u | tr '\n' ' ')
-aienos=$(git -C "${AIENOS_R7_DIR:-../aienos-capability-c}" rev-parse HEAD 2>/dev/null)
-physics=$(git -C "${PHYSICS_DIR:-../physics}" rev-parse HEAD 2>/dev/null)
+aienos=$AIENOS_LOCK
+physics=$PHYSICS_LOCK
{
printf '{"run_id":%s,"mode":%s,"candidate_commit":%s,"tree_dirty":%s,' \
"$(jstr "$RUN_ID")" "$(jstr "$MODE")" "$(jstr "$COMMIT")" "$DIRTY"
@@ -112,12 +260,11 @@ physics=$(git -C "${PHYSICS_DIR:-../physics}" rev-parse HEAD 2>/dev/null)
"$(jstr "$temps")" "$(jstr "$spbm_ver")" "$(jstr "$(cat /proc/loadavg)")" "$(jstr "$top")" "$(jstr "$servers")"
printf '"aienos_commit":%s,"physics_commit":%s,"compiler":%s,' \
"$(jstr "$aienos")" "$(jstr "$physics")" \
- "$(jstr "$(gcc --version | head -1)")"
+ "$(jstr "$CC_VERSION")"
printf '"binaries":{"trial":%s,"nodigest":%s,"reducer":%s},' \
- "$(jstr "$(sha256sum "$B" | cut -d' ' -f1)")" "$(jstr "$(sha256sum "$BND" | cut -d' ' -f1)")" \
- "$(jstr "$(sha256sum "$RED" | cut -d' ' -f1)")"
+ "$(jstr "$TRIAL_SHA")" "$(jstr "$NODIGEST_SHA")" "$(jstr "$REDUCER_SHA")"
printf '"reducer_source_sha256":%s,"rounds":%s,"l1_runs":%s,"l2_runs":%s}\n' \
- "$(jstr "$(sha256sum tools/r15_reduce.c | cut -d' ' -f1)")" "$ROUNDS" "$L1RUNS" "$L2RUNS"
+ "$(jstr "$(sha_file "$CANDIDATE_SRC/tools/r15_reduce.c")")" "$ROUNDS" "$L1RUNS" "$L2RUNS"
} > "$OUT/machine.json"
ps -eo pid,pcpu,rss,comm --sort=-pcpu > "$OUT/processes-before.txt"
[ "$PARANOID_DURING" = 1 ] || say "WARNING: could not set perf_event_paranoid to 1 (reads $PARANOID_DURING); memory-traffic counters will be missing"
@@ -161,13 +308,37 @@ fi
say "R15 $MODE run $RUN_ID started: $ROUNDS rounds, $L1RUNS Level-1 runs, $L2RUNS Level-2 runs"
FAILED=0
+integrity_fail() { # <file> <expected> <phase>
+ local file=$1 expected=$2 phase=$3 actual
+ actual=$(sha_file "$file" 2>/dev/null)
+ say "EXECUTABLE INTEGRITY FAILURE: $(basename "$file") $phase expected $expected got ${actual:-unreadable}"
+ printf 'executable=%s\nphase=%s\nexpected_sha256=%s\nactual_sha256=%s\n' \
+ "$(basename "$file")" "$phase" "$expected" "${actual:-unreadable}" > "$OUT/executable-integrity-failure.txt"
+ exit 5
+}
+guard_binary() { # <file> <expected> <phase>
+ local actual
+ actual=$(sha_file "$1" 2>/dev/null) || integrity_fail "$1" "$2" "$3"
+ [ "$actual" = "$2" ] || integrity_fail "$1" "$2" "$3"
+}
+expected_binary() {
+ case "$1" in
+ "$B") printf '%s\n' "$TRIAL_SHA" ;;
+ "$BND") printf '%s\n' "$NODIGEST_SHA" ;;
+ "$RED") printf '%s\n' "$REDUCER_SHA" ;;
+ *) integrity_fail "$1" unknown "unregistered executable" ;;
+ esac
+}
one() { # <label> <file> <binary> <args...>
local label=$1 file=$2 bin=$3
shift 3
- local t0=$SECONDS
+ local t0=$SECONDS expected
+ expected=$(expected_binary "$bin")
+ guard_binary "$bin" "$expected" "before $file"
"$STATE" mark "$OUT" "begin $file"
"$bin" "$@" "$OUT/$file" >> "$OUT/stderr.log" 2>&1
local rc=$?
+ guard_binary "$bin" "$expected" "after $file"
"$STATE" mark "$OUT" "end $file exit $rc"
echo "$file exit $rc seconds $((SECONDS - t0))" >> "$OUT/runs.txt"
if [ $rc -ne 0 ]; then FAILED=$((FAILED + 1)); say "$label FAILED (exit $rc); recorded, not rerun"; else say "$label ok ($((SECONDS - t0)) s)"; fi
@@ -206,9 +377,36 @@ done
ps -eo pid,pcpu,rss,comm --sort=-pcpu > "$OUT/processes-after.txt"
restore
-trap - EXIT
+RESTORE_NEEDED=false
(cd "$OUT" && sha256sum ./*.jsonl machine.json machine-state.ndjson machine-perf.csv machine-state-marks.txt $([ -f preflight.txt ] && echo preflight.txt) 2>/dev/null | sed 's| \./| |' > SHA256SUMS)
+guard_binary "$RED" "$REDUCER_SHA" "before reduction"
"$RED" "$OUT" "$OUT/summary.json" > "$OUT/reduce.log" 2>&1
+guard_binary "$RED" "$REDUCER_SHA" "after reduction"
+
+# The final binding is separate from the reducer's raw-input manifest: it is
+# written only after every executable use and then sealed with the binaries,
+# build log and build provenance in PROVENANCE_SHA256SUMS.
+guard_binary "$B" "$TRIAL_SHA" "at final seal"
+guard_binary "$BND" "$NODIGEST_SHA" "at final seal"
+guard_binary "$RED" "$REDUCER_SHA" "at final seal"
+FINAL_HEAD=$(git rev-parse HEAD 2>/dev/null) || FINAL_HEAD=unreadable
+if FINAL_STATUS=$(git status --porcelain --untracked-files=no 2>/dev/null); then
+ FINAL_DIRTY=$([ -n "$FINAL_STATUS" ] && echo true || echo false)
+else
+ FINAL_DIRTY=true
+fi
+HEAD_UNCHANGED=false; [ "$FINAL_HEAD" = "$COMMIT" ] && HEAD_UNCHANGED=true
+{
+ printf '{"schema":"AIEN_RX_R15_FINAL_STATE_V1","candidate_commit":%s,"final_head":%s,' \
+ "$(jstr "$COMMIT")" "$(jstr "$FINAL_HEAD")"
+ printf '"tracked_tree_dirty":%s,"head_unchanged":%s,"binaries_unchanged":true,' \
+ "$FINAL_DIRTY" "$HEAD_UNCHANGED"
+ printf '"binaries":{"trial":%s,"nodigest":%s,"reducer":%s}}\n' \
+ "$(jstr "$TRIAL_SHA")" "$(jstr "$NODIGEST_SHA")" "$(jstr "$REDUCER_SHA")"
+} > "$OUT/final-state.json"
+(cd "$OUT" && sha256sum build.log build-provenance.json final-state.json \
+ "bin/$(basename "$B")" "bin/$(basename "$BND")" "bin/$(basename "$RED")" > PROVENANCE_SHA256SUMS) \
+ || { say "failed to seal build provenance"; exit 5; }
say "finished: $FAILED process(es) failed; $(grep -c PASS "$OUT/reduce.log") of 16 gates pass (see summary.json)"
tail -1 "$OUT/reduce.log" >> "$LOG"
echo done > "$OUT/done"
diff --git a/tools/r15_receipt.sh b/tools/r15_receipt.sh
index 13b06dc08 ..8807d4f6e 100755
--- a/tools/r15_receipt.sh
+++ b/tools/r15_receipt.sh
@@ -25,6 +25,9 @@
# <raw-dir>/machine.json hardware identity and commits (§13), written by
# tools/r15_qualify.sh at run time
# <raw-dir>/SHA256SUMS the raw file digests
+# <raw-dir>/build-provenance.json, final-state.json and
+# PROVENANCE_SHA256SUMS bind the archived sources,
+# toolchain, sealed executables and final tree state
# candidate-commit the commit proposed for R15 (default: env
# OMEGA_CANDIDATE_COMMIT; empty = not candidate-bound)
# reruns.json the §14 correctness reruns (+ §16 item 9 SEQ parity)
@@ -45,12 +48,13 @@
# embedded byte for byte. The writer only decides the outcome:
# PASS only if every gate G1-G16 is PASS (all_gates_pass true), the raw
# directory verifies against SHA256SUMS and the reducer's raw digest, the
-# run is candidate-bound (run commit == candidate, clean tree), silicon was
-# observed, aienos and physics commits are recorded and equal the pins in
-# aienos.lock/physics.lock at the run commit, and every required correctness
-# rerun is PASS. Anything else is FAIL, with the reasons listed.
+# run is candidate-bound (run commit == candidate, clean initial/final tree,
+# archive-built binaries unchanged through execution), silicon was observed,
+# aienos and physics commits equal the pins at the run commit, and every
+# required correctness rerun is PASS. Anything else is FAIL, with reasons.
# Shell and coreutils only (sha256sum, grep, sed, git). No jq, no Python.
set -u
+export GIT_NO_REPLACE_OBJECTS=1 GIT_GRAFT_FILE=/nonexistent/r15-receipt-grafts
RAW=${1:?raw run directory}
OUTDIR=${2:?output directory}
@@ -67,6 +71,9 @@ if [ -s "$RAW/instrument-unavailable.txt" ]; then
fi
SUM=$RAW/summary.json
MACH=$RAW/machine.json
+PROV=$RAW/build-provenance.json
+FINAL=$RAW/final-state.json
+PROV_SUMS=$RAW/PROVENANCE_SHA256SUMS
for f in "$SUM" "$MACH" "$RAW/SHA256SUMS"; do
[ -s "$f" ] || { echo "r15_receipt: missing $f" >&2; exit 2; }
done
@@ -78,7 +85,12 @@ REQUIRED_RERUNS="R3 R7 R8 R9 R10 R11 R12_host R12_silicon R13_host R13_silicon R
mstr() { grep -o "\"$1\":\"[^\"]*\"" "$MACH" | head -1 | sed 's/^"[^"]*":"//; s/"$//'; }
mraw() { grep -o "\"$1\":[^,}]*" "$MACH" | head -1 | sed 's/^"[^"]*"://'; }
sraw() { grep -o "\"$1\":[^,}]*" "$SUM" | tail -1 | sed 's/^"[^"]*"://'; }
+fstr() { grep -o "\"$2\":\"[^\"]*\"" "$1" 2>/dev/null | head -1 | sed 's/^"[^"]*":"//; s/"$//'; }
+fraw() { grep -o "\"$2\":[^,}]*" "$1" 2>/dev/null | head -1 | sed 's/^"[^"]*"://'; }
+fobj() { grep -o "\"$2\":{[^}]*}" "$1" 2>/dev/null | head -1 | sed 's/^"[^"]*"://'; }
jstr() { printf '"%s"' "$(printf '%s' "$1" | tr -d '"\\' | tr '\n' ' ')"; }
+is_sha256() { [[ "$1" =~ ^[0-9a-f]{64}$ ]]; }
+is_commit() { [[ "$1" =~ ^[0-9a-f]{40}$ ]]; }
REASONS=()
fail() { REASONS+=("$1"); }
@@ -91,6 +103,28 @@ AIENOS=$(mstr aienos_commit)
PHYSICS=$(mstr physics_commit)
REDUCER_SRC=$(mstr reducer_source_sha256)
BINARIES=$(grep -o '"binaries":{[^}]*}' "$MACH" | sed 's/^"binaries"://')
+PROV_SCHEMA=$(fstr "$PROV" schema)
+PROV_COMMIT=$(fstr "$PROV" candidate_commit)
+PROV_CANDIDATE_ARCHIVE=$(fstr "$PROV" candidate_archive_sha256)
+PROV_PHYSICS=$(fstr "$PROV" physics_commit)
+PROV_PHYSICS_ARCHIVE=$(fstr "$PROV" physics_archive_sha256)
+PROV_AIENOS=$(fstr "$PROV" aienos_commit)
+PROV_AIENOS_ARCHIVE=$(fstr "$PROV" aienos_archive_sha256)
+PROV_BUILD_COMMAND=$(fstr "$PROV" build_command)
+PROV_COMPILER=$(fstr "$PROV" compiler_sha256)
+PROV_MAKE=$(fstr "$PROV" make_sha256)
+PROV_BUILD_LOG=$(fstr "$PROV" build_log_sha256)
+PROV_BINARIES=$(fobj "$PROV" binaries)
+PROV_TRIAL=$(fstr "$PROV" trial)
+PROV_NODIGEST=$(fstr "$PROV" nodigest)
+PROV_REDUCER=$(fstr "$PROV" reducer)
+FINAL_SCHEMA=$(fstr "$FINAL" schema)
+FINAL_COMMIT=$(fstr "$FINAL" candidate_commit)
+FINAL_HEAD=$(fstr "$FINAL" final_head)
+FINAL_DIRTY=$(fraw "$FINAL" tracked_tree_dirty)
+FINAL_HEAD_UNCHANGED=$(fraw "$FINAL" head_unchanged)
+FINAL_BINARIES_UNCHANGED=$(fraw "$FINAL" binaries_unchanged)
+FINAL_BINARIES=$(fobj "$FINAL" binaries)
SCHEMA_IN=$(grep -o '"schema":"[^"]*"' "$SUM" | head -1 | sed 's/.*:"//; s/"$//')
ALL_PASS=$(sraw all_gates_pass)
DIGEST_CLAIMED=$(grep -o '"raw_digest_sha256_of_SHA256SUMS":"[0-9a-f]*"' "$SUM" | sed 's/.*:"//; s/"$//')
@@ -99,6 +133,10 @@ GATES=$(grep -o '"gates":\[[^]]*\]' "$SUM" | sed 's/^"gates"://')
[ "$SCHEMA_IN" = AIEN_RX_R15_SUMMARY_V1 ] || fail "summary.json schema is '$SCHEMA_IN', not AIEN_RX_R15_SUMMARY_V1"
[ -n "$GATES" ] || fail "summary.json has no gate table"
+RUN_COMMIT_OK=true
+is_commit "$RUN_COMMIT" || { RUN_COMMIT_OK=false; fail "run commit is missing or malformed"; }
+MODE_OK=true
+case "$MODE" in host|silicon) ;; *) MODE_OK=false; fail "run mode '$MODE' is invalid";; esac
# ---- gates (§11): every one of G1-G16 present and PASS
NGATES=0
@@ -119,23 +157,102 @@ DIGEST_OK=false
if [ -n "$DIGEST_CLAIMED" ] && [ "$DIGEST_CLAIMED" = "$DIGEST_ACTUAL" ]; then DIGEST_OK=true
else fail "raw digest in summary.json ($DIGEST_CLAIMED) != SHA-256 of SHA256SUMS ($DIGEST_ACTUAL)"; fi
-# ---- candidate binding
-BOUND=false
-if [ -z "$CANDIDATE" ]; then fail "no candidate commit given"
-elif [ "$CANDIDATE" != "$RUN_COMMIT" ]; then fail "run commit $RUN_COMMIT is not the candidate $CANDIDATE"
-elif [ "$TREE_DIRTY" != false ]; then fail "run tree was dirty"
-else BOUND=true; fi
+# ---- build and execution provenance
+PROV_FILES_OK=false
+PROV_DIGEST=""
+if [ ! -s "$PROV_SUMS" ]; then
+ fail "PROVENANCE_SHA256SUMS missing"
+elif [ "$MODE_OK" != true ]; then
+ fail "cannot validate executable provenance for invalid run mode"
+elif ! awk -v b1="bin/rx_r15_perf_$MODE" -v b2="bin/rx_r15_perf_${MODE}_nodigest" '
+ NF != 2 { bad = 1; next }
+ $2 != "build.log" && $2 != "build-provenance.json" && $2 != "final-state.json" &&
+ $2 != b1 && $2 != b2 && $2 != "bin/r15_reduce" { bad = 1 }
+ { if (++seen[$2] != 1) bad = 1 }
+ END { if (NR != 6 || bad) exit 1 }
+ ' "$PROV_SUMS"; then
+ fail "PROVENANCE_SHA256SUMS has an unexpected, duplicate or malformed path"
+elif ! (cd "$RAW" && sha256sum --quiet -c PROVENANCE_SHA256SUMS >/dev/null 2>&1); then
+ fail "build provenance files do not verify against PROVENANCE_SHA256SUMS"
+else
+ MANIFEST_COMPLETE=true
+ for rel in build.log build-provenance.json final-state.json \
+ "bin/rx_r15_perf_$MODE" "bin/rx_r15_perf_${MODE}_nodigest" bin/r15_reduce; do
+ awk -v want="$rel" 'NF == 2 && $2 == want { found = 1 } END { exit !found }' "$PROV_SUMS" \
+ || { MANIFEST_COMPLETE=false; fail "$rel missing from PROVENANCE_SHA256SUMS"; }
+ done
+ if [ "$MANIFEST_COMPLETE" = true ]; then PROV_FILES_OK=true; fi
+ PROV_DIGEST=$(sha256sum "$PROV_SUMS" | cut -d' ' -f1)
+fi
+
+PROVENANCE_OK=true
+[ "$PROV_SCHEMA" = AIEN_RX_R15_BUILD_PROVENANCE_V1 ] || { PROVENANCE_OK=false; fail "build provenance schema is '$PROV_SCHEMA'"; }
+[ "$PROV_COMMIT" = "$RUN_COMMIT" ] || { PROVENANCE_OK=false; fail "build provenance commit $PROV_COMMIT != run commit $RUN_COMMIT"; }
+[ "$PROV_PHYSICS" = "$PHYSICS" ] || { PROVENANCE_OK=false; fail "build provenance physics commit $PROV_PHYSICS != recorded $PHYSICS"; }
+[ "$PROV_AIENOS" = "$AIENOS" ] || { PROVENANCE_OK=false; fail "build provenance aienos commit $PROV_AIENOS != recorded $AIENOS"; }
+[ "$PROV_BINARIES" = "$BINARIES" ] || { PROVENANCE_OK=false; fail "build provenance binary hashes differ from machine.json"; }
+[ -n "$PROV_BUILD_COMMAND" ] || { PROVENANCE_OK=false; fail "build provenance has no build command"; }
+for ent in "candidate archive:$PROV_CANDIDATE_ARCHIVE" "physics archive:$PROV_PHYSICS_ARCHIVE" \
+ "aienos archive:$PROV_AIENOS_ARCHIVE" "compiler:$PROV_COMPILER" "make:$PROV_MAKE" \
+ "build log:$PROV_BUILD_LOG"; do
+ label=${ent%%:*}; value=${ent#*:}
+ is_sha256 "$value" || { PROVENANCE_OK=false; fail "$label digest is missing or malformed"; }
+done
+if [ -s "$RAW/build.log" ]; then
+ [ "$PROV_BUILD_LOG" = "$(sha256sum "$RAW/build.log" | cut -d' ' -f1)" ] \
+ || { PROVENANCE_OK=false; fail "build log digest differs from build provenance"; }
+else
+ PROVENANCE_OK=false; fail "build.log missing"
+fi
+if [ "$MODE_OK" = true ]; then
+ for ent in "bin/rx_r15_perf_$MODE:$PROV_TRIAL" \
+ "bin/rx_r15_perf_${MODE}_nodigest:$PROV_NODIGEST" "bin/r15_reduce:$PROV_REDUCER"; do
+ rel=${ent%%:*}; expected=${ent#*:}
+ if ! is_sha256 "$expected"; then
+ PROVENANCE_OK=false; fail "$rel digest is missing or malformed"
+ elif [ ! -f "$RAW/$rel" ] || [ "$(sha256sum "$RAW/$rel" | cut -d' ' -f1)" != "$expected" ]; then
+ PROVENANCE_OK=false; fail "$rel does not match the source-to-binary manifest"
+ fi
+ done
+else
+ PROVENANCE_OK=false
+fi
+
+FINAL_OK=true
+[ "$FINAL_SCHEMA" = AIEN_RX_R15_FINAL_STATE_V1 ] || { FINAL_OK=false; fail "final state schema is '$FINAL_SCHEMA'"; }
+[ "$FINAL_COMMIT" = "$RUN_COMMIT" ] || { FINAL_OK=false; fail "final state commit $FINAL_COMMIT != run commit $RUN_COMMIT"; }
+[ "$FINAL_HEAD" = "$RUN_COMMIT" ] || { FINAL_OK=false; fail "final HEAD $FINAL_HEAD != run commit $RUN_COMMIT"; }
+[ "$FINAL_DIRTY" = false ] || { FINAL_OK=false; fail "run tree was dirty at final seal"; }
+[ "$FINAL_HEAD_UNCHANGED" = true ] || { FINAL_OK=false; fail "HEAD did not remain unchanged through the run"; }
+[ "$FINAL_BINARIES_UNCHANGED" = true ] || { FINAL_OK=false; fail "an executed binary changed during the run"; }
+[ "$FINAL_BINARIES" = "$BINARIES" ] || { FINAL_OK=false; fail "final binary hashes differ from machine.json"; }
SILICON=false
-if [ "$MODE" = silicon ]; then SILICON=true; else fail "run mode is '$MODE', not silicon"; fi
+if [ "$MODE" = silicon ]; then SILICON=true
+elif [ "$MODE_OK" = true ]; then fail "run mode is '$MODE', not silicon"
+fi
# ---- pinned dependencies (aienos.lock / physics.lock at the run commit)
-AIENOS_LOCK=$(git -C "$HERE" show "$RUN_COMMIT:aienos.lock" 2>/dev/null | tr -d '[:space:]')
-PHYSICS_LOCK=$(git -C "$HERE" show "$RUN_COMMIT:physics.lock" 2>/dev/null | tr -d '[:space:]')
-if [ -z "$AIENOS" ]; then fail "aienos_commit not recorded in machine.json"
-elif [ "$AIENOS" != "$AIENOS_LOCK" ]; then fail "aienos_commit $AIENOS != aienos.lock $AIENOS_LOCK"; fi
-if [ -z "$PHYSICS" ]; then fail "physics_commit not recorded in machine.json"
-elif [ "$PHYSICS" != "$PHYSICS_LOCK" ]; then fail "physics_commit $PHYSICS != physics.lock $PHYSICS_LOCK"; fi
+AIENOS_LOCK=""; PHYSICS_LOCK=""
+if [ "$RUN_COMMIT_OK" = true ]; then
+ AIENOS_LOCK=$(git -C "$HERE" show "$RUN_COMMIT:aienos.lock" 2>/dev/null | tr -d '[:space:]')
+ PHYSICS_LOCK=$(git -C "$HERE" show "$RUN_COMMIT:physics.lock" 2>/dev/null | tr -d '[:space:]')
+fi
+DEPENDENCIES_OK=true
+[ "$RUN_COMMIT_OK" = true ] || DEPENDENCIES_OK=false
+if [ -z "$AIENOS" ]; then DEPENDENCIES_OK=false; fail "aienos_commit not recorded in machine.json"
+elif [ "$AIENOS" != "$AIENOS_LOCK" ]; then DEPENDENCIES_OK=false; fail "aienos_commit $AIENOS != aienos.lock $AIENOS_LOCK"; fi
+if [ -z "$PHYSICS" ]; then DEPENDENCIES_OK=false; fail "physics_commit not recorded in machine.json"
+elif [ "$PHYSICS" != "$PHYSICS_LOCK" ]; then DEPENDENCIES_OK=false; fail "physics_commit $PHYSICS != physics.lock $PHYSICS_LOCK"; fi
+
+# ---- candidate binding: every source, executable and final-state control
+BOUND=false
+if [ -z "$CANDIDATE" ]; then fail "no candidate commit given"
+elif [ "$CANDIDATE" != "$RUN_COMMIT" ]; then fail "run commit $RUN_COMMIT is not the candidate $CANDIDATE"
+elif [ "$TREE_DIRTY" != false ]; then fail "run tree was dirty at start"
+elif [ "$PROV_FILES_OK" != true ] || [ "$PROVENANCE_OK" != true ] || \
+ [ "$FINAL_OK" != true ] || [ "$DEPENDENCIES_OK" != true ]; then :
+else BOUND=true; fi
# ---- correctness reruns (§14, §16 item 9)
if [ -n "$RERUNS" ] && [ -s "$RERUNS" ]; then
@@ -219,6 +336,13 @@ TMP=$(mktemp "$OUTDIR/.r15-receipt.XXXXXX") || exit 2
printf ' "physics_commit": %s,\n' "$(jstr "$PHYSICS")"
printf ' "physics_lock": %s,\n' "$(jstr "$PHYSICS_LOCK")"
printf ' "benchmark_binaries_sha256": %s,\n' "${BINARIES:-null}"
+ printf ' "provenance_digest_sha256": %s,\n' "$(jstr "$PROV_DIGEST")"
+ printf ' "provenance_files_verified": %s,\n' "$PROV_FILES_OK"
+ printf ' "build_provenance": '
+ if [ -s "$PROV" ]; then tr -d '\n' < "$PROV"; else printf 'null'; fi
+ printf ',\n "final_state": '
+ if [ -s "$FINAL" ]; then tr -d '\n' < "$FINAL"; else printf 'null'; fi
+ printf ',\n'
printf ' "raw_digest_sha256": %s,\n' "$(jstr "$DIGEST_ACTUAL")"
printf ' "raw_digest_matches_reducer": %s,\n' "$DIGEST_OK"
printf ' "raw_files_verified": %s,\n' "$RAW_FILES_OK"