diff --git a/.crumb b/.crumb index 61248e065..69d561623 100644 --- a/.crumb +++ b/.crumb @@ -63,8 +63,8 @@ "purpose": "Directory doctrine. Purpose not yet described by a human." }, { - "digest": "c5c1674600955e86dbd99a603d76ef472cd3742a1e8ed239a442fd0246f10d56", - "last_commit": "a386d65", + "digest": "ee805b014db4923cbbb2a86b940e5737e76d15c636148c3576276204e8b076f1", + "last_commit": "5b826f5", "name": "mk", "purpose": "Directory mk. Purpose not yet described by a human." }, @@ -93,27 +93,27 @@ "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "3d15ce0a4e66566f1d0e5ba22d84982aa0881dacf98732c2fa56b935406a8751", - "last_commit": "ec3659f", + "digest": "c344fe651eaf853a43d4767d6ea5d29151bb4e610b67829d956b29a47d966f01", + "last_commit": "ab07608", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { - "digest": "5844e06455eea3780afb1dd3b3351ace41e1648a721491c692783c057fd2479d", - "last_commit": "ec3659f", + "digest": "546da8393e444a620edd23486a7a66b483539dd10a4c273e4bd41deacb2d218d", + "last_commit": "468354a", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:41dab9e8a3aa8db7675d36d6d394395b5bfeb9ff64e2212bc5a2b991134cf881", - "compiled_at": "2026-10-05T15:03:46Z", + "children_root": "sha256:cbc160ad83bcab2c0ff053fa2c59c79be642222c1a7733583c3cf2e70be993a9", + "compiled_at": "2026-10-05T15:28:49Z", "compiler": "crumb-compile/1", - "digest": "sha256:712e4a8b0cdc4672bb315e5fbe799cbf24ca9eda6b0011cc2a706f7b43f8a5d4", + "digest": "sha256:9ab08bdb200b75198478eef41117768be3eebef31ad0da59b0a4489497165aae", "evidence_files": 2749, "evidence_root": "sha256:c6e60c5b2803cfddf6a1fed130c92066d285ddb68aeea0bc65d58668cf139dfc", - "files": 4539, - "generated_at_commit": "ec3659fd8cda2fc4b16dbd4e729dae172ccdae6a", - "source_tree": "sha256:63721a48df45ecf4fe43294a06c2c5004307f25869633b0d2170af4ed96da90f" + "files": 4541, + "generated_at_commit": "50d535b45ee24fa8bec28ac3248be7209b6a07b0", + "source_tree": "sha256:3eb9e9d67192f0e40ce2dfb740c017a703d678161d8733b6b3a4159854d14ec8" }, "owner_lane": "", "provenance": { diff --git a/.crumbignore b/.crumbignore index 115cbebe0..753b63f5a 100644 --- a/.crumbignore +++ b/.crumbignore @@ -1,2 +1,5 @@ # evidence/ is additions-only (evidence-immutable.yml); its seeded .crumb must never be rewritten evidence +# build/ holds extracted aienos sources proven against aienos.lock byte for byte; a +# rewritten .crumb there makes the authority build refuse its own cache +build diff --git a/.github/workflows/host-suites-2.yml b/.github/workflows/host-suites-2.yml index 06403a357..6a3372bdc 100644 --- a/.github/workflows/host-suites-2.yml +++ b/.github/workflows/host-suites-2.yml @@ -334,6 +334,9 @@ jobs: - name: R16 qualify script self-test (dirty tree refused, NOT_RUN honest, failing check exits non-zero) if: ${{ !cancelled() }} run: make test-r16-qualify-selftest + - name: aienos.lock source proof (blobs of the full locked commit; modified, unrelated or other-commit trees refused) + if: ${{ !cancelled() }} + run: make test-aienos-lock-source - name: ALLEN v0 host gates (identity, restart, memory, model independence, no authority, negative control) if: ${{ !cancelled() }} env: diff --git a/Makefile b/Makefile index 8f6b4d9e9..9a9df8643 100644 --- a/Makefile +++ b/Makefile @@ -360,34 +360,46 @@ test-sem-incremental: $(RX_SEM_TEST) ./$(RX_SEM_TEST) # R7: native AIENOS authority versus the Linux oracle, then the world view. -# Default: the authority pinned by aienos.lock, extracted with `git archive` from -# AIENOS_LOCK_REPO (a clone that has the commit) into $(OUT_DIR). An override must point -# at a tree with native/capability; the build stops if it does not (the old default -# ../aienos-r9 silently had none on the Spark). +# The authority source is the FULL commit in aienos.lock, proven by +# tools/aienos_lock_source.sh from git objects (a directory name, a short SHA or an +# override is not proof). Default: extracted with `git archive` from a repository holding +# that commit (AIENOS_LOCK_REPO, or the repository around AIENOS_R7_DIR) into +# $(OUT_DIR)/aienos-authority/. An AIENOS_R7_DIR override is used only after +# the same proof: every tracked file under the subpaths built from has the locked blob +# and no unignored extra file sits beside them. The proof runs on every build (phony +# prerequisite), so a source edited after extraction stops the build. AIENOS_LOCK_REPO ?= ../aienos-argus-cap AIENOS_LOCK = $(shell head -n 1 aienos.lock) -AIENOS_R7_DEFAULT = $(OUT_DIR)/aienos-authority/$(shell echo $(AIENOS_LOCK) | cut -c1-7) +AIENOS_R7_DEFAULT = $(OUT_DIR)/aienos-authority/$(AIENOS_LOCK) AIENOS_R7_DIR ?= $(AIENOS_R7_DEFAULT) -AIENOS_CAP_LIB ?= $(AIENOS_R7_DIR)/native/capability/out/libaienos_capability.a +AIENOS_CAP_LIB ?= $(OUT_DIR)/aienos-cap/$(AIENOS_LOCK)/libaienos_capability.a +# $(call aienos_source,): materialize into the default cache, or prove the override. +aienos_source = if [ "$(AIENOS_R7_DIR)" = "$(AIENOS_R7_DEFAULT)" ]; then \ + AIENOS_LOCK_REPO="$(AIENOS_LOCK_REPO)" AIENOS_R7_DIR= bash tools/aienos_lock_source.sh materialize "$(AIENOS_R7_DIR)" $(1); \ + else \ + AIENOS_LOCK_REPO="$(AIENOS_LOCK_REPO)" AIENOS_R7_DIR="$(AIENOS_R7_DIR)" bash tools/aienos_lock_source.sh verify-dir "$(AIENOS_R7_DIR)" $(1); \ + fi || { echo "error: the aienos authority source is not the aienos.lock commit $(AIENOS_LOCK) (see above)."; \ + echo " pass AIENOS_LOCK_REPO=, or AIENOS_R7_DIR=;"; \ + echo " a modified default cache under $(OUT_DIR)/aienos-authority must be deleted, not reused."; exit 1; } RX_R7_SRCS = src/runtime/rx_caproot.c src/runtime/rx_world.c src/runtime/rx_coherent.c \ src/runtime/rx_native_bind.c src/sha256.c src/omega_evidence.c \ tests/runtime/rx_r7_native.c RX_R7_TEST = $(OUT_DIR)/rx_r7_native_test -$(AIENOS_CAP_LIB): - @if [ "$(AIENOS_R7_DIR)" = "$(AIENOS_R7_DEFAULT)" ] && [ ! -d "$(AIENOS_R7_DIR)/native/capability" ]; then \ - test -n "$(AIENOS_LOCK)" || { echo "aienos.lock is empty"; exit 1; }; \ - git -C "$(AIENOS_LOCK_REPO)" cat-file -e "$(AIENOS_LOCK)^{commit}" 2>/dev/null || { \ - echo "error: AIENOS_LOCK_REPO=$(AIENOS_LOCK_REPO) is not an aienos clone with commit $(AIENOS_LOCK) (aienos.lock)."; \ - echo " pass AIENOS_LOCK_REPO=, e.g. make AIENOS_LOCK_REPO=$$HOME/workspace/aienos-argus-cap ,"; \ - echo " or AIENOS_R7_DIR=."; exit 1; }; \ - mkdir -p "$(AIENOS_R7_DIR)" && \ - git -C $(AIENOS_LOCK_REPO) archive $(AIENOS_LOCK) native/capability | tar -x -C "$(AIENOS_R7_DIR)"; \ - fi - @test -f "$(AIENOS_R7_DIR)/native/capability/Makefile" || { \ - echo "AIENOS_R7_DIR=$(AIENOS_R7_DIR) has no native/capability:"; \ - echo " set AIENOS_R7_DIR to an aienos tree at aienos.lock, or AIENOS_LOCK_REPO to a clone with it"; exit 1; } - $(MAKE) -C $(AIENOS_R7_DIR)/native/capability +.PHONY: aienos-authority-capability +aienos-authority-capability: + @$(call aienos_source,native/capability) + +# Built out of tree from the proven source into a fresh directory on every build; the +# library is replaced only when its bytes change (ar is deterministic), so nothing relinks +# when nothing changed and no stale or planted object is ever reused. The inner make is +# called by name with MAKEFLAGS cleared: the outer command line (CFLAGS=..., -n, -W) +# never reaches the authority build, and a dry run (make -n) only prints this recipe. +$(AIENOS_CAP_LIB): aienos-authority-capability + @t=$$(mktemp -d "$${TMPDIR:-/tmp}/aienos-cap.XXXXXX") && \ + env -u MAKEFLAGS -u MFLAGS -u MAKELEVEL make -s -C $(AIENOS_R7_DIR)/native/capability OUT=$$t $$t/libaienos_capability.a >/dev/null && \ + mkdir -p $(dir $@) && { cmp -s $$t/libaienos_capability.a $@ || cp $$t/libaienos_capability.a $@; }; \ + rc=$$?; rm -rf $$t; exit $$rc # OMEGA_EFFECT_CAP64 (spec/effect-cap64-migration.md): effect objects carry the # full 64-bit AIENOS capability generation. Physics-free: the Omega core, the @@ -395,7 +407,7 @@ $(AIENOS_CAP_LIB): # (aienos.lock) used directly. Prints OMEGA_EFFECT_CAP64_{ROUNDTRIP,IDENTITY, # STALE_REJECT,AUTHORITY}_PASS gate lines. EFFECT_CAP64_CAP_LIB ?= $(AIENOS_CAP_LIB) -EFFECT_CAP64_CAP_INC ?= $(patsubst %/,%,$(dir $(EFFECT_CAP64_CAP_LIB)))/.. +EFFECT_CAP64_CAP_INC ?= $(AIENOS_R7_DIR)/native/capability EFFECT_CAP64_TEST = $(OUT_DIR)/tests-effect/test_effect_cap64 EFFECT_CAP64_OBJS = $(addprefix $(OUT_DIR)/,sha256.o omega_canonical.o omega_validate.o omega_core.o omega_codec.o) @@ -843,6 +855,12 @@ test-r16-inventory: $(R16_INVENTORY) test-r16-qualify-selftest: bash tests/r16_qualify/run.sh +# The aienos.lock source proof (tools/aienos_lock_source.sh) and the authority build rule +# that uses it: fixture repositories, host only. +.PHONY: test-aienos-lock-source +test-aienos-lock-source: + bash tests/aienos_lock_source/run.sh + # R16-G3: the authoritative path with the legacy orchestrators unavailable. # Link map, shared libraries, embedded names and an exec trace of the R13 # living system and the R14 recovery run, legacy programs stubbed on PATH. @@ -899,7 +917,7 @@ test-r16-negative: $(RX_R16_NEGATIVE) # "Removing any one guard turns the test red": rebuilds the G4 test against # scratch copies with one guard removed at a time; each must FAIL. Minutes. test-r16-negative-mutants: $(RX_R16_NEGATIVE) - sh tests/r16_negative/mutate.sh "$(CC)" "$(CFLAGS)" "$(AIENOS_R7_DIR)" \ + R16_CAP_LIB="$(AIENOS_CAP_LIB)" sh tests/r16_negative/mutate.sh "$(CC)" "$(CFLAGS)" "$(AIENOS_R7_DIR)" \ $(RX_R15_RIG_SRCS) tests/runtime/rx_r16_negative.c # R16-G5 API/build surface: legacy modes only under explicit names, the SEQ diff --git a/mk/.crumb b/mk/.crumb index 2f29a3f14..7f6ef1e69 100644 --- a/mk/.crumb +++ b/mk/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-05T14:17:15Z", + "compiled_at": "2026-10-05T15:04:25Z", "compiler": "crumb-compile/1", - "digest": "sha256:c5c1674600955e86dbd99a603d76ef472cd3742a1e8ed239a442fd0246f10d56", + "digest": "sha256:ee805b014db4923cbbb2a86b940e5737e76d15c636148c3576276204e8b076f1", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 55, - "generated_at_commit": "ca12ad5bb771d41056b9c99571d736171a64b78d", - "source_tree": "sha256:5236dbd9da84e1d6c1733a05fd7cd2d0e5aba277aa822b3b9bcc1ce1d89356f7" + "generated_at_commit": "509fc2f2a20331b9c950fbc495b4fffb0a9825a6", + "source_tree": "sha256:b903311360d7a9a6329a01c60413e6fc1fb8fd835bf8bf2b4c43bef80d031ade" }, "owner_lane": "", "provenance": { diff --git a/mk/allen.mk b/mk/allen.mk index 44530fa07..df40050d0 100644 --- a/mk/allen.mk +++ b/mk/allen.mk @@ -38,20 +38,18 @@ ALLEN_RX_SRCS = src/runtime/rx_caproot.c src/runtime/rx_world.c src/runtime/rx_c ALLEN_HDRS = src/allen/allen_bind.h src/runtime/rx_aien.h src/runtime/rx_world.h \ src/runtime/rx_cortex.h src/runtime/rx_cortex_record.h src/runtime/aienos_cap.h -# The aienos trees the codec needs, at aienos.lock (same shape as the -# $(AIENOS_CAP_LIB) rule). The stamp records the lock it was made for. -$(ALLEN_STAMP): aienos.lock +# The aienos trees the codec needs, at aienos.lock, proven like the $(AIENOS_CAP_LIB) +# source (Makefile R7 block) on every build. The stamp records the lock and is rewritten +# only when it changes, so a passing proof does not rebuild the objects. +.PHONY: aienos-authority-allen +aienos-authority-allen: + @$(call aienos_source,native/kernel/svc native/kernel/core native/argus native/store) + +$(ALLEN_STAMP): aienos.lock aienos-authority-allen @mkdir -p $(ALLEN_DIR) - @if [ "$(AIENOS_R7_DIR)" = "$(AIENOS_R7_DEFAULT)" ] && [ ! -f "$(ALLEN_AIENOS_SVC)/continuity_subject.h" ]; then \ - git -C $(AIENOS_LOCK_REPO) cat-file -e $(AIENOS_LOCK)^{commit} 2>/dev/null || { \ - echo "aienos.lock commit $(AIENOS_LOCK) is not in AIENOS_LOCK_REPO=$(AIENOS_LOCK_REPO)"; exit 1; }; \ - mkdir -p "$(AIENOS_R7_DIR)" && \ - git -C $(AIENOS_LOCK_REPO) archive $(AIENOS_LOCK) native/kernel/svc native/kernel/core native/argus native/store \ - | tar -x -C "$(AIENOS_R7_DIR)"; \ - fi @test -f "$(ALLEN_AIENOS_SVC)/continuity_subject.h" || { \ echo "AIENOS_R7_DIR=$(AIENOS_R7_DIR) has no native/kernel/svc/continuity_subject.h (aienos.lock too old?)"; exit 1; } - @echo "$(AIENOS_LOCK)" > $@ + @echo "$(AIENOS_LOCK)" | cmp -s - $@ || echo "$(AIENOS_LOCK)" > $@ $(ALLEN_BIND_OBJ): src/allen/allen_bind.c $(ALLEN_HDRS) $(ALLEN_STAMP) $(CC) $(CFLAGS) $(ALLEN_AIENOS_INC) -c -o $@ src/allen/allen_bind.c diff --git a/mk/visor-authority.mk b/mk/visor-authority.mk index e227f5230..946e6cdb0 100644 --- a/mk/visor-authority.mk +++ b/mk/visor-authority.mk @@ -16,9 +16,9 @@ # Makefile's pinned default for every authority target (R7 to R16). AIENOS_LOCK_REPO ?= ../aienos-argus-cap AIENOS_LOCK = $(shell head -n 1 aienos.lock) -AIENOS_R7_DEFAULT = $(OUT_DIR)/aienos-authority/$(shell echo $(AIENOS_LOCK) | cut -c1-7) +AIENOS_R7_DEFAULT = $(OUT_DIR)/aienos-authority/$(AIENOS_LOCK) AIENOS_R7_DIR ?= $(AIENOS_R7_DEFAULT) -AIENOS_CAP_LIB ?= $(AIENOS_R7_DIR)/native/capability/out/libaienos_capability.a +AIENOS_CAP_LIB ?= $(OUT_DIR)/aienos-cap/$(AIENOS_LOCK)/libaienos_capability.a VISOR_AUTH_CAP_LIB ?= $(AIENOS_CAP_LIB) VISOR_AUTH_RX_SRCS = src/runtime/rx_caproot.c src/runtime/rx_world.c src/runtime/rx_coherent.c \ src/runtime/rx_generation.c src/runtime/rx_aegis.c diff --git a/tests/.crumb b/tests/.crumb index 68ff3fed0..ffebfa593 100644 --- a/tests/.crumb +++ b/tests/.crumb @@ -229,8 +229,8 @@ "purpose": "Directory tests/r16_inventory. Purpose not yet described by a human." }, { - "digest": "ee440289b52f009835a35b384e086872b04cecb15665b9682a0d27a5dfee30c9", - "last_commit": "520c895", + "digest": "bcbd86e0fc80826cf66b7c2bbd71b6eab93c539313dbd042f30f3bb1fd3c5659", + "last_commit": "5b826f5", "name": "r16_negative", "purpose": "Directory tests/r16_negative. Purpose not yet described by a human." }, @@ -283,15 +283,15 @@ "purpose": "Directory tests/visor. Purpose not yet described by a human." } ], - "children_root": "sha256:215c9654ba0e4f579f3f1c7f09b3ecdacc7c922de1af68565150b55fedf9729a", - "compiled_at": "2026-10-05T15:03:46Z", + "children_root": "sha256:ca83c873b245d9a367fabf72c1d7ab183ace4a7ada1139333778b6ec1d928781", + "compiled_at": "2026-10-05T15:28:49Z", "compiler": "crumb-compile/1", - "digest": "sha256:3d15ce0a4e66566f1d0e5ba22d84982aa0881dacf98732c2fa56b935406a8751", + "digest": "sha256:c344fe651eaf853a43d4767d6ea5d29151bb4e610b67829d956b29a47d966f01", "evidence_files": 11, "evidence_root": "sha256:d5c1bceb4d57ef0eb42797c58801b5926509711614c3e38bb7105b6efa3942f2", - "files": 798, - "generated_at_commit": "ec3659fd8cda2fc4b16dbd4e729dae172ccdae6a", - "source_tree": "sha256:f346163d2500f3984cebb6ecc27c2e93787c92dd296ee676a8c443aa762cc425" + "files": 799, + "generated_at_commit": "50d535b45ee24fa8bec28ac3248be7209b6a07b0", + "source_tree": "sha256:da421f93937838ed46d86d46893c0bf4863dbe2b02563bdf805cf0027347847a" }, "owner_lane": "", "provenance": { diff --git a/tests/aienos_lock_source/run.sh b/tests/aienos_lock_source/run.sh new file mode 100644 index 000000000..e3cda22f0 --- /dev/null +++ b/tests/aienos_lock_source/run.sh @@ -0,0 +1,122 @@ +#!/bin/bash +# Test for tools/aienos_lock_source.sh and the Makefile rule that builds the trusted +# capability root from it. Host only, no chip. Fixture git repositories stand in for aienos. +# Every counterexample must be refused with the right exit status: 1 = verified mismatch or +# absence, 2 = the locked commit cannot be read (never reported as absent, never as proven). +# Usage: bash tests/aienos_lock_source/run.sh +set -u +HERE=$(cd "$(dirname "$0")/../.." && pwd) +SCR=$(mktemp -d "${TMPDIR:-/tmp}/aienos-lock-src.XXXXXX") || exit 2 +trap 'rm -rf "$SCR"' EXIT INT TERM +FAILS=0 +check() { if eval "$2"; then echo "ok $1"; else echo "FAIL $1"; FAILS=$((FAILS + 1)); fi; } +T="$HERE/tools/aienos_lock_source.sh" +export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=advice.detachedHead GIT_CONFIG_VALUE_0=false + +# Fixture aienos: commit GOOD has a buildable native/capability; commit A lacks aienos_cap_mint. +LK=$SCR/aienos +lkg() { git -C "$LK" -c user.name=t -c user.email=t@invalid -c commit.gpgsign=false "$@"; } +mkdir -p "$LK/native/capability" "$LK/native/store" +printf 'out/\n' > "$LK/native/capability/.gitignore" +printf 'int aienos_cap_validate(int v)\n{ return v; }\nint aienos_cap_mint(int a)\n{ return a; }\n' > "$LK/native/capability/aienos_capability.c" +printf 'OUT ?= out\n$(OUT)/libaienos_capability.a: aienos_capability.c\n\tmkdir -p $(OUT) && $(CC) -c -o $(OUT)/aienos_capability.o aienos_capability.c && ar rcs $@ $(OUT)/aienos_capability.o\n' > "$LK/native/capability/Makefile" +printf 'int store_v1;\n' > "$LK/native/store/store_v1.c" +lkg init -q && lkg add -A && lkg commit -qm good +GOOD=$(git -C "$LK" rev-parse HEAD) +sed -i 's/aienos_cap_mint(/aienos_cap_other(/' "$LK/native/capability/aienos_capability.c"; lkg commit -qam "A: no mint" +A=$(git -C "$LK" rev-parse HEAD) +lkg checkout -q "$GOOD" +L() { env AIENOS_LOCK_REPO="$LK" AIENOS_R7_DIR= "$@"; } +rc() { "$@" >/dev/null 2>&1; echo $?; } + +# 1. reading blobs of the locked commit +check "show: locked file read (exit 0)" '[ "$(L AIENOS_LOCK=$GOOD bash "$T" show native/capability/aienos_capability.c | grep -c aienos_cap_mint)" = 1 ]' +check "blob: equals the commit's blob id" '[ "$(L AIENOS_LOCK=$GOOD bash "$T" blob native/capability/aienos_capability.c)" = "$(git -C "$LK" rev-parse "$GOOD:native/capability/aienos_capability.c")" ]' +check "show: path absent at the locked commit is exit 1 (verified absence)" '[ "$(rc L AIENOS_LOCK=$GOOD bash "$T" show native/capability/none.c)" = 1 ]' +check "show: lock A is read as A although HEAD is GOOD" '! L AIENOS_LOCK=$A bash "$T" show native/capability/aienos_capability.c | grep -q aienos_cap_mint' +check "identity: names the full lock and its tree" '[ "$(L AIENOS_LOCK=$GOOD bash "$T" identity | jq -r .commit_tree)" = "$(git -C "$LK" rev-parse "$GOOD^{tree}")" ]' +check "unavailable repository: exit 2, not 1" '[ "$(rc env AIENOS_LOCK_REPO=/nonexistent AIENOS_LOCK=$GOOD bash "$T" show native/capability/aienos_capability.c)" = 2 ]' +check "repository without the locked commit: exit 2" '[ "$(rc env AIENOS_LOCK_REPO="$LK" AIENOS_LOCK=0123456789abcdef0123456789abcdef01234567 bash "$T" identity)" = 2 ]' +check "abbreviated lock refused: exit 2" '[ "$(rc L AIENOS_LOCK=${GOOD:0:7} bash "$T" identity)" = 2 ]' +check "uppercase or padded lock refused: exit 2" '[ "$(rc L AIENOS_LOCK="${GOOD^^}" bash "$T" identity)" = 2 ] && [ "$(rc L AIENOS_LOCK="$GOOD " bash "$T" identity)" = 2 ]' +lkg replace "$A" "$GOOD" +check "replace ref A->GOOD ignored: A still lacks mint" '! L AIENOS_LOCK=$A bash "$T" show native/capability/aienos_capability.c | grep -q aienos_cap_mint' +lkg replace -d "$A" >/dev/null +# a loose object whose bytes were replaced on disk (here: by another object's bytes) no +# longer hashes to its id +CORR=$SCR/corrupt; cp -r "$LK" "$CORR" +B=$(git -C "$CORR" rev-parse "$A:native/capability/aienos_capability.c") +X=$(printf 'int aienos_cap_mint(int a)\n{ return a; }\n' | git -C "$CORR" hash-object --stdin -w) +obj="$CORR/.git/objects/${B:0:2}/${B:2}" +chmod u+w "$obj" && cp "$CORR/.git/objects/${X:0:2}/${X:2}" "$obj" +check "altered object bytes: refused (exit 2), never read as content" '[ "$(rc env AIENOS_LOCK_REPO="$CORR" AIENOS_R7_DIR= AIENOS_LOCK=$A bash "$T" show native/capability/aienos_capability.c)" = 2 ]' + +# 2. directories: proven only against the locked commit +D=$SCR/cache +check "materialize into an empty cache: exit 0" '[ "$(rc L AIENOS_LOCK=$GOOD bash "$T" materialize "$D" native/capability)" = 0 ]' +check "proven cache verifies: exit 0" '[ "$(rc L AIENOS_LOCK=$GOOD bash "$T" verify-dir "$D" native/capability)" = 0 ]' +make -s -C "$D/native/capability" >/dev/null 2>&1 +check "in-tree build outputs (ignored out/, could hold planted objects) refused: exit 1" '[ -f "$D/native/capability/out/libaienos_capability.a" ] && [ "$(rc L AIENOS_LOCK=$GOOD bash "$T" verify-dir "$D" native/capability)" = 1 ]' +rm -rf "$D/native/capability/out" +echo 'int evil;' > "$D/native/capability/evil.c"; printf '*.c\n' > "$D/.gitignore"; printf 'evil.c\n' > "$D/native/.gitignore" +check "extra file hidden by ignore files above the checked subpath: exit 1" '[ "$(rc L AIENOS_LOCK=$GOOD bash "$T" verify-dir "$D" native/capability)" = 1 ]' +rm -f "$D/native/capability/evil.c" "$D/.gitignore" "$D/native/.gitignore" +chmod +x "$D/native/capability/aienos_capability.c" +check "file mode changed: exit 1" '[ "$(rc L AIENOS_LOCK=$GOOD bash "$T" verify-dir "$D" native/capability)" = 1 ]' +chmod -x "$D/native/capability/aienos_capability.c" +# Attribute and config filters must not decide what "matches" means: a planted +# "* text eol=lf" (root, above the subpath, or in the lock repo's info/attributes) +# plus core.autocrlf would make git normalize CRLF edits away. +sed -i 's/$/\r/' "$D/native/capability/aienos_capability.c" +printf '* text eol=lf\n' > "$D/.gitattributes"; printf '* text eol=lf\n' > "$D/native/.gitattributes" +mkdir -p "$(git -C "$LK" rev-parse --absolute-git-dir)/info"; printf '* text eol=lf\n' > "$(git -C "$LK" rev-parse --absolute-git-dir)/info/attributes" +check "CRLF edit hidden by planted .gitattributes and info/attributes: exit 1" '[ "$(rc L GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=core.autocrlf GIT_CONFIG_VALUE_0=input AIENOS_LOCK=$GOOD bash "$T" verify-dir "$D" native/capability)" = 1 ]' +rm -f "$D/.gitattributes" "$D/native/.gitattributes" "$(git -C "$LK" rev-parse --absolute-git-dir)/info/attributes" +git -C "$LK" show "$GOOD:native/capability/aienos_capability.c" > "$D/native/capability/aienos_capability.c" +check "restored file verifies again: exit 0" '[ "$(rc L AIENOS_LOCK=$GOOD bash "$T" verify-dir "$D" native/capability)" = 0 ]' +cp "$D/native/capability/aienos_capability.c" "$SCR/same-bytes.c"; rm "$D/native/capability/aienos_capability.c" +ln -s "$SCR/same-bytes.c" "$D/native/capability/aienos_capability.c" +check "file replaced by a symlink to identical bytes: exit 1" '[ "$(rc L AIENOS_LOCK=$GOOD bash "$T" verify-dir "$D" native/capability)" = 1 ]' +rm "$D/native/capability/aienos_capability.c"; cp "$SCR/same-bytes.c" "$D/native/capability/aienos_capability.c" +echo 'int injected;' >> "$D/native/capability/aienos_capability.c" +check "modified cached source: exit 1" '[ "$(rc L AIENOS_LOCK=$GOOD bash "$T" verify-dir "$D" native/capability)" = 1 ]' +check "materialize does not re-extract over a modified cache: exit 1" '[ "$(rc L AIENOS_LOCK=$GOOD bash "$T" materialize "$D" native/capability)" = 1 ]' +git -C "$LK" show "$GOOD:native/capability/aienos_capability.c" > "$D/native/capability/aienos_capability.c" +echo 'int extra;' > "$D/native/capability/extra.c" +check "extra unignored file beside the locked sources: exit 1" '[ "$(rc L AIENOS_LOCK=$GOOD bash "$T" verify-dir "$D" native/capability)" = 1 ]' +rm "$D/native/capability/extra.c" "$D/native/capability/Makefile" +check "missing locked file: exit 1" '[ "$(rc L AIENOS_LOCK=$GOOD bash "$T" verify-dir "$D" native/capability)" = 1 ]' +UNREL=$SCR/unrelated; mkdir -p "$UNREL/native/capability"; cp "$LK/native/capability/"* "$UNREL/native/capability/" +check "unrelated directory with plausible functions, no lock repo: exit 2" '[ "$(rc env AIENOS_LOCK_REPO=/nonexistent AIENOS_R7_DIR="$UNREL" AIENOS_LOCK=$GOOD bash "$T" verify-dir "$UNREL" native/capability)" = 2 ]' +check "unrelated directory checked against lock A: exit 1" '[ "$(rc L AIENOS_LOCK=$A bash "$T" verify-dir "$UNREL" native/capability)" = 1 ]' +CL=$SCR/clone; git clone -q "$LK" "$CL"; git -C "$CL" -c advice.detachedHead=false checkout -q "$GOOD" +check "clean checkout of a different commit (GOOD) against lock A: exit 1" '[ "$(rc env AIENOS_LOCK_REPO=/nonexistent AIENOS_R7_DIR="$CL" AIENOS_LOCK=$A bash "$T" verify-dir "$CL" native/capability)" = 1 ]' +check "clean checkout of the locked commit, proven through its own repository: exit 0" '[ "$(rc env AIENOS_LOCK_REPO=/nonexistent AIENOS_R7_DIR="$CL" AIENOS_LOCK=$GOOD bash "$T" verify-dir "$CL" native/capability)" = 0 ]' +echo 'int dirty;' >> "$CL/native/capability/aienos_capability.c" +check "dirty checkout of the locked commit: exit 1" '[ "$(rc env AIENOS_LOCK_REPO=/nonexistent AIENOS_R7_DIR="$CL" AIENOS_LOCK=$GOOD bash "$T" verify-dir "$CL" native/capability)" = 1 ]' + +# 3. the Makefile rule: the capability library is built only from a proven source, on every build +W=$SCR/omega; mkdir -p "$W" +cp -r "$HERE/Makefile" "$HERE/mk" "$HERE/tools" "$W/" +cp "$HERE/physics.lock" "$W/" 2>/dev/null || true +echo "$GOOD" > "$W/aienos.lock" +M() { make -s -C "$W" AIENOS_LOCK_REPO="$LK" "$@" >"$SCR/make.log" 2>&1; echo $?; } +check "make: default cache materialized and library built" '[ "$(M build/aienos-cap/$GOOD/libaienos_capability.a)" = 0 ] && [ -f "$W/build/aienos-cap/$GOOD/libaienos_capability.a" ] && [ ! -e "$W/build/aienos-authority/$GOOD/native/capability/out" ]' +L1=$(stat -c %Y.%s "$W/build/aienos-cap/$GOOD/libaienos_capability.a"); sleep 1 +check "make: second build replaces nothing (no relink)" '[ "$(M build/aienos-cap/$GOOD/libaienos_capability.a)" = 0 ] && [ "$(stat -c %Y.%s "$W/build/aienos-cap/$GOOD/libaienos_capability.a")" = "$L1" ]' +printf 'junk' > "$W/build/aienos-cap/$GOOD/libaienos_capability.a" +check "make: planted library replaced by the fresh build from the proven source" '[ "$(M build/aienos-cap/$GOOD/libaienos_capability.a)" = 0 ] && ar t "$W/build/aienos-cap/$GOOD/libaienos_capability.a" | grep -q aienos_capability.o' +echo 'int injected;' >> "$W/build/aienos-authority/$GOOD/native/capability/aienos_capability.c" +check "make: cache edited after extraction stops the next build" '[ "$(M build/aienos-cap/$GOOD/libaienos_capability.a)" != 0 ] && grep -q "not the aienos.lock commit" "$SCR/make.log"' +check "make: unrelated AIENOS_R7_DIR override refused" '[ "$(M AIENOS_R7_DIR="$UNREL" build/aienos-cap/$GOOD/libaienos_capability.a)" != 0 ]' +git -C "$CL" checkout -q -- . +check "make: clean checkout of a different commit as override refused" '[ "$(cd "$CL" && git -c advice.detachedHead=false checkout -q "$A"; M AIENOS_R7_DIR="$CL" build/aienos-cap/$GOOD/libaienos_capability.a)" != 0 ]' +git -C "$CL" checkout -q "$GOOD" +mkdir -p "$CL/native/capability/out"; echo planted > "$CL/native/capability/out/aienos_capability.o" +check "make: locked checkout with a planted out/ object refused" '[ "$(M AIENOS_R7_DIR="$CL" build/aienos-cap/$GOOD/libaienos_capability.a)" != 0 ]' +rm -rf "$CL/native/capability/out" +check "make: clean checkout of the locked commit as override builds" '[ "$(M AIENOS_R7_DIR="$CL" build/aienos-cap/$GOOD/libaienos_capability.a)" = 0 ]' +check "make: lock repository missing the commit refused" '[ "$(make -s -C "$W" AIENOS_LOCK_REPO=/nonexistent AIENOS_R7_DIR="$UNREL" build/aienos-cap/$GOOD/libaienos_capability.a >/dev/null 2>&1; echo $?)" != 0 ]' + +if [ "$FAILS" -ne 0 ]; then echo "aienos lock source test: $FAILS FAILED"; exit 1; fi +echo "aienos lock source test: PASS" diff --git a/tests/r16_negative/.crumb b/tests/r16_negative/.crumb index 81b7ef892..56b37ebce 100644 --- a/tests/r16_negative/.crumb +++ b/tests/r16_negative/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-04T13:47:05Z", + "compiled_at": "2026-10-05T15:04:25Z", "compiler": "crumb-compile/1", - "digest": "sha256:ee440289b52f009835a35b384e086872b04cecb15665b9682a0d27a5dfee30c9", + "digest": "sha256:bcbd86e0fc80826cf66b7c2bbd71b6eab93c539313dbd042f30f3bb1fd3c5659", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 1, - "generated_at_commit": "834ee93e4314a42c1127a2fcda8b29cf3b511245", - "source_tree": "sha256:b7bb5b50a10aaa649879256e511dfb341419203635fa8568e8112808cda4fb63" + "generated_at_commit": "509fc2f2a20331b9c950fbc495b4fffb0a9825a6", + "source_tree": "sha256:9b33cab85ea4c1600c98617d009e0257f303bf7e94f7ae8a81f8c949d2b5d2a7" }, "owner_lane": "", "provenance": { diff --git a/tests/r16_negative/mutate.sh b/tests/r16_negative/mutate.sh index e474be525..4c7801db7 100755 --- a/tests/r16_negative/mutate.sh +++ b/tests/r16_negative/mutate.sh @@ -23,7 +23,7 @@ set -u [ $# -ge 4 ] || { echo "usage: $0 " >&2; exit 2; } cc=$1; cflags=$2; r7=$3; shift 3 srcs="$*" -lib="$r7/native/capability/out/libaienos_capability.a" +lib=${R16_CAP_LIB:-$r7/native/capability/out/libaienos_capability.a} # make passes $(AIENOS_CAP_LIB) [ -f "$lib" ] || { echo "R16-G4 mutants: missing $lib" >&2; exit 2; } tmp=$(mktemp -d "${TMPDIR:-/tmp}/r16-mutants.XXXXXX") || exit 2 trap 'rm -rf "$tmp"' EXIT INT TERM diff --git a/tests/r16_qualify/run.sh b/tests/r16_qualify/run.sh index 6902ac6df..04cbafb66 100755 --- a/tests/r16_qualify/run.sh +++ b/tests/r16_qualify/run.sh @@ -16,7 +16,7 @@ check() { if eval "$2"; then echo "ok $1"; else echo "FAIL $1"; FAILS=$((FAILS W=$SCR/w mkdir -p "$W/tools" -cp "$HERE/tools/r16_qualify.sh" "$W/tools/" +cp "$HERE/tools/r16_qualify.sh" "$HERE/tools/aienos_lock_source.sh" "$W/tools/" G6FILES="src/omega_accelerator_world.c src/runtime/rx_generation.c src/omega_world_gates.c tools/omegatool.c src/runtime/rx_native_bind.c src/omega_evidence.c src/omega_verify.c src/runtime/rx_resident_gpu.c src/runtime/rx_seq_reference.c src/runtime/rx_world.c src/runtime/rx_living.c" for p in $G6FILES; do mkdir -p "$W/$(dirname "$p")"; cp "$HERE/$p" "$W/$p"; done printf 'build/\n' > "$W/.gitignore" @@ -240,7 +240,7 @@ check "G6 all good: G6 is MISSING_IMPLEMENTATION (operator emergency controls na check "G6 all good: eleven items PASS, operator emergency controls MISSING_IMPLEMENTATION" '[ "$(grep -c "\"item\": \"[a-z0-9_]*\", \"status\": \"PASS\"" "$R")" = 11 ] && [ "$(g6_item operator_emergency_controls_passing)" = MISSING_IMPLEMENTATION ]' check "G6 all good: protected_surfaces_kept six presence flags true" '[ "$(grep -c "_present\": true" "$R")" = 6 ]' check "G6 all good: no FAIL anywhere and G6 alone does not make the run pass (exit 3)" '[ $rc = 3 ] && ! echo "$out" | grep -q "G6=FAIL"' -check "G6 all good: receipt names file and symbol per item" 'grep -q "\"file\": \"src/runtime/rx_generation.c\", \"symbol\": \"rx_gen_recover\", \"defined\": true" "$R"' +check "G6 all good: receipt names file and symbol per item" 'grep -q "\"file\": \"src/runtime/rx_generation.c\", \"symbol\": \"rx_gen_recover\", \"source\": \"omega_tree\", \"defined\": true" "$R"' check "G6 operated checks cite the test and its status" 'grep -q "{\"name\": \"R9\", \"target\": \"test-r9\", \"status\": \"PASS\"}" "$R"' # presence without operation: symbols all defined, tests never ran -> NOT_RUN, never PASS @@ -329,6 +329,47 @@ check "G6 pinned tree unreadable: trusted_capability_root NOT_RUN (not MISSING, out=$(G6Q) check "G6 pinned tree readable again: trusted_capability_root PASS" '[ "$(g6_item trusted_capability_root_present)" = PASS ]' +# 8c. capability-root source identity (the locked commit, never a directory). Lock A lacks +# aienos_cap_mint; every place that has it must not turn the item PASS. +GOODLOCK=$(cat "$W/aienos.lock") +lkg() { git -C "$LK" -c user.name=r16 -c user.email=r16@invalid -c commit.gpgsign=false "$@"; } +lkg checkout -q -b lacks-mint "$GOODLOCK" +sed -i 's/aienos_cap_mint(/aienos_cap_other(/' "$LK/native/capability/aienos_capability.c"; lkg commit -qam "lock A: no mint" +ALOCK=$(git -C "$LK" rev-parse HEAD); lkg checkout -q - +printf '%s\n' "$ALOCK" > "$W/aienos.lock"; g add -A; g commit -qm "lock A" +UNREL=$SCR/unrelated; mkdir -p "$UNREL/native/capability" +printf 'int aienos_cap_validate(const void *v)\n{ return 0; }\nint aienos_cap_mint(void *a)\n{ return 0; }\n' > "$UNREL/native/capability/aienos_capability.c" +out=$(Q R16_RUN_ID=g6 AIENOS_R7_DIR="$UNREL" 2>&1) +check "G6 lock A + unrelated dir with plausible functions: MISSING_IMPLEMENTATION (dir not read)" '[ "$(g6_item trusted_capability_root_present)" = MISSING_IMPLEMENTATION ]' +out=$(Q R16_RUN_ID=g6 AIENOS_R7_DIR="$UNREL" AIENOS_LOCK_REPO=/nonexistent 2>&1) +check "G6 lock A unavailable + unrelated dir supplied: NOT_RUN (not PASS)" '[ "$(g6_item trusted_capability_root_present)" = NOT_RUN ]' +check "G6 unavailable: receipt g6_lock_source status unavailable" '[ "$(jq -r .g6_lock_source.status "$R")" = unavailable ]' +CLONE=$SCR/clean-other; git clone -q "$LK" "$CLONE"; git -C "$CLONE" checkout -q "$GOODLOCK" +out=$(Q R16_RUN_ID=g6 AIENOS_R7_DIR="$CLONE" 2>&1) +check "G6 lock A + clean checkout of a different commit that has mint: MISSING_IMPLEMENTATION" '[ "$(g6_item trusted_capability_root_present)" = MISSING_IMPLEMENTATION ]' +out=$(Q R16_RUN_ID=g6 AIENOS_R7_DIR="$CLONE" AIENOS_LOCK_REPO=/nonexistent 2>&1) +check "G6 lock A, no lock repo, other-commit checkout whose repo holds A: MISSING_IMPLEMENTATION (A read, not the files)" '[ "$(g6_item trusted_capability_root_present)" = MISSING_IMPLEMENTATION ]' +for c in "$ALOCK" "${ALOCK:0:7}"; do + mkdir -p "$W/build/aienos-authority/$c/native/capability" + cp "$UNREL/native/capability/aienos_capability.c" "$W/build/aienos-authority/$c/native/capability/" +done +out=$(Q R16_RUN_ID=g6 2>&1) +check "G6 lock A + modified cache dirs (full and short name) with mint: MISSING_IMPLEMENTATION" '[ "$(g6_item trusted_capability_root_present)" = MISSING_IMPLEMENTATION ]' +rm -rf "$W/build/aienos-authority" +lkg replace "$ALOCK" "$GOODLOCK" +out=$(Q R16_RUN_ID=g6 2>&1) +check "G6 lock A with a git replace ref onto a commit that has mint: MISSING_IMPLEMENTATION" '[ "$(g6_item trusted_capability_root_present)" = MISSING_IMPLEMENTATION ]' +lkg replace -d "$ALOCK" >/dev/null +printf '%s\n' "${GOODLOCK:0:7}" > "$W/aienos.lock"; g add -A; g commit -qm "short lock" +out=$(Q R16_RUN_ID=g6 2>&1) +check "G6 abbreviated aienos.lock: NOT_RUN, g6_lock_source malformed_lock" '[ "$(g6_item trusted_capability_root_present)" = NOT_RUN ] && [ "$(jq -r .g6_lock_source.status "$R")" = malformed_lock ]' +printf '%s\n' "$GOODLOCK" > "$W/aienos.lock"; g add -A; g commit -qm "good lock again" +out=$(G6Q) +check "G6 valid locked source: PASS" '[ "$(g6_item trusted_capability_root_present)" = PASS ]' +check "G6 valid: receipt records the full lock, its tree and the blob read" '[ "$(jq -r .g6_lock_source.aienos_lock "$R")" = "$GOODLOCK" ] && [ "$(jq -r .g6_lock_source.commit_tree "$R")" = "$(git -C "$LK" rev-parse "$GOODLOCK^{tree}")" ] && [ "$(jq -r "[.g6_items[] | select(.item==\"trusted_capability_root_present\") | .implementation[] | select(.source==\"aienos_lock_commit\") | .blob] | unique | .[0]" "$R")" = "$(git -C "$LK" rev-parse "$GOODLOCK:native/capability/aienos_capability.c")" ]' +out=$(Q R16_RUN_ID=g6 AIENOS_CAP_LIB=/tmp/prebuilt.a 2>&1); rc=$? +check "prebuilt AIENOS_CAP_LIB override refused (exit 2)" '[ $rc = 2 ] && echo "$out" | grep -q "no source proof"' + # receipt is valid JSON; each item says plainly what its mapping is (no shared boilerplate) check "G6 receipt is valid JSON (jq)" 'jq -e . "$R" >/dev/null' check "G6 receipt: twelve items, twelve different basis texts" '[ "$(jq "[.g6_items[].basis] | unique | length" "$R")" = 12 ] && [ "$(jq ".g6_items | length" "$R")" = 12 ]' diff --git a/tools/.crumb b/tools/.crumb index 6e99b44b8..15504fa2f 100644 --- a/tools/.crumb +++ b/tools/.crumb @@ -56,14 +56,14 @@ } ], "children_root": "sha256:3f9857a8b0946837f5556bcea0b4deaddd3a5aa3a60a31aa08ac917ac69d19f9", - "compiled_at": "2026-10-05T15:03:46Z", + "compiled_at": "2026-10-05T15:28:49Z", "compiler": "crumb-compile/1", - "digest": "sha256:5844e06455eea3780afb1dd3b3351ace41e1648a721491c692783c057fd2479d", + "digest": "sha256:546da8393e444a620edd23486a7a66b483539dd10a4c273e4bd41deacb2d218d", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 132, - "generated_at_commit": "ec3659fd8cda2fc4b16dbd4e729dae172ccdae6a", - "source_tree": "sha256:af007b489c00d3ca31e9389fa6b8fc2e66853381f6a676ca17212ffea46728df" + "files": 133, + "generated_at_commit": "50d535b45ee24fa8bec28ac3248be7209b6a07b0", + "source_tree": "sha256:bb5621de70ca077dc05c32d77923be3d1d42ee37cb200e3dbcfadf634752dc12" }, "owner_lane": "", "provenance": { diff --git a/tools/aienos_lock_source.sh b/tools/aienos_lock_source.sh new file mode 100755 index 000000000..d5a1e207d --- /dev/null +++ b/tools/aienos_lock_source.sh @@ -0,0 +1,152 @@ +#!/bin/bash +# aienos_lock_source.sh -- resolve and prove the aienos source pinned by aienos.lock. +# +# The trusted capability root is the native C library at the FULL commit in aienos.lock +# (spec C3). A directory name, an abbreviated SHA or an environment override is not proof +# of that identity. This tool proves it from git objects: +# * the lock must be one full 40-hex commit id; +# * a repository counts only if it holds that commit object; replace refs and grafts +# are disabled (GIT_NO_REPLACE_OBJECTS) and every object read is re-hashed, so the +# content returned is the content the commit id names; +# * a directory counts only if every file under the asked subpaths has the raw bytes +# (no filters, no attributes) and mode of the locked commit and no other file (build +# outputs included) sits beside them. +# +# Usage: +# aienos_lock_source.sh identity one JSON object: lock, repo, tree, status +# aienos_lock_source.sh show file content at the locked commit +# aienos_lock_source.sh blob blob id of at the locked commit +# aienos_lock_source.sh verify-dir ... prove holds the locked subpaths +# aienos_lock_source.sh materialize ... extract missing subpaths into +# (only if empty of them), then verify-dir +# Exit status: 0 proven; 1 verified mismatch or verified absence (the locked commit was read +# and the path is missing, or the directory differs); 2 unavailable (no repository holds +# the locked commit, or the lock is malformed). 2 never means "absent". +# +# Environment: +# AIENOS_LOCK_FILE lock file (default /aienos.lock) +# AIENOS_LOCK lock value instead of the file (tests only; must still be full 40-hex) +# AIENOS_LOCK_REPO repository to read objects from (default /../aienos-argus-cap); +# a place to look, not proof: the commit object is the proof +# AIENOS_R7_DIR if it lies inside a git repository, that repository is also tried +set -u +export GIT_NO_REPLACE_OBJECTS=1 GIT_GRAFT_FILE=/nonexistent/aienos-lock-source-grafts +HERE=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) + +die2() { echo "aienos_lock_source: UNAVAILABLE: $*" >&2; exit 2; } +die1() { echo "aienos_lock_source: MISMATCH: $*" >&2; exit 1; } + +LOCK=${AIENOS_LOCK:-$(head -n 1 "${AIENOS_LOCK_FILE:-$HERE/aienos.lock}" 2>/dev/null)} +[[ "$LOCK" =~ ^[0-9a-f]{40}$ ]] || die2 "aienos.lock is not one full 40-hex commit id: '${LOCK}'" + +# rehash : the object's content hashes to its id. +rehash() { + local got + got=$(git -C "$1" cat-file "$2" "$3" 2>/dev/null | git hash-object -t "$2" --stdin 2>/dev/null) || return 1 + [ "$got" = "$3" ] +} + +REPO="" +for cand in "${AIENOS_LOCK_REPO:-$HERE/../aienos-argus-cap}" \ + "$( [ -n "${AIENOS_R7_DIR:-}" ] && [ -d "$AIENOS_R7_DIR" ] && git -C "$AIENOS_R7_DIR" rev-parse --show-toplevel 2>/dev/null)"; do + [ -n "$cand" ] && [ -d "$cand" ] || continue + [ "$(git -C "$cand" rev-parse --verify -q "$LOCK^{commit}" 2>/dev/null)" = "$LOCK" ] || continue + rehash "$cand" commit "$LOCK" || continue + REPO=$(cd "$cand" && pwd); break +done +TREE="" +if [ -n "$REPO" ]; then + TREE=$(git -C "$REPO" rev-parse --verify -q "$LOCK^{tree}") + rehash "$REPO" tree "$TREE" || die2 "tree object $TREE of $LOCK fails its hash in $REPO" +fi +need_repo() { [ -n "$REPO" ] || die2 "no repository holds commit $LOCK (AIENOS_LOCK_REPO=${AIENOS_LOCK_REPO:-unset})"; } + +# check_trees : every tree object on the way to and under re-hashes. +check_trees() { + local mode type id path + while read -r mode type id path; do + [ "$type" = tree ] || continue + rehash "$REPO" tree "$id" || die2 "tree $id ($path) fails its hash" + done < <(git -C "$REPO" ls-tree -r -t "$LOCK" -- "$1") +} + +cmd=${1:-}; shift || true +case "$cmd" in +identity) + if [ -n "$REPO" ]; then + printf '{"aienos_lock": "%s", "source": "git-object", "repo": "%s", "commit_tree": "%s", "status": "available"}\n' "$LOCK" "$REPO" "$TREE" + else + printf '{"aienos_lock": "%s", "source": "none", "repo": "", "commit_tree": "", "status": "unavailable"}\n' "$LOCK" + exit 2 + fi ;; +blob|show) + [ $# = 1 ] || die2 "usage: $cmd " + need_repo + check_trees "$1" + id=$(git -C "$REPO" rev-parse --verify -q "$LOCK:$1") || die1 "$1 is absent at $LOCK" + [ "$(git -C "$REPO" cat-file -t "$id")" = blob ] || die1 "$1 is not a file at $LOCK" + rehash "$REPO" blob "$id" || die2 "blob $id ($1) fails its hash" + if [ "$cmd" = blob ]; then echo "$id"; else git -C "$REPO" cat-file blob "$id"; fi ;; +verify-dir|materialize) + [ $# -ge 2 ] || die2 "usage: $cmd ..." + dir=$1; shift + need_repo + for s in "$@"; do + git -C "$REPO" rev-parse --verify -q "$LOCK:$s" >/dev/null || die1 "$s is absent at $LOCK" + check_trees "$s" + done + if [ "$cmd" = materialize ]; then + missing=() + for s in "$@"; do [ -e "$dir/$s" ] || missing+=("$s"); done + if [ ${#missing[@]} -gt 0 ]; then + mkdir -p "$dir" || die2 "cannot create $dir" + git -C "$REPO" archive "$LOCK" "${missing[@]}" | tar -x -C "$dir" || die2 "extraction into $dir failed" + fi + fi + [ -d "$dir" ] || die1 "$dir does not exist" + dir=$(cd "$dir" && pwd) + # Compare raw bytes, outside git's checkout machinery: no index, no ignore rules, + # no .gitattributes (a planted "* text eol=lf" would hide CRLF edits), no config + # filters. Each file is hashed with --no-filters and must equal the locked blob; + # its type and executable bit must equal the locked mode; and the subpaths must + # hold no other file (build outputs included: the authority is built out of tree). + tmpd=$(mktemp -d "${TMPDIR:-/tmp}/aienos-lock-vd.XXXXXX") || die2 "mktemp failed" + trap 'rm -rf "$tmpd"' EXIT + git -C "$REPO" ls-tree -r -z --full-tree "$LOCK" -- "$@" > "$tmpd/tree" || die2 "ls-tree $LOCK failed" + : > "$tmpd/want"; : > "$tmpd/regular"; : > "$tmpd/regular.ids"; bad="" + while IFS= read -r -d '' ent; do + meta=${ent%%$'\t'*}; path=${ent#*$'\t'} + read -r mode type id <<< "$meta" + case "$path" in *$'\n'*) die2 "path with a newline at $LOCK: refusing" ;; esac + printf '%s\n' "$path" >> "$tmpd/want" + f=$dir/$path + case "$mode" in + 120000) + if [ -L "$f" ] && [ "$(readlink "$f" | tr -d '\n' | git -C "$REPO" hash-object --no-filters --stdin)" = "$id" ]; then : + else bad+="$path(symlink) "; fi ;; + 100644|100755) + if [ -L "$f" ] || [ ! -f "$f" ]; then bad+="$path(not a file) "; continue; fi + if [ "$mode" = 100755 ] && [ ! -x "$f" ]; then bad+="$path(mode) "; continue; fi + if [ "$mode" = 100644 ] && [ -x "$f" ]; then bad+="$path(mode) "; continue; fi + printf '%s\n' "$f" >> "$tmpd/regular"; printf '%s\n' "$id" >> "$tmpd/regular.ids" ;; + *) die2 "$path has unsupported mode $mode ($type) at $LOCK" ;; + esac + done < "$tmpd/tree" + [ -s "$tmpd/want" ] || die1 "no files under $* at $LOCK" + if [ -s "$tmpd/regular" ]; then + git -C "$REPO" hash-object --no-filters --stdin-paths < "$tmpd/regular" > "$tmpd/regular.got" 2>/dev/null \ + || die1 "cannot hash the files under $dir" + bad+=$(paste -d ' ' "$tmpd/regular.ids" "$tmpd/regular.got" "$tmpd/regular" \ + | awk -v d="$dir/" '$1 != $2 { p = substr($0, length($1) + length($2) + 3); sub("^" d, "", p); printf "%s(content) ", p }') + fi + [ -z "$bad" ] || die1 "$dir differs from $LOCK: $(echo "$bad" | cut -c1-300)" + # Every non-directory entry under the subpaths must be a locked path. + (cd "$dir" && find "$@" ! -type d -print0) > "$tmpd/have0" 2>/dev/null || die1 "cannot list every entry under $dir (unreadable directory?)" + tr '\0' '\n' < "$tmpd/have0" | sort > "$tmpd/have" + sort -o "$tmpd/want" "$tmpd/want" + extra=$(comm -13 "$tmpd/want" "$tmpd/have") + [ -z "$extra" ] || die1 "$dir has files not in $LOCK (build outputs included; build out of tree): $(echo "$extra" | head -5 | tr '\n' ' ')" + echo "aienos_lock_source: $dir matches $LOCK for $*" >&2 ;; +*) + die2 "unknown command '$cmd' (identity | show | blob | verify-dir | materialize)" ;; +esac diff --git a/tools/c4_requal_mutants.sh b/tools/c4_requal_mutants.sh index 5a83c4474..0a9414b77 100755 --- a/tools/c4_requal_mutants.sh +++ b/tools/c4_requal_mutants.sh @@ -12,8 +12,13 @@ set -u root=$(git rev-parse --show-toplevel) out=${1:-"$root/build/c4_mutants.json"} -auth=$(ls -d "$root"/build/aienos-authority/*/ 2>/dev/null | head -n 1) -[ -n "$auth" ] || { echo "run 'make test-c4-requal' first (builds the authority library)" >&2; exit 2; } +# The authority cache for the FULL aienos.lock commit, proven to hold that commit's +# native/capability (tools/aienos_lock_source.sh); never "the first directory found". +lock=$(head -n 1 "$root/aienos.lock") +auth="$root/build/aienos-authority/$lock" +[ -d "$auth" ] || { echo "run 'make test-c4-requal' first (builds the authority library for $lock)" >&2; exit 2; } +AIENOS_R7_DIR= bash "$root/tools/aienos_lock_source.sh" verify-dir "$auth" native/capability || { + echo "build/aienos-authority/$lock is not the aienos.lock source; delete it and rebuild" >&2; exit 2; } phys=${PHYSICS_DIR:-$(cd "$root/../physics" && pwd)} # M03 retired: cx_open is the single integrity seam; rx_compose no longer re-walks the chain. @@ -39,8 +44,9 @@ M16~src/runtime/rx_compose.c~s/if (pp \&\& state_ref_promoted(s, pp\[CX_WREC_FIE M17~src/runtime/rx_compose.c~s/if (c->cx.n < cnt || (cnt > 0 && (!head || memcmp(head->digest, an + 8, 32) != 0))) {/(void)head; if (0) {/~refuse a Cortex journal cut behind the checkpoint anchor ' # Same copy list as before: the source dirs plus the one authority library. -copy="src tests tools Makefile mk aienos.lock physics.lock build/aienos-authority/$(basename "$auth")" -build="nice -n 10 make PHYSICS_DIR=\"$phys\" ${MAKE_ARGS:-} c4-requal-bin" +copy="src tests tools Makefile mk aienos.lock physics.lock build/aienos-authority/$lock build/aienos-cap/$lock" +lockrepo=$(AIENOS_R7_DIR= bash "$root/tools/aienos_lock_source.sh" identity | sed -n 's/.*"repo": "\([^"]*\)".*/\1/p') +build="nice -n 10 make PHYSICS_DIR=\"$phys\" AIENOS_LOCK_REPO=\"$lockrepo\" ${MAKE_ARGS:-} c4-requal-bin" test_cmd='./build/rx_c4_requal "$PWD/r.json"' # The runner prints the per-mutant lines on stderr as before. -e keeps the old diff --git a/tools/r16_qualify.sh b/tools/r16_qualify.sh index 93d2e503a..ab73dbff1 100755 --- a/tools/r16_qualify.sh +++ b/tools/r16_qualify.sh @@ -49,6 +49,9 @@ if [ -n "${R16_EXPECT_COMMIT:-}" ] && [ "$R16_EXPECT_COMMIT" != "$CANDIDATE_COMM refuse "HEAD $CANDIDATE_COMMIT is not the expected candidate $R16_EXPECT_COMMIT" fi export OMEGA_CANDIDATE_COMMIT="$CANDIDATE_COMMIT" +for v in AIENOS_CAP_LIB VISOR_AUTH_CAP_LIB EFFECT_CAP64_CAP_LIB; do + [ -z "${!v:-}" ] || refuse "$v is set: a prebuilt authority library has no source proof; build it from aienos.lock (AIENOS_LOCK_REPO / AIENOS_R7_DIR)" +done if [ -n "${PHYSICS_DIR:-}" ]; then export PHYSICS_DIR; fi if [ -n "${AIENOS_LOCK_REPO:-}" ]; then export AIENOS_LOCK_REPO; fi @@ -305,21 +308,25 @@ echo " G7=$G7 (R15 acceptance receipt: $R15ACC)" # what the spec itself names or a mapping chosen here (PROXY), and what the tests do not cover. echo "[*] R16-G6: protected things kept..." # g6_defined : f = C function definition line, t = fixed text, -# l = function definition in the tree pinned by aienos.lock (the trusted capability -# root source). Returns 0 defined, 1 absent, 2 cannot look (lock tree unavailable). +# l = function definition in the aienos source at the FULL aienos.lock commit (the trusted +# capability root). Kind l reads immutable blobs through tools/aienos_lock_source.sh: the +# repository must hold the locked commit object, every object read is re-hashed, replace +# refs are off. Files in AIENOS_R7_DIR, a build cache or a directory name are never read +# for it; the repository around AIENOS_R7_DIR may serve objects, which prove themselves. +# Returns 0 defined, 1 absent (the locked commit was read: file or symbol not there), +# 2 cannot look (no repository holds the locked commit, or the lock is malformed). G6_LOCK_COMMIT=$(head -n 1 "$HERE/aienos.lock" 2>/dev/null || true) -g6_lock_source() { # prints the file from the aienos.lock tree, or returns 2 - local rel=$1 d - for d in "${AIENOS_R7_DIR:-}" "$HERE/build/aienos-authority/${G6_LOCK_COMMIT:0:7}"; do - if [ -n "$d" ] && [ -f "$d/$rel" ]; then cat "$d/$rel"; return 0; fi - done - if [ -n "$G6_LOCK_COMMIT" ] && git -C "${AIENOS_LOCK_REPO:-$HERE/../aienos-argus-cap}" show "$G6_LOCK_COMMIT:$rel" 2>/dev/null; then return 0; fi - return 2 -} +g6_lock() { AIENOS_LOCK=$G6_LOCK_COMMIT bash "$HERE/tools/aienos_lock_source.sh" "$@"; } +G6_LOCK_IDENTITY=$(g6_lock identity 2>/dev/null) || true +[ -n "$G6_LOCK_IDENTITY" ] || G6_LOCK_IDENTITY="{\"aienos_lock\": \"$G6_LOCK_COMMIT\", \"source\": \"none\", \"status\": \"malformed_lock\"}" +declare -A G6BLOB g6_defined() { local re="^[A-Za-z_][^;]*[ *]$2\\([^;]*\$" if [ "$3" = l ]; then - local src; src=$(g6_lock_source "$1") || return 2 + local src rc + src=$(g6_lock show "$1" 2>/dev/null); rc=$? + [ "$rc" = 0 ] || return "$rc" + G6BLOB[$1]=$(g6_lock blob "$1" 2>/dev/null) printf '%s\n' "$src" | grep -Eq -- "$re"; return $? fi [ -f "$HERE/$1" ] || return 1 @@ -346,7 +353,7 @@ g6_test() { G6_ITEMS='known_good_fallback_present|src/omega_accelerator_world.c:omega_world_drain:f;src/omega_accelerator_world.c:omega_world_init:f|M19|Spec lines 182-183 name M19 omega_world_* as the known-good fallback (class C): the spec own mapping, not a proxy. Exercised by test-m19 (silicon, N/N gates). Does not test falling back from the reaction world to the M19 world. recovery_path_present|src/runtime/rx_generation.c:rx_gen_recover:f|R9,R14_host|PROXY: the spec names no single recovery symbol; rx_gen_recover is the generation-store crash recovery chosen here. R9 stops after each persistence step and R14 host recovers; boot or repair recovery outside omega is not covered. deterministic_maintenance_controls_present|src/omega_world_gates.c:run_m19_gates:f;tools/omegatool.c:--run-m19-gates:t|M19|Spec line 182 classes omegatool --run-*-gates as B (deterministic maintenance). PARTIAL: only the M19 runner is exercised (by test-m19); the other --run-*-gates entries are not. -trusted_capability_root_present|src/runtime/rx_native_bind.c:rx_world_init_native:f;native/capability/aienos_capability.c:aienos_cap_validate:l;native/capability/aienos_capability.c:aienos_cap_mint:l|R7,R12_host|Spec C3: the native C library at aienos.lock is the sole authoritative root. Checks that source (lock tree) plus omega binding; NOT_RUN if the lock tree cannot be read. R7 compares native authority with the Linux oracle. +trusted_capability_root_present|src/runtime/rx_native_bind.c:rx_world_init_native:f;native/capability/aienos_capability.c:aienos_cap_validate:l;native/capability/aienos_capability.c:aienos_cap_mint:l|R7,R12_host|Spec C3: the native C library at aienos.lock is the sole authoritative root. Checks that source as immutable blobs of the FULL locked commit (tools/aienos_lock_source.sh; identity in g6_lock_source) plus the omega binding; NOT_RUN if no repository holds the locked commit, MISSING_IMPLEMENTATION if the locked commit was read and lacks a symbol. R7 compares native authority with the Linux oracle. generation_mechanism_present|src/runtime/rx_generation.c:rx_gen_propose:f|R9,R13_host|Map row OM-022 and spec line 659 name rx_generation.c as the protected generation mechanism; rx_gen_propose is the entry chosen here (PROXY for the symbol). R9 barrier and R13 host promote. evidence_present|src/omega_evidence.c:omega_evidence_write_digest:f|R15_receipt,R9|PROXY: the spec names no evidence symbol; omega_evidence_write_digest (content-addressed evidence writer) chosen here. R15 receipt test and R9 evidence blob exercise it indirectly. r9_crash_recovery_passing|src/runtime/rx_generation.c:rx_gen_recover:f|R9|PROXY: R9 exercises rx_gen_recover (same routine as recovery_path_present, not independent). PASS means the R9 barrier test passed in this run. @@ -368,7 +375,9 @@ while IFS='|' read -r key pairs tests basis; do if [ "$dr" = 0 ]; then d=true elif [ "$dr" = 2 ]; then d='"unreadable"'; if [ "$present" = true ]; then present=unknown; fi else d=false; present=false; fi - implj="$implj{\"file\": \"$pf\", \"symbol\": \"$sym\", \"defined\": $d}, " + src_kind=omega_tree; blobj="" + if [ "$kind" = l ]; then src_kind=aienos_lock_commit; blobj=", \"blob\": \"${G6BLOB[$pf]:-}\""; fi + implj="$implj{\"file\": \"$pf\", \"symbol\": \"$sym\", \"source\": \"$src_kind\", \"defined\": $d$blobj}, " done implj=${implj%, } tj=""; ts=PASS; IFS=',' read -ra TA <<< "$tests" @@ -468,6 +477,7 @@ cat > "$OUT_RECEIPT_TMP" <