aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / aien-proof / formal / formal-job.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 | # Run one formal oracle job on the proof board and bind the result to its evidence. |
| 18 | # |
| 19 | # formal-job.sh formal/jobs/<name>.job |
| 20 | # |
| 21 | # Needs: AIEN_ARCH_DIR (aien-architecture checkout holding the oracle and manifests), |
| 22 | # aien-proof on PATH (or AIEN_PROOF_BIN), gh authenticated (to fetch the covered file once). |
| 23 | # Optional: AIEN_FORMAL_CACHE (default ~/.cache/aien-formal), AIEN_PROOF_DIR (board dir). |
| 24 | # Prints the receipt ID. Exit code follows the receipt result (0 PASS). |
| 25 | # |
| 26 | # The covered implementation file is fetched at the pinned COVERED_COMMIT into the cache and |
| 27 | # hashed like any input, so the pin is part of the job fingerprint. Changing the job file, this |
| 28 | # script, the invariant manifest, any Lean source, or the covered file changes the job key. |
| 29 | set -eu |
| 30 | job_file=${1:?usage: formal-job.sh JOBFILE} |
| 31 | here=$(cd "$(dirname "$0")" && pwd) |
| 32 | job_file=$(cd "$(dirname "$job_file")" && pwd)/$(basename "$job_file") |
| 33 | arch=${AIEN_ARCH_DIR:?set AIEN_ARCH_DIR to the aien-architecture checkout} |
| 34 | proof=${AIEN_PROOF_BIN:-aien-proof} |
| 35 | cache=${AIEN_FORMAL_CACHE:-$HOME/.cache/aien-formal} |
| 36 | |
| 37 | # shellcheck disable=SC1090 |
| 38 | . "$job_file" |
| 39 | |
| 40 | mode=${2:-start} |
| 41 | |
| 42 | covered_abs="$cache/${COVERED_REPO}/$COVERED_COMMIT/$COVERED_PATH" |
| 43 | out="$cache/out/$JOB.out" |
| 44 | |
| 45 | inputs_flags() { |
| 46 | printf '%s\n' --base "$arch" --invariant "$INVARIANT" |
| 47 | for m in $MODEL; do printf '%s\n' --model "$m"; done |
| 48 | printf '%s\n' --proof-source "$ORACLE_DIR" --covered "$covered_abs" |
| 49 | } |
| 50 | # word-safe enough: no path here contains spaces |
| 51 | iflags=$(inputs_flags | tr '\n' ' ') |
| 52 | |
| 53 | if [ "$mode" = "exec" ]; then |
| 54 | # Inside the board job: write the digest line, then the oracle output, keep both. |
| 55 | mkdir -p "$(dirname "$out")" |
| 56 | # shellcheck disable=SC2086 |
| 57 | d=$("$proof" formal digest $iflags) |
| 58 | { echo "inputs_digest: $d"; sh "$arch/$ORACLE_DIR/$RUNNER"; } >"$out" 2>&1 && rc=0 || rc=$? |
| 59 | cat "$out" |
| 60 | exit "$rc" |
| 61 | fi |
| 62 | |
| 63 | # Fetch the covered file at the pinned commit (once). |
| 64 | if [ ! -s "$covered_abs" ]; then |
| 65 | mkdir -p "$(dirname "$covered_abs")" |
| 66 | gh api -H "Accept: application/vnd.github.raw" \ |
| 67 | "repos/$COVERED_REPO/contents/$COVERED_PATH?ref=$COVERED_COMMIT" >"$covered_abs.tmp" |
| 68 | mv "$covered_abs.tmp" "$covered_abs" |
| 69 | fi |
| 70 | |
| 71 | export PATH="$HOME/.elan/bin:$PATH" |
| 72 | toolchain="$(tr -d '\n' <"$arch/$ORACLE_DIR/lean-toolchain") / $(lean --version | head -1) / $(lake --version | head -1)" |
| 73 | theorems=$(sed -n 's/^theorem \([A-Za-z_0-9.]*\).*/\1/p' "$arch/$THEOREM_FILE" | sed 's/^/--theorem /' | tr '\n' ' ') |
| 74 | arch_commit=$(git -C "$arch" rev-parse HEAD) |
| 75 | dirty="" |
| 76 | [ -n "$(git -C "$arch" status --porcelain -- "$INVARIANT" "$ORACLE_DIR")" ] && dirty="--dirty" |
| 77 | |
| 78 | # The board job. Inputs are the invariant manifest, the Lean sources, this script, the job |
| 79 | # file, and the covered file. Run from the architecture checkout so inputs hash by relative path. |
| 80 | cd "$arch" |
| 81 | rc=0 |
| 82 | "$proof" run --job "$JOB" \ |
| 83 | --input "$INVARIANT" --input "$ORACLE_DIR" \ |
| 84 | --input "$here/formal-job.sh" --input "$job_file" --input "$covered_abs" \ |
| 85 | -- sh "$here/formal-job.sh" "$job_file" exec || rc=$? |
| 86 | [ -s "$out" ] || { echo "no output recorded for $JOB (rc=$rc)"; exit 1; } |
| 87 | |
| 88 | # shellcheck disable=SC2086 |
| 89 | exec "$proof" formal bind $iflags \ |
| 90 | --oracle-toolchain "$toolchain" $theorems \ |
| 91 | --result-prefix "$RESULT_PREFIX" --output-file "$out" \ |
| 92 | --repo "https://github.com/$COVERED_REPO" --commit "$COVERED_COMMIT" \ |
| 93 | --machine "$(hostname)" --procedure "$JOB" \ |
| 94 | --external-ref "aien-architecture@$arch_commit" $dirty |