omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / calibration / scripts / freeze_receipt.sh
| 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 | # freeze_receipt.sh: step 2 of the two-step freeze (BLINDING_PROTOCOL.md section 2). Writes |
| 18 | # calibration/experiments/EXP-001/freeze_receipt.json with TURING_PROFILE_V1_FROZEN = PASS for the freeze |
| 19 | # commit C_f, or refuses (exit 2) and writes nothing. |
| 20 | # |
| 21 | # freeze_receipt.sh C_F [--no-fetch] [--out FILE] |
| 22 | # |
| 23 | # C_f is the commit that added the frozen candidate manifest, profile value and sidecar (step 1). It names no |
| 24 | # commit inside itself; this receipt is the first file that records C_f, and it is committed AFTER C_f (the |
| 25 | # receipt commit changes nothing the seeds or the evaluator depend on). Every check reads C_f through git, never |
| 26 | # the worktree: |
| 27 | # 1 C_f is a full 40-hex commit and an ancestor of origin/main (fetched first unless --no-fetch). C_f must |
| 28 | # reach main by a real merge or a fast-forward; a squash or rebase makes a new commit and C_f is lost. |
| 29 | # 2 candidate_manifest.json and preregistration.json at C_f both have "status": "frozen". |
| 30 | # 3 the profile at C_f holds no FILL_AT_FREEZE; its SHA-256 equals the sidecar and the manifest profile_sha256. |
| 31 | # 4 runtime_digest in the profile at C_f equals runtime_sha256.runtime_digest in the manifest at C_f. |
| 32 | # 5 independent_scorer_source_sha256 in the manifest equals indep_source_digest.sh over C_f's tree. |
| 33 | # 6 every shared_background_sha256 entry equals the SHA-256 of that file at C_f. |
| 34 | # 7 no sealed data exists yet for C_f (sealed/<C_f> and its .failed-* are absent). |
| 35 | # No Python: bash, git, sha256sum, sed. |
| 36 | set -euo pipefail |
| 37 | here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 38 | repo="$(git -C "$here" rev-parse --show-toplevel)" |
| 39 | . "$here/tc_exp.sh" |
| 40 | cf="${1:-}" |
| 41 | shift || true |
| 42 | fetch=1 out="$repo/$EXP_DIR/freeze_receipt.json" |
| 43 | while [ $# -gt 0 ]; do |
| 44 | case "$1" in |
| 45 | --no-fetch) fetch=0; shift ;; |
| 46 | --out) out="$2"; shift 2 ;; |
| 47 | *) echo "freeze_receipt: unknown option '$1'" >&2; exit 2 ;; |
| 48 | esac |
| 49 | done |
| 50 | die() { echo "freeze_receipt: REFUSED: $*" >&2; exit 2; } |
| 51 | M=$EXP_DIR/candidate_manifest.json |
| 52 | P=$EXP_PROFILE |
| 53 | S=$EXP_SIDECAR |
| 54 | at() { git -C "$repo" show "$cf:$1"; } |
| 55 | |
| 56 | [[ "$cf" =~ ^[0-9a-f]{40}$ ]] || die "C_f must be a full 40-hex commit id" |
| 57 | git -C "$repo" cat-file -e "$cf^{commit}" 2>/dev/null || die "commit $cf not found" |
| 58 | [ "$fetch" = 1 ] && git -C "$repo" fetch -q origin main |
| 59 | om="$(git -C "$repo" rev-parse --verify -q 'origin/main^{commit}')" || die "no origin/main" |
| 60 | git -C "$repo" merge-base --is-ancestor "$cf" "$om" || die "check 1: $cf is not an ancestor of origin/main ($om)" |
| 61 | |
| 62 | man="$(at "$M")" || die "check 2: $M missing at C_f" |
| 63 | grep -q '^ "status": "frozen",' <<<"$man" || die "check 2: manifest at C_f is not frozen" |
| 64 | pre="$(at $EXP_DIR/preregistration.json)" || die "check 2: preregistration.json missing at C_f" |
| 65 | grep -q "^ \"status\": \"frozen\"," <<<"$pre" || die "check 2: preregistration.json at C_f is not status frozen" |
| 66 | jv() { sed -n "s/^ *\"$1\": \"\([^\"]*\)\".*/\1/p" <<<"$man" | head -1; } |
| 67 | |
| 68 | prof="$(at "$P")" || die "check 3: profile missing at C_f" |
| 69 | grep -q FILL_AT_FREEZE <<<"$prof" && die "check 3: profile at C_f still holds FILL_AT_FREEZE" |
| 70 | ph="$(at "$P" | sha256sum | cut -c1-64)" |
| 71 | sh_="$(at "$S" | cut -c1-64)" || die "check 3: sidecar missing at C_f" |
| 72 | [ "$ph" = "$sh_" ] || die "check 3: profile SHA-256 $ph != sidecar $sh_" |
| 73 | [ "$ph" = "$(jv profile_sha256)" ] || die "check 3: manifest profile_sha256 differs from the profile at C_f" |
| 74 | |
| 75 | prd="$(sed -n 's/^runtime_digest = "\([0-9a-f]\{64\}\)".*/\1/p' <<<"$prof")" |
| 76 | [ -n "$prd" ] || die "check 4: profile runtime_digest is not a 64-hex value" |
| 77 | [ "$prd" = "$(jv runtime_digest)" ] || die "check 4: profile runtime_digest $prd != manifest $(jv runtime_digest)" |
| 78 | |
| 79 | tmp="$(mktemp -d)" |
| 80 | trap 'rm -rf "$tmp"' EXIT |
| 81 | git -C "$repo" archive "$cf" calibration/scripts/indep_source_digest.sh tools/turing_verify_indep | tar -x -C "$tmp" |
| 82 | idg="$(sh "$tmp/calibration/scripts/indep_source_digest.sh")" |
| 83 | [ "$idg" = "$(jv independent_scorer_source_sha256)" ] || die "check 5: independent scorer source at C_f is $idg, manifest says $(jv independent_scorer_source_sha256)" |
| 84 | |
| 85 | nbg=0 |
| 86 | while read -r rel want; do |
| 87 | got=MISSING |
| 88 | if git -C "$repo" cat-file -e "$cf:$rel" 2>/dev/null; then got="$(at "$rel" | sha256sum | cut -c1-64)"; fi |
| 89 | [ "$got" = "$want" ] || die "check 6: shared background $rel at C_f is $got, manifest says $want" |
| 90 | nbg=$((nbg + 1)) |
| 91 | done < <(sed -n '/"shared_background_sha256": {/,/}/s/^ *"\([^"]*\)": "\([^"]*\)",\{0,1\}$/\1 \2/p' <<<"$man") |
| 92 | [ "$nbg" -gt 0 ] || die "check 6: no shared background entries" |
| 93 | |
| 94 | sealed="${TC_SEALED_ROOT:-$HOME/aien-data/turing-cal/sealed}" |
| 95 | for x in "$sealed/$cf" "$sealed/$cf".*; do [ -e "$x" ] && die "check 7: sealed data for $cf already exists ($x)"; done |
| 96 | |
| 97 | ct="$(git -C "$repo" show -s --format=%ct "$cf")" |
| 98 | [ ! -e "$out" ] || die "$out already exists (one receipt per freeze)" |
| 99 | cat >"$out" <<EOF |
| 100 | { |
| 101 | "schema": "turing.cal.freeze_receipt.v1", |
| 102 | "TURING_PROFILE_V1_FROZEN": "PASS", |
| 103 | "freeze_commit": "$cf", |
| 104 | "freeze_commit_time_utc": "$(date -u -d "@$ct" +%Y-%m-%dT%H:%M:%SZ)", |
| 105 | "origin_main_checked": "$om", |
| 106 | "profile_sha256": "$ph", |
| 107 | "candidate_manifest_sha256": "$(at "$M" | sha256sum | cut -c1-64)", |
| 108 | "runtime_digest": "$prd", |
| 109 | "independent_scorer_source_sha256": "$idg", |
| 110 | "shared_background_entries_checked": $nbg, |
| 111 | "sealed_data_present": false, |
| 112 | "written_utc": "$(date -u +%Y-%m-%dT%H:%M:%SZ)", |
| 113 | "next": "commit this receipt (a later commit than C_f), then generate_sealed_data.sh --commit $cf --profile-digest $ph" |
| 114 | } |
| 115 | EOF |
| 116 | echo "freeze_receipt: TURING_PROFILE_V1_FROZEN = PASS for $cf -> $out" |