interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-proof / formal / formal-job.sh

94 lines · 4077 bytes Raw Blame History
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.
29set -eu
30job_file=${1:?usage: formal-job.sh JOBFILE}
31here=$(cd "$(dirname "$0")" && pwd)
32job_file=$(cd "$(dirname "$job_file")" && pwd)/$(basename "$job_file")
33arch=${AIEN_ARCH_DIR:?set AIEN_ARCH_DIR to the aien-architecture checkout}
34proof=${AIEN_PROOF_BIN:-aien-proof}
35cache=${AIEN_FORMAL_CACHE:-$HOME/.cache/aien-formal}
36
37# shellcheck disable=SC1090
38. "$job_file"
39
40mode=${2:-start}
41
42covered_abs="$cache/${COVERED_REPO}/$COVERED_COMMIT/$COVERED_PATH"
43out="$cache/out/$JOB.out"
44
45inputs_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
51iflags=$(inputs_flags | tr '\n' ' ')
52
53if [ "$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"
61fi
62
63# Fetch the covered file at the pinned commit (once).
64if [ ! -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"
69fi
70
71export PATH="$HOME/.elan/bin:$PATH"
72toolchain="$(tr -d '\n' <"$arch/$ORACLE_DIR/lean-toolchain") / $(lean --version | head -1) / $(lake --version | head -1)"
73theorems=$(sed -n 's/^theorem \([A-Za-z_0-9.]*\).*/\1/p' "$arch/$THEOREM_FILE" | sed 's/^/--theorem /' | tr '\n' ' ')
74arch_commit=$(git -C "$arch" rev-parse HEAD)
75dirty=""
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.
80cd "$arch"
81rc=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
89exec "$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