interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / om / site / verify-omc.sh

63 lines · 3631 bytes Raw Blame History
1#!/bin/sh
2# verify-omc.sh -- refuse the vendored Omega compiler unless omega-mv vouches for it.
3#
4# A digest committed next to the binary proves nothing: one PR can change both.
5# The trust anchor is omega-mv instead. The lock (om/site/omc.provenance) names
6# a fixed omega-mv revision; this script fetches omega-mv fresh and requires
7# 1. the revision is an ancestor of omega-mv main (it landed through review),
8# 2. seed/out/omc.sha256 at that revision names the locked digest,
9# 3. seed/out/omc at that revision is byte-identical to the vendored binary,
10# 4. seed/omega-from-seed.sh at that revision rebuilds omc from the
11# hand-written seed hex and the result is byte-identical too.
12# Moving to a newer compiler is a visible diff of the lock, never silent.
13# Runs on Linux AArch64 only (the seed chain emits AArch64 executables); any
14# other host fails, it does not skip.
15#
16# Usage: sh om/site/verify-omc.sh [vendored-omc [lock]]
17# Prints OMC-PIN PASS and exits 0, or OMC-PIN FAIL <reason> and exits 1.
18set -eu
19REPO=https://interplane.io/drakestapleton/omega-mv
20OMC=${1:-om/site/omc}
21LOCK=${2:-om/site/omc.provenance}
22
23fail() { printf 'OMC-PIN FAIL %s\n' "$*"; exit 1; }
24field() { sed -n "s/^$1 //p" "$LOCK"; }
25
26[ -f "$OMC" ] || fail "no vendored compiler at $OMC"
27[ -f "$LOCK" ] || fail "no lock at $LOCK"
28[ "$(uname -s) $(uname -m)" = "Linux aarch64" ] || fail "host $(uname -s) $(uname -m) cannot run the seed chain; need Linux aarch64"
29
30repo=$(field repository)
31rev=$(field revision)
32path=$(field path)
33want=$(field sha256)
34[ "$repo" = "$REPO" ] || fail "lock repository '$repo' is not $REPO"
35printf '%s\n' "$rev" | grep -Eq '^[0-9a-f]{40}$' || fail "lock revision '$rev' is not a full commit sha"
36printf '%s\n' "$want" | grep -Eq '^[0-9a-f]{64}$' || fail "lock sha256 '$want' is not a sha256"
37[ "$path" = "seed/out/omc" ] || fail "lock path '$path' is not seed/out/omc"
38
39have=$(sha256sum "$OMC" | cut -d' ' -f1)
40[ "$have" = "$want" ] || fail "vendored $OMC is $have, lock says $want"
41
42W=$(mktemp -d)
43trap 'rm -rf "$W"' EXIT
44git -C "$W" init -q
45git -C "$W" fetch -q --filter=blob:none "$REPO" main "$rev" || fail "cannot fetch $REPO main and $rev"
46main=$(git -C "$W" ls-remote "$REPO" refs/heads/main | awk -F"\t" '$2 == "refs/heads/main" {print $1}')
47[ -n "$main" ] || fail "cannot read $REPO main"
48git -C "$W" cat-file -e "$main^{commit}" || fail "fetched main $main is missing"
49git -C "$W" merge-base --is-ancestor "$rev" "$main" || fail "$rev is not on $REPO main ($main)"
50printf 'omc-pin: %s is an ancestor of omega-mv main %s\n' "$rev" "$main"
51
52recorded=$(git -C "$W" show "$rev:seed/out/omc.sha256" | cut -d' ' -f1) || fail "no seed/out/omc.sha256 at $rev"
53[ "$recorded" = "$want" ] || fail "omega-mv $rev records $recorded, lock says $want"
54git -C "$W" show "$rev:seed/out/omc" > "$W/omc.committed" || fail "no seed/out/omc at $rev"
55cmp -s "$W/omc.committed" "$OMC" || fail "vendored $OMC differs from seed/out/omc at $rev"
56printf 'omc-pin: vendored binary equals seed/out/omc at %s (%s)\n' "$rev" "$want"
57
58git -C "$W" -c advice.detachedHead=false checkout -q "$rev" || fail "cannot check out $rev"
59sh "$W/seed/omega-from-seed.sh" > "$W/birth.log" 2>&1 || { cat "$W/birth.log"; fail "seed rebuild failed at $rev"; }
60grep -q '^RC=0$' "$W/birth.log" || { cat "$W/birth.log"; fail "seed rebuild did not report RC=0"; }
61cmp -s "$W/seed/out/omc" "$OMC" || fail "seed rebuild at $rev is $(sha256sum "$W/seed/out/omc" | cut -d' ' -f1), not the vendored binary"
62printf 'omc-pin: seed/omega-from-seed.sh at %s rebuilt the same %s bytes\n' "$rev" "$(wc -c < "$OMC")"
63printf 'OMC-PIN PASS %s %s\n' "$rev" "$want"