#!/usr/bin/env bash # ───────────────────────────────────────────────────────────────────────────── # selftest-correspondence.sh — attacks check.sh Phase 0d. # # Phase 0d asserts HOW each external the extraction asks for is answered: with # an assumption in the hand-written model, or with a proof already in the # extracted corpus. The second class is the one the documents make a claim # about — the curve calls and curve types are said to resolve to the proven # model's own definitions rather than to axioms — and that claim was prose # until this phase existed. # # 0 control: the committed table matches the files # 1 the extraction asks for something NOTHING provides -> UNRESOLVED # 2 a PROVEN external answered by an axiom in the model instead. This is the # attack that matters: a proof silently downgraded to an assumption, in a # name whose spelling does not change anywhere else. # 3 a row deleted from the committed table -> drift # 4 a row's verdict edited in the committed table -> drift # # No Lean: Phase 0d is pure text over gen/. Seconds, not minutes. # ───────────────────────────────────────────────────────────────────────────── set -uo pipefail HERE="$(cd "$(dirname "$0")" && pwd)" FAILURES=0 STASH="$(mktemp -d)" cleanup() { [ -f "$STASH/corr" ] && cp "$STASH/corr" "$HERE/MODEL-CORRESPONDENCE.txt" [ -f "$STASH/model" ] && cp "$STASH/model" "$HERE/$MODEL_REL" [ -f "$STASH/tmpl" ] && cp "$STASH/tmpl" "$HERE/$TMPL_REL" rm -rf "$STASH" } # Derive the victims from this repo rather than naming them: the forks do not # share a gen/ layout (anza has no CurveSig crate at all, so it has no PROVEN # rows and case 2 does not apply there). TMPL_REL=$(cd "$HERE" && ls gen/*/FunsExternal_Template.lean | head -1) MODEL_REL="${TMPL_REL/_Template/}" PROVEN_ROW=$(grep -m1 '|PROVEN$' "$HERE/MODEL-CORRESPONDENCE.txt" || true) trap cleanup EXIT INT TERM cp "$HERE/MODEL-CORRESPONDENCE.txt" "$STASH/corr" cp "$HERE/$MODEL_REL" "$STASH/model" cp "$HERE/$TMPL_REL" "$STASH/tmpl" # Phase 0d lifted from the shipping button. awk '/^# ── Phase 0d/{f=1} f&&/^# ── (Phase 1|Phases end)/{exit} f{print}' \ "$HERE/check.sh" > "$STASH/payload.sh" { echo 'set -euo pipefail' echo "HERE=\"$HERE\"" cat "$STASH/payload.sh" } > "$STASH/p0d.sh" # Assert on the PAYLOAD, not the concatenation: a marker appearing in the # preamble would otherwise satisfy a check meant to prove the lift landed. for want in 'Phase 0d' 'MODEL CORRESPONDENCE' 'model-correspondence.py'; do grep -qF "$want" "$STASH/payload.sh" || { echo "FATAL: the lifted driver has no '$want' — check.sh's phase markers moved."; exit 1; } done "$HERE/lift-guard.sh" "$STASH/payload.sh" "$STASH/p0d.sh" "check.sh Phase 0d" || exit 1 expect() { # expect