Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/calibration/scripts/test_blinding.sh # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / calibration / scripts / test_blinding.sh` 203 lines ยท 12499 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # SPDX-License-Identifier: Apache-2.0 3 # Copyright 2026 Drake Stapleton (AIEN / aien-dev) 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # Turing calibration (CAL-0 / EXP-001, EXP-001R): blinding self-test (make test-turing-cal-blinding). 18 # 19 # Plants a random canary file inside the REAL sealed root, then checks, through 20 # the real wrappers: 21 # candidate jail: cannot read the canary, cannot list the sealed root, cannot 22 # find the canary by name anywhere, cannot reach it through /proc/*/root, 23 # cannot create a user namespace or mount, has no network; CAN read dev data 24 # and CAN write its working directory; 25 # candidate wrapper: refuses to bind a directory that contains the sealed root; 26 # evaluator jail: CAN read the canary, cannot write the frozen tree, CAN write 27 # its output directory, has no network. 28 # Then the overlap audit self-tests on synthetic planted ledgers (amended G6, burned EXP-001 seeds). 29 # The canary is removed on exit. Exit 0 = all checks pass. 30 set -uo pipefail 31 here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 32 # shellcheck source=tc_jail_lib.sh 33 . "$here/tc_jail_lib.sh" 34 C="$here/candidate_env.sh" 35 V="$here/evaluator_env.sh" 36 dev="${TC_TEST_DEV:-$HOME/aien-data/crumbline}" 37 devfile="$(find "$dev" -name trace.ctr -type f | head -1)" 38 [ -n "$devfile" ] || { echo "no development trace.ctr under $dev" >&2; exit 2; } 39 40 pass=0 fail=0 41 ok() { echo "PASS $*"; pass=$((pass + 1)); } 42 bad() { echo "FAIL $*"; fail=$((fail + 1)); } 43 expect_fail() { local what="$1"; shift; if "$@" >/dev/null 2>&1; then bad "$what (succeeded)"; else ok "$what"; fi; } 44 expect_ok() { local what="$1"; shift; if "$@" >/dev/null 2>&1; then ok "$what"; else bad "$what (failed)"; fi; } 45 46 created_root=0 47 [ -d "$TC_SEALED_ROOT" ] || { mkdir -p "$TC_SEALED_ROOT" && chmod 0700 "$TC_SEALED_ROOT" && created_root=1; } 48 tag="blinding-canary-$(od -An -N8 -tx1 /dev/urandom | tr -d ' \n')" 49 canary_dir="$TC_SEALED_ROOT/.$tag" 50 mkdir -m 0700 "$canary_dir" 51 secret="$(od -An -N16 -tx1 /dev/urandom | tr -d ' \n')" 52 printf '%s\n' "$secret" >"$canary_dir/$tag.bin" 53 scratch="$(mktemp -d)" 54 frozen="$scratch/frozen" 55 evout="$scratch/eval-out" 56 work="$scratch/candidate-work" 57 mkdir -p "$frozen" "$work" 58 echo frozen >"$frozen/artifact" 59 cleanup() { 60 rm -rf "$canary_dir" "$scratch" 61 [ "$created_root" = 1 ] && rmdir "$TC_SEALED_ROOT" 2>/dev/null 62 true 63 } 64 trap cleanup EXIT 65 66 cand() { "$C" --workdir "$work" --dev "$dev" -- "$@"; } 67 eval_() { "$V" --frozen "$frozen" --sealed "$canary_dir" --out "$evout" -- "$@"; } 68 69 echo "== candidate environment" 70 expect_fail "candidate cannot read the canary" cand cat "$canary_dir/$tag.bin" 71 expect_fail "candidate cannot list the sealed root" cand ls "$TC_SEALED_ROOT" 72 out="$(cand sh -c "find / -name '*$tag*' 2>/dev/null" || true)" 73 [ -z "$out" ] && ok "candidate finds no canary by name anywhere" || bad "candidate found: $out" 74 out="$(cand sh -c "cat /proc/*/root$canary_dir/$tag.bin 2>/dev/null" || true)" 75 [ "$out" != "$secret" ] && ok "candidate cannot reach the canary via /proc/*/root" || bad "canary via /proc" 76 expect_fail "candidate cannot create a user namespace" cand unshare --user --map-root-user true 77 expect_fail "candidate cannot mount" cand mount -t tmpfs none /tmp 78 expect_fail "candidate has no network" cand bash -c 'exec 3<>/dev/tcp/1.1.1.1/53' 79 expect_ok "candidate can read development data" cand head -c 247 "$devfile" 80 expect_ok "candidate can write its working directory" cand sh -c "echo x > '$work/probe'" 81 expect_fail "candidate wrapper refuses a bind containing the sealed root" \ 82 "$C" --workdir "$work" --dev "$(dirname "$TC_SEALED_ROOT")" -- true 83 84 echo "== evaluator environment" 85 out="$(eval_ cat "$canary_dir/$tag.bin" 2>/dev/null || true)" 86 [ "$out" = "$secret" ] && ok "evaluator can read sealed data" || bad "evaluator cannot read sealed data" 87 expect_fail "evaluator cannot modify the frozen tree" eval_ sh -c "echo y > '$frozen/artifact'" 88 expect_fail "evaluator cannot write sealed data" eval_ sh -c "echo y > '$canary_dir/new'" 89 expect_ok "evaluator can write its output directory" eval_ sh -c "echo z > '$evout/result'" 90 expect_fail "evaluator has no network" eval_ bash -c 'exec 3<>/dev/tcp/1.1.1.1/53' 91 expect_fail "evaluator cannot see development data" eval_ head -c 1 "$devfile" 92 expect_fail "evaluator wrapper refuses --out inside the frozen tree" \ 93 "$V" --frozen "$frozen" --sealed "$canary_dir" --out "$frozen/o" -- true 94 95 96 echo "== overlap audit, amended G6 (synthetic planted ledgers; no real sealed data is read)" 97 V6="$here/verify_holdout_separation.sh" 98 G="$here/generate_sealed_data.sh" 99 ovroot="$scratch/ov" 100 mkdir -p "$ovroot" 101 hx() { printf '%s' "$1" | sha256sum | cut -d' ' -f1; } 102 ov_repo="$ovroot/repo" 103 mkdir -p "$ov_repo/calibration/experiments/EXP-001" "$ov_repo/calibration/experiments/EXP-001R" 104 for e in EXP-001 EXP-001R; do printf '{\n "status": "frozen",\n}\n' >"$ov_repo/calibration/experiments/$e/candidate_manifest.json"; done 105 git -C "$ov_repo" init -q 2>/dev/null 106 git -C "$ov_repo" -c user.name=t -c user.email=t@t add calibration 107 git -C "$ov_repo" -c user.name=t -c user.email=t@t commit -q -m synthetic 108 ov_commit="$(git -C "$ov_repo" rev-parse HEAD)" 109 ov_digest="$(hx digest)" 110 ov_seed() { local h; h="$(printf '%s' "turing.cal.sealed.v1|$ov_commit|$ov_digest|g$1|$2" | sha256sum | cut -c1-16)" 111 printf '%d\n' "$((16#$(printf '%x' $((16#${h:0:1} & 7)))${h:1}))"; } 112 sleep 1 113 # ledger line: population crumb sealed stream 114 ll() { printf '{"population":"%s","crumb_digest":"%s","sealed_digest":"%s","trace_stream_digest":"%s"}\n' "$1" "$2" "$3" "$4"; } 115 # mk_side DIR LEDGERLINE... : DIR/control/{trace.ctr (empty CTR1), ledger.jsonl} 116 mk_side() { local d="$1"; shift; mkdir -p "$d/control"; : >"$d/control/trace.ctr"; printf '%s\n' "$@" >"$d/control/ledger.jsonl"; } 117 # scenario NAME EXPID DEV_POP DEV_SEALED SEALED_POP SEALED_SEALED WHERE(dev|burned) -> runs the audit, sets ov_rc, ov_out 118 scenario() { 119 local name="$1" expid="$2" dpop="$3" dsd="$4" spop="$5" ssd="$6" where="$7" d="$ovroot/$1" 120 local x; x="$(hx "crumb-$name")" 121 rm -rf "$d"; mkdir -p "$d" 122 mk_side "$d/dev/a" "$(ll Fundamental "$(hx other-dev-$name)" "$(hx dv-$name)" "$(hx ds-$name)")" 123 mk_side "$d/burned/a" "$(ll Fundamental "$(hx other-burned-$name)" "$(hx bv-$name)" "$(hx bs-$name)")" 124 if [ "$where" = dev ]; then 125 mk_side "$d/dev/b" "$(ll "$dpop" "$x" "$(hx "$dsd")" "$(hx dstream-$name)")" 126 else 127 mk_side "$d/burned/b" "$(ll "$dpop" "$x" "$(hx "$dsd")" "$(hx bstream-$name)")" 128 fi 129 find "$d/dev" -name trace.ctr | LC_ALL=C sort >"$d/dev.txt" 130 local s1 s2; s1="$(ov_seed 1 0)"; s2="$(ov_seed 2 0)" 131 mk_side "$d/sealed/group-1/seed-$s1" "$(ll Fundamental "$(hx s1-$name)" "$(hx sv1-$name)" "$(hx ss1-$name)")" 132 mk_side "$d/sealed/group-2/seed-$s2" "$(ll "$spop" "$x" "$(hx "$ssd")" "$(hx sstream-$name)")" 133 { 134 printf '{\n "freeze_commit": "%s",\n "profile_digest": "%s",\n "seeds": [\n' "$ov_commit" "$ov_digest" 135 printf ' {"group": 1, "index": 0, "seed": %s},\n {"group": 2, "index": 0, "seed": %s}\n ]\n}\n' "$s1" "$s2" 136 } >"$d/sealed/seed_commitment.json" 137 { 138 echo '{"files": [' 139 n=0 140 for t in "$d/sealed/group-1/seed-$s1/control/trace.ctr" "$d/sealed/group-2/seed-$s2/control/trace.ctr"; do 141 [ "$n" = 0 ] || echo "," 142 printf ' {"path": "%s", "sha256": "%s", "bytes": 0, "records": 0, "kept": true}' "${t#"$d/sealed/"}" "$(sha256sum "$t" | cut -d' ' -f1)" 143 n=$((n + 1)) 144 done 145 echo; echo ']}' 146 } >"$d/sealed/manifest.json" 147 sha256sum "$d/sealed/seed_commitment.json" | cut -d' ' -f1 >"$d/sealed/COMPLETE" 148 ov_out="$d/overlap_audit.json" 149 EXP_ID="$expid" TC_EXP001_SEALED="$d/burned" "$V6" --sealed-dir "$d/sealed" --out "$ov_out" \ 150 --dev-list "$d/dev.txt" --repo "$ov_repo" >"$d/audit.log" 2>&1 151 ov_rc=$? 152 } 153 g6line() { grep '"crumb_digest": {' "$ov_out"; } 154 155 scenario i-dev EXP-001R Ambiguous hidden-dev Ambiguous hidden-sealed dev 156 [ "$ov_rc" = 0 ] && grep -q '"result": "PASS"' "$ov_out" && g6line | grep -q '"pass": true, "detail": "1 shared, 1 exempt (Ambiguous, different hidden set)"' \ 157 && [ "$(grep -c '"population": "Ambiguous", "sealed_digest"' "$ov_out")" = 1 ] \ 158 && ok "(i) Ambiguous visible-only match, different sealed_digest: audit PASS, 1 exempt, listed with both sealed_digests" \ 159 || bad "(i) Ambiguous different-hidden match should PASS with 1 exempt (rc $ov_rc: $(tail -2 "$ovroot/i-dev/audit.log" | tr '\n' ' '))" 160 scenario i-burned EXP-001R Ambiguous hidden-dev Ambiguous hidden-sealed burned 161 [ "$ov_rc" = 0 ] && g6line | grep -q '1 shared, 1 exempt' \ 162 && ok "(i-b) same match against a burned EXP-001 sealed trace: PASS, 1 exempt" \ 163 || bad "(i-b) burned-side Ambiguous different-hidden match should PASS (rc $ov_rc)" 164 scenario ii EXP-001R Ambiguous same-hidden Ambiguous same-hidden dev 165 [ "$ov_rc" = 1 ] && g6line | grep -q '"pass": false' && grep -q '"result": "FAIL"' "$ov_out" \ 166 && ok "(ii) Ambiguous match with the same sealed_digest: audit FAIL at G6" \ 167 || bad "(ii) same-hidden Ambiguous match should FAIL (rc $ov_rc)" 168 scenario iii EXP-001R Fundamental hidden-dev Fundamental hidden-sealed dev 169 [ "$ov_rc" = 1 ] && g6line | grep -q '"pass": false, "detail": "1 shared, 0 exempt' \ 170 && ok "(iii) non-Ambiguous crumb_digest match, different sealed_digest: audit FAIL at G6" \ 171 || bad "(iii) non-Ambiguous match should FAIL (rc $ov_rc)" 172 scenario iii-mixed EXP-001R Ambiguous hidden-dev Fundamental hidden-sealed dev 173 [ "$ov_rc" = 1 ] && g6line | grep -q '"pass": false' \ 174 && ok "(iii-b) sealed population not Ambiguous (dev side Ambiguous): audit FAIL at G6" \ 175 || bad "(iii-b) sealed non-Ambiguous should FAIL (rc $ov_rc)" 176 scenario strict EXP-001 Ambiguous hidden-dev Ambiguous hidden-sealed dev 177 [ "$ov_rc" = 1 ] && g6line | grep -q '"pass": false, "detail": "1 shared"' \ 178 && ok "EXP-001 keeps the original strict G6 (same planted match FAILs)" \ 179 || bad "EXP-001 strict G6 should FAIL the Ambiguous match (rc $ov_rc)" 180 nb=0 181 while read -r s; do 182 [ -n "$s" ] || continue 183 nb=$((nb + 1)) 184 EXP_ID=EXP-001R "$G" --is-burned "$s" >/dev/null 2>&1 || bad "(iv) burned EXP-001 seed $nb not refused by generate_sealed_data.sh (EXP-001R)" 185 done <"$here/burned_seeds_exp001.txt" 186 [ "$nb" = 6 ] && ok "(iv) all 6 burned EXP-001 sealed seeds are refused by generate_sealed_data.sh (EXP-001R)" || bad "(iv) expected 6 burned seeds, found $nb" 187 if EXP_ID=EXP-001R "$G" --is-burned `12345678901234` >/dev/null 2>&1; then bad "(iv) an unrelated seed was refused"; else ok "(iv) an unrelated seed is not refused"; fi 188 echo "== freeze sealed-root check (synthetic empty directories only)" 189 sr="$scratch/sealed-root"; mkdir -p "$sr" 190 bname=`d3cba292b9282116d1e374db22344bca4d47717e` 191 sealed_ok() { ( EXP_ID="$1" . "$here/tc_exp.sh"; tc_sealed_clear "$sr" >/dev/null ) ; } 192 sealed_ok EXP-001R && sealed_ok EXP-001 && ok "empty sealed root: freeze allowed for both" || bad "empty sealed root refused" 193 mkdir "$sr/$bname" 194 sealed_ok EXP-001R && ok "burned root present: freeze allowed for EXP-001R" || bad "burned root refused for EXP-001R" 195 sealed_ok EXP-001 && bad "burned root present: EXP-001 must refuse" || ok "burned root present: refused for EXP-001 (any entry)" 196 mkdir "$sr/`0123456789abcdef0123456789abcdef01234567`" 197 sealed_ok EXP-001R && bad "extra directory accepted for EXP-001R" || ok "burned root plus an unknown directory: refused for EXP-001R" 198 sealed_ok EXP-001 && bad "extra directory accepted for EXP-001" || ok "unknown directory: refused for EXP-001" 199 rmdir "$sr/`0123456789abcdef0123456789abcdef01234567`"; mkdir "$sr/$bname.failed-1" 200 sealed_ok EXP-001R && bad "burned root .failed-* accepted" || ok "a .failed-* sibling of the burned root is refused for EXP-001R (exact root only)" 201 echo "skipped: dev-vs-dev audit mode (verify_holdout_separation.sh always compares one sealed dir against dev data; no such mode exists)" 202 echo "blinding self-test: $pass passed, $fail failed" 203 [ "$fail" = 0 ]