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 / research / atemporal / at1 / evaluator / gates / isolation.sh
| 1 | #!/bin/sh |
| 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 | # AT-1 isolation gate (charter section 6, G2; adapted from the AT-0 Agent 4 |
| 18 | # gate). Two independent scans of each compute object or executable: |
| 19 | # 1. symbol scan (nm): no clock, randomness, environment, file, network, |
| 20 | # process, thread or raw-syscall entry point, C or Rust std; |
| 21 | # 2. instruction scan (at1-eval scan-clock): no inline counter read |
| 22 | # (CNTVCT_EL0, CNTPCT_EL0, PMCCNTR_EL0, RDTSC) and no inline system call |
| 23 | # (SVC, SYSCALL), which no symbol table shows. |
| 24 | # Portable POSIX sh: works with GNU nm and the llvm nm of Apple clang. |
| 25 | # sh gates/isolation.sh <at1-eval> <object-or-binary>... judge candidate objects |
| 26 | # sh gates/isolation.sh --controls <at1-eval> [receipt] prove the gate on its controls |
| 27 | # Exit 0 only on PASS. |
| 28 | set -u |
| 29 | FORBIDDEN="clock_gettime clock_getres clock_nanosleep clock gettimeofday time timegm timelocal localtime localtime_r gmtime gmtime_r mktime strftime nanosleep sleep usleep mach_absolute_time mach_continuous_time clock_gettime_nsec_np rand rand_r srand random srandom drand48 lrand48 arc4random arc4random_buf getrandom getentropy getenv secure_getenv setenv putenv fopen fopen64 freopen open open64 openat openat64 creat socket connect accept bind listen send recv sendto recvfrom getaddrinfo gethostbyname dlopen dlsym system popen fork vfork posix_spawn execv execve execvp execl pthread_create thrd_create clone syscall __syscall read write pread pwrite pread64 pwrite64 readv writev fread fwrite fgets fgetc getc getchar getline getdelim fscanf scanf mmap mmap64 ioctl" |
| 30 | |
| 31 | scan_one() { # $1 = at1-eval, $2 = object; prints hits, returns 1 on any |
| 32 | o=$2; bad=0 |
| 33 | if [ ! -f "$o" ]; then echo "FAIL: missing $o"; return 1; fi |
| 34 | t=$(mktemp "${TMPDIR:-/tmp}/at1iso.XXXXXX") || return 1 |
| 35 | { nm -p "$o" 2>/dev/null; nm -D "$o" 2>/dev/null; } > "$t" |
| 36 | if [ ! -s "$t" ] && ! nm "$o" >/dev/null 2>&1; then echo "FAIL: $o: nm cannot read symbols"; rm -f "$t"; return 1; fi |
| 37 | # strip version suffixes and hardened-libc aliases (__fread_chk -> fread, __open_2 -> open) |
| 38 | syms=$(awk 'NF>=2 {print $NF}' "$t" | sed -E 's/@.*$//; s/^_?__([a-z0-9_]+)_chk$/\1/; s/^_?__([a-z0-9_]+)_2$/\1/') |
| 39 | for f in $FORBIDDEN; do |
| 40 | if printf '%s\n' "$syms" | grep -qx "_\{0,1\}$f"; then echo "FAIL: $o references $f"; bad=1; fi |
| 41 | done |
| 42 | { nm -C -p "$o" 2>/dev/null; nm -C -D "$o" 2>/dev/null; } >> "$t" |
| 43 | if grep -qE '3std4time|3std3env|3std2fs|3std3net|3std7process|3std6thread|3std2io5stdio|10SystemTime|7Instant|getrandom|std::(time|env|fs|net|process|thread|io::stdio)|SystemTime|Instant::|rand::' "$t"; then |
| 44 | echo "FAIL: $o references a Rust std time/env/fs/net/process/thread or rand path"; bad=1 |
| 45 | fi |
| 46 | rm -f "$t" |
| 47 | # instruction scan (skipped only in the symbol-scan-only control, where $1 is `true`); |
| 48 | # a scanner that cannot run, or does not end with its PASS line, fails the object |
| 49 | if [ "$1" != true ]; then |
| 50 | sc=$("$1" scan-clock "$o" 2>&1); st=$? |
| 51 | printf '%s\n' "$sc" | sed -n 's/^HIT /FAIL: instruction /p; s/^UNREADABLE /FAIL: unreadable /p' |
| 52 | if [ $st -ne 0 ] || ! printf '%s\n' "$sc" | grep -qx "AT1_CLOCK_SCAN: PASS"; then |
| 53 | printf '%s\n' "$sc" | grep -qE '^(HIT|UNREADABLE) ' || echo "FAIL: instruction scan did not run on $o (exit $st)" |
| 54 | bad=1 |
| 55 | fi |
| 56 | fi |
| 57 | return $bad |
| 58 | } |
| 59 | |
| 60 | if [ "${1:-}" = "--controls" ]; then |
| 61 | EVAL=${2:?usage: isolation.sh --controls <at1-eval> [receipt]} |
| 62 | if [ ! -x "$EVAL" ]; then echo "AT1_ISOLATION_CONTROLS: FAIL ($EVAL is not an executable at1-eval)"; exit 1; fi |
| 63 | OUT=${3:-results/ISOLATION_RECEIPT.txt} |
| 64 | D=$(mktemp -d "${TMPDIR:-/tmp}/at1gate.XXXXXX") || exit 1 |
| 65 | here=$(dirname "$0") |
| 66 | CC=${CC:-cc} |
| 67 | ok=1 |
| 68 | { |
| 69 | echo "# AT-1 G2 gate controls: $(uname -s) $(uname -m), CC=$CC ($($CC --version 2>/dev/null | head -n 1))" |
| 70 | for c in clean_control hidden_clock_mutant counter_mutant raw_syscall_mutant; do |
| 71 | if ! $CC -c -O1 -o "$D/$c.o" "$here/$c.c" 2>"$D/$c.err"; then |
| 72 | echo "$c NOT_BUILT $(head -n 1 "$D/$c.err")"; ok=0; continue |
| 73 | fi |
| 74 | hits=$(scan_one "$EVAL" "$D/$c.o") |
| 75 | if [ -z "$hits" ]; then got=PASS; else got=FAIL; fi |
| 76 | if [ "$c" = clean_control ]; then want=PASS; else want=FAIL; fi |
| 77 | if [ "$got" = "$want" ]; then v=AS_INTENDED; else v=WRONG; ok=0; fi |
| 78 | echo "$c gate=$got want=$want $v $(printf '%s' "$hits" | tr '\n' ';')" |
| 79 | done |
| 80 | # the symbol scan alone must be blind to the two inline mutants (that is why the instruction scan exists) |
| 81 | for c in counter_mutant raw_syscall_mutant; do |
| 82 | [ -f "$D/$c.o" ] || continue |
| 83 | if scan_one true "$D/$c.o" >/dev/null 2>&1; then echo "$c symbol-scan-only=PASS (blind, as expected)"; else echo "$c symbol-scan-only=FAIL"; fi |
| 84 | done |
| 85 | if [ $ok = 1 ]; then echo "AT1_ISOLATION_CONTROLS: PASS"; else echo "AT1_ISOLATION_CONTROLS: FAIL"; fi |
| 86 | } | sed "s|$D/||g" > "$D/receipt" |
| 87 | mkdir -p "$(dirname "$OUT")" |
| 88 | cp "$D/receipt" "$OUT" |
| 89 | cat "$OUT" |
| 90 | rm -rf "$D" |
| 91 | # ok is set inside the piped block (a subshell), so the verdict is read back from the receipt |
| 92 | grep -qx "AT1_ISOLATION_CONTROLS: PASS" "$OUT" |
| 93 | exit $? |
| 94 | fi |
| 95 | |
| 96 | EVAL=${1:?usage: isolation.sh <at1-eval> <object>...} |
| 97 | if [ ! -x "$EVAL" ]; then echo "AT1_ISOLATION: FAIL ($EVAL is not an executable at1-eval)"; exit 1; fi |
| 98 | shift |
| 99 | fail=0 |
| 100 | for o in "$@"; do scan_one "$EVAL" "$o" || fail=1; done |
| 101 | if [ $fail = 0 ]; then echo "AT1_ISOLATION: PASS ($# objects clean)"; else echo "AT1_ISOLATION: FAIL"; fi |
| 102 | exit $fail |