interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / calibration / scripts / freeze_receipt.sh

116 lines · 6164 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# 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.
36set -euo pipefail
37here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
38repo="$(git -C "$here" rev-parse --show-toplevel)"
39. "$here/tc_exp.sh"
40cf="${1:-}"
41shift || true
42fetch=1 out="$repo/$EXP_DIR/freeze_receipt.json"
43while [ $# -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
49done
50die() { echo "freeze_receipt: REFUSED: $*" >&2; exit 2; }
51M=$EXP_DIR/candidate_manifest.json
52P=$EXP_PROFILE
53S=$EXP_SIDECAR
54at() { git -C "$repo" show "$cf:$1"; }
55
56[[ "$cf" =~ ^[0-9a-f]{40}$ ]] || die "C_f must be a full 40-hex commit id"
57git -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
59om="$(git -C "$repo" rev-parse --verify -q 'origin/main^{commit}')" || die "no origin/main"
60git -C "$repo" merge-base --is-ancestor "$cf" "$om" || die "check 1: $cf is not an ancestor of origin/main ($om)"
61
62man="$(at "$M")" || die "check 2: $M missing at C_f"
63grep -q '^ "status": "frozen",' <<<"$man" || die "check 2: manifest at C_f is not frozen"
64pre="$(at $EXP_DIR/preregistration.json)" || die "check 2: preregistration.json missing at C_f"
65grep -q "^ \"status\": \"frozen\"," <<<"$pre" || die "check 2: preregistration.json at C_f is not status frozen"
66jv() { sed -n "s/^ *\"$1\": \"\([^\"]*\)\".*/\1/p" <<<"$man" | head -1; }
67
68prof="$(at "$P")" || die "check 3: profile missing at C_f"
69grep -q FILL_AT_FREEZE <<<"$prof" && die "check 3: profile at C_f still holds FILL_AT_FREEZE"
70ph="$(at "$P" | sha256sum | cut -c1-64)"
71sh_="$(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
75prd="$(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
79tmp="$(mktemp -d)"
80trap 'rm -rf "$tmp"' EXIT
81git -C "$repo" archive "$cf" calibration/scripts/indep_source_digest.sh tools/turing_verify_indep | tar -x -C "$tmp"
82idg="$(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
85nbg=0
86while 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))
91done < <(sed -n '/"shared_background_sha256": {/,/}/s/^ *"\([^"]*\)": "\([^"]*\)",\{0,1\}$/\1 \2/p' <<<"$man")
92[ "$nbg" -gt 0 ] || die "check 6: no shared background entries"
93
94sealed="${TC_SEALED_ROOT:-$HOME/aien-data/turing-cal/sealed}"
95for x in "$sealed/$cf" "$sealed/$cf".*; do [ -e "$x" ] && die "check 7: sealed data for $cf already exists ($x)"; done
96
97ct="$(git -C "$repo" show -s --format=%ct "$cf")"
98[ ! -e "$out" ] || die "$out already exists (one receipt per freeze)"
99cat >"$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}
115EOF
116echo "freeze_receipt: TURING_PROFILE_V1_FROZEN = PASS for $cf -> $out"