Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/tests/checker2/lrat.sh # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / tests / checker2 / lrat.sh` 139 lines ยท 8305 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 # LRAT gate (omega#446): bounded integer programs proved trap-free by checker2. 18 # For every tests/checker2/lrat/*.osc (header lines "// prove: ", "// expect: holds|trap"): 19 # producer emits the IR bytes; checker2 bit-blasts the property NO-TRAP of to CNF; 20 # the UNTRUSTED solver c2sat runs under a timeout; 21 # holds -> c2sat must answer UNSAT (exit 20) and checker2 must replay the LRAT proof (VERIFIED); 22 # trap -> c2sat must answer SAT (exit 10): the program really can trap. 23 # Any disagreement with the expectation, any timeout or any refused proof fails the gate. 24 # At least 20 "holds" programs must end VERIFIED. 25 # Negative controls (each must be REFUSED, or the gate fails): 26 # every proof with its final (empty clause) line removed; 27 # every proof whose final step has its hints removed; 28 # the abs8 proof replayed against the unguarded abs8 IR (a proof binds to one program). 29 # Receipts (evidence class 2): issue checks the proofs; verify replays them and refuses missing, 30 # corrupted, substituted or misapplied proofs, and proofs offered for a class 1 receipt. 31 # verify is production by default: a TEST receipt is refused unless --allow-test-key is given. 32 # Replay: c2sat is run twice per program; the two proofs must be byte-identical. 33 # Checker identity: a receipt issued by (same sources, another identity) is refused 34 # as UNTRUSTED_CHECKER unless verify names that identity with --accept-checker; producer and 35 # dependency digests that differ from the given ones are refused. 36 # Usage: lrat.sh [timeout-seconds] 37 set -u 38 EMIT=$1 C2=$2 SAT=$3 W=$4 C2O=$5 T=${6:-60} 39 D=$(dirname "$0")/lrat 40 rm -rf "$W" && mkdir -p "$W" || exit 2 41 fail=0 verified=0 traps=0 ctl=0 42 bad() { echo "lrat: FAIL $*"; fail=$((fail + 1)); } 43 44 for src in "$D"/*.osc; do 45 b=$(basename "$src" .osc) 46 f=$(sed -n 's,^// prove: *,,p' "$src") 47 e=$(sed -n 's,^// expect: *,,p' "$src") 48 [ -n "$f" ] && [ -n "$e" ] || { bad "$b: missing prove/expect header"; continue; } 49 "$EMIT" "$src" "$W/$b.ir" >/dev/null 2>&1 || { bad "$b: producer refused"; continue; } 50 "$C2" prove-cnf "$W/$b.ir" "$f" "$W/$b.cnf" >"$W/$b.info" 2>&1 || { bad "$b: prove-cnf: $(cat "$W/$b.info")"; continue; } 51 timeout "$T" "$SAT" "$W/$b.cnf" "$W/$b.lrat" >"$W/$b.sat" 2>&1 52 r=$? 53 case "$e:$r" in 54 holds:20) 55 timeout "$T" "$SAT" "$W/$b.cnf" "$W/$b.lrat2" >/dev/null 2>&1 56 cmp -s "$W/$b.lrat" "$W/$b.lrat2" || bad "$b: proof not reproducible" 57 out=$("$C2" prove-check "$W/$b.ir" "$f" "$W/$b.lrat" 2>&1) 58 case "$out" in 59 lrat=VERIFIED*) verified=$((verified + 1)); echo "lrat: $b $f VERIFIED $(grep -o 'vars=[0-9]* clauses=[0-9]*' "$W/$b.info") steps=${out##*steps=}" ;; 60 *) bad "$b: proof refused: $out"; continue ;; 61 esac 62 # control 1: drop the final line (the empty clause) 63 sed '$d' "$W/$b.lrat" >"$W/$b.cut" 64 "$C2" prove-check "$W/$b.ir" "$f" "$W/$b.cut" 2>&1 | grep -q '^lrat=REFUSED' && ctl=$((ctl + 1)) || bad "$b: truncated proof accepted" 65 # control 2: final step without hints 66 sed '$s/^\([0-9]*\) 0 .*/\1 0 0/' "$W/$b.lrat" >"$W/$b.nohint" 67 "$C2" prove-check "$W/$b.ir" "$f" "$W/$b.nohint" 2>&1 | grep -q '^lrat=REFUSED' && ctl=$((ctl + 1)) || bad "$b: hintless proof accepted" 68 ;; 69 trap:10) traps=$((traps + 1)); echo "lrat: $b $f can trap (counterexample found, as expected)" ;; 70 *:124) bad "$b: solver timeout after ${T}s" ;; 71 *) bad "$b: expected $e, solver exit $r" ;; 72 esac 73 done 74 75 # control 3: a valid proof for one program must not verify another program 76 if [ -f "$W/p01_abs8.lrat" ] && [ -f "$W/n01_abs8_unguarded.ir" ]; then 77 "$C2" prove-check "$W/n01_abs8_unguarded.ir" abs8 "$W/p01_abs8.lrat" 2>&1 | grep -q '^lrat=REFUSED' && ctl=$((ctl + 1)) || bad "abs8 proof verified the unguarded program" 78 else 79 bad "cross-program control inputs missing" 80 fi 81 82 # receipts with LRAT evidence (class 2): proofs are checked at issue and replayed at verify 83 R=$W/rcpt 84 mkdir -p "$R/out" "$R/out1" 85 printf 'exe\n' >"$R/exe" 86 iss() { "$C2" receipt issue "$1" "$R/exe" --target lrat-gate --epoch 5 --expiry 9 --out-dir "$2" "$3" "$4" >/dev/null 2>&1; } 87 want() { # want 88 w=$1 n=$2 89 shift 2 90 got=$("$C2" receipt verify "$@" 2>/dev/null | grep '^receipt=') 91 [ "$got" = "receipt=$w" ] && ctl=$((ctl + 1)) || bad "receipt $n: got '$got', want receipt=$w" 92 } 93 if iss "$W/p01_abs8.ir" "$R/out" --lrat "abs8=$W/p01_abs8.lrat"; then 94 rc2=$(ls "$R/out"/*.rcpt) 95 V="$rc2 $W/p01_abs8.ir $R/exe --target lrat-gate --epoch 6 --allow-test-key" 96 # production is the default: without --allow-test-key a TEST-signed receipt is refused 97 want TEST_SIGNER_IN_PRODUCTION default-refuses-test "$rc2" "$W/p01_abs8.ir" "$R/exe" --target lrat-gate --epoch 6 --lrat "abs8=$W/p01_abs8.lrat" 98 want TEST_SIGNER_IN_PRODUCTION explicit-production-refuses-test "$rc2" "$W/p01_abs8.ir" "$R/exe" --target lrat-gate --epoch 6 --production --lrat "abs8=$W/p01_abs8.lrat" 99 "$C2" receipt verify $V --production --lrat "abs8=$W/p01_abs8.lrat" >/dev/null 2>&1 100 [ $? -eq 2 ] && ctl=$((ctl + 1)) || bad "--production with --allow-test-key not refused as usage" 101 { cat "$W/p01_abs8.lrat"; echo "c same proof, different bytes"; } >"$W/p01_abs8.other" 102 want VALID class2-replayed $V --lrat "abs8=$W/p01_abs8.lrat" 103 want LRAT-PROOFS-REQUIRED class2-without-proofs $V 104 want LRAT-REPLAY-FAILED class2-bad-proof $V --lrat "abs8=$W/p01_abs8.cut" 105 want LRAT-REQUIREMENTS-MISMATCH class2-other-proof $V --lrat "abs8=$W/p01_abs8.other" 106 want PROGRAM_MISMATCH class2-wrong-program "$rc2" "$W/n01_abs8_unguarded.ir" "$R/exe" --target lrat-gate --epoch 6 --allow-test-key --lrat "abs8=$W/p01_abs8.lrat" 107 else 108 bad "receipt issue with a verified proof failed" 109 fi 110 iss "$W/n01_abs8_unguarded.ir" "$R/out" --lrat "abs8=$W/p01_abs8.lrat" && bad "receipt issued for a program its proof does not cover" || ctl=$((ctl + 1)) 111 if iss "$W/p02_avg_u8.ir" "$R/out1" --input "$R/exe"; then 112 rc1=$(ls "$R/out1"/*.rcpt) 113 V1="$rc1 $W/p02_avg_u8.ir $R/exe --target lrat-gate --epoch 6 --allow-test-key" 114 want VALID class1-control $V1 115 want WRONG_PRODUCER class1-other-producer $V1 --producer "$R/exe" 116 want DEPENDENCIES_MISMATCH class1-unexpected-dep $V1 --dep `0000000000000000000000000000000000000000000000000000000000000001` 117 want LRAT-NOT-CLAIMED class1-with-proof "$(ls "$R/out1"/*.rcpt)" "$W/p02_avg_u8.ir" "$R/exe" --target lrat-gate --epoch 6 --allow-test-key --lrat "avg=$W/p02_avg_u8.lrat" 118 else 119 bad "class 1 receipt issue failed" 120 fi 121 122 # checker identity: same sources under another identity; its receipts are not checker2's verdicts 123 mkdir -p "$R/out2" 124 if "$C2O" receipt issue "$W/p02_avg_u8.ir" "$R/exe" --target lrat-gate --epoch 5 --expiry 9 --out-dir "$R/out2" >/dev/null 2>&1; then 125 rco=$(ls "$R/out2"/*.rcpt) 126 oid=$("$C2O" version | sed -n 's/^checker_id=//p') 127 sid=$("$C2" version | sed -n 's/^checker_id=//p') 128 [ -n "$oid" ] && [ "$oid" != "$sid" ] || bad "checker2-other has no distinct identity" 129 VO="$rco $W/p02_avg_u8.ir $R/exe --target lrat-gate --epoch 6 --allow-test-key" 130 want UNTRUSTED_CHECKER other-checker-refused $VO 131 want VALID other-checker-accepted-explicitly $VO --accept-checker "$oid" 132 else 133 bad "receipt issue by checker2-other failed" 134 fi 135 136 echo "lrat: verified=$verified expected-traps=$traps controls-refused=$ctl failures=$fail" 137 [ "$verified" -ge 20 ] || bad "only $verified programs verified (need 20)" 138 [ "$fail" -eq 0 ] || exit 1 139 echo "lrat: PASS"