Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,3 @@ package-lock.json text eol=lf -diff linguist-generated=true
*.nix text eol=lf
flake.lock text eol=lf -diff linguist-generated=true

# Scanner refusal control: its CRLF line ends are the test, so git must keep
# the bytes as they are (scripts/check-trusted-base.sh).
tests/trusted-base/CarriageReturn.txt -text
11 changes: 9 additions & 2 deletions .github/workflows/proofs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Install the pinned prover
run: |
apt-get update
apt-get install --no-install-recommends -y ca-certificates curl git agda-bin=2.6.4.3-1+b2
apt-get install --no-install-recommends -y ca-certificates curl unzip git agda-bin=2.6.4.3-1+b2
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
Expand Down Expand Up @@ -92,8 +92,15 @@ jobs:
# check-trusted-base.sh below already calls it (--inputs agda).
- name: Fetch the pinned receipt tools (sha256-checked)
run: bash scripts/grade-receipt.sh --fetch-reader
# The standard's shared trusted-base gate reads Agda's report with
# agda-postulates.js, so this job needs Bun (as the receipt job does).
- name: Setup Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version: '1.3.12'
# PROOF-POLICY §8.4: the prover-supplied postulates of the import cone
# are exactly the trusted base the receipt lists (scripts/proof-flags.sh).
# are exactly the trusted base the receipt lists (scripts/proof-flags.sh),
# read by the standard's shared gate (scripts/check-agda-trusted-base.sh).
- name: Trusted base of the import cone
run: bash scripts/check-trusted-base.sh 2>&1 | tee /tmp/trusted-base.log
- name: Which laws generic TINI uses
Expand Down
12 changes: 8 additions & 4 deletions PROOF-STATUS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,14 @@ ways). W-1 is kept, closed, in link:docs/proof-debt.adoc#waivers[`docs/proof-deb
* `(trusted-base ...)`: the four postulates of `Agda.Primitive` (`Level`,
`lzero`, `lsuc`, `_⊔_`) with their `BUILTIN` bindings. These are the only
postulates in the prover-supplied modules of the import cone of
`SecretTypes.All`. `scripts/check-trusted-base.sh` asks Agda for the cone
(`--dependency-graph`), scans those modules with a comment-aware scanner
(`scripts/scan-agda-postulates.awk`, with controls in `tests/trusted-base/`)
and compares the result with the one list in `scripts/proof-flags.sh`;
`SecretTypes.All`. `scripts/check-trusted-base.sh` runs the standard's
shared gate (`scripts/check-agda-trusted-base.sh`, pinned with the receipt
tools). It asks Agda for the cone (`--dependency-graph`) and reads the
postulates Agda itself reports in it (`--html`, not a lexical scan of the
source; its controls, including two postulates on one line split by a
semicolon, live in the standard). It compares the prover's postulates with
the one list in `scripts/proof-flags.sh`, as the receipt writes it
(`grade-receipt.sh --trusted-base`);
* one `(echo ...)` per history rewrite of a commit that a receipt names
(§8.5.2): the source commit, its image on main, and the inputs digest of
each leg, equal at both;
Expand Down
81 changes: 24 additions & 57 deletions scripts/check-trusted-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,80 +9,47 @@
# declare primitives by postulate, and --safe accepts them. Such a postulate
# is admissible only if the receipt lists it by name with its binding, and the
# gate checks that exact list. This script is that check:
# 1. run the scanner's controls (tests/trusted-base), so a scanner that
# stops finding postulates fails here first;
# 2. ask Agda for the cone (--dependency-graph, the gate's own flags);
# 3. scan every prover-supplied module of the cone;
# 4. compare the result, as a set, with proof_trusted_base.
# 1. run the standard's shared gate, scripts/check-agda-trusted-base.sh
# (pinned with scripts/agda-postulates.js by scripts/grade-receipt.sh).
# It type-checks the root under the gate's own flags, reads the
# postulates Agda itself reports for the cone (no lexical scan of Agda
# source), refuses any postulate in a module under src/, and requires
# the prover's postulates to be exactly the receipt's trusted base
# (`grade-receipt.sh --trusted-base`, from proof_trusted_base). Its
# controls run in the standard; a live control runs here on every call;
# 2. require the Agda input set of the receipt to be exactly the
# repository's part of the cone that gate reported.
# Any difference fails. A prover pin bump that changes the list fails here
# until proof_trusted_base is updated and the receipt is earned again.
#
# Needs agda (the pinned version), bun, and the pinned standards files
# (scripts/grade-receipt.sh --fetch-reader).
set -euo pipefail
cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.."
export LC_ALL=C
. scripts/proof-flags.sh
prover="${AGDA:-agda}"
scan=scripts/scan-agda-postulates.awk
gate="${RECEIPT_STD_OVERRIDE:-_build/standards}/scripts/check-agda-trusted-base.sh"
work="$(mktemp -d)"; trap 'rm -rf "$work"' EXIT
[[ -f "$gate" ]] || { echo "ERROR: $gate is missing (run bash scripts/grade-receipt.sh --fetch-reader)" >&2; exit 1; }

# 1. Controls. Positive and comment-only fixtures must give their expected
# lists; the refusal fixtures must be refused (exit 3), never passed.
for f in tests/trusted-base/*.txt; do
name="$(basename -- "$f" .txt)"
set +e; awk -v "module=Fixture.$name" -f "$scan" "$f" > "$work/$name.out" 2> "$work/$name.err"; rc=$?; set -e
if [[ -f "tests/trusted-base/$name.expected" ]]; then
if (( rc != 0 )) || ! diff -u "tests/trusted-base/$name.expected" "$work/$name.out"; then
cat "$work/$name.err" >&2
echo "FAIL: scanner control $name (rc=$rc)" >&2; exit 1
fi
elif (( rc != 3 )); then
cat "$work/$name.out" >&2
echo "FAIL: scanner control $name was not refused (rc=$rc)" >&2; exit 1
fi
done
echo "PASS: scanner controls ($(ls tests/trusted-base/*.txt | wc -l | tr -d ' ') fixtures)"

# 2. The cone, as Agda reports it under the gate's flags.
# 1. The shared gate, on the list the receipt writes. grade-receipt.sh checks
# the sha256 of every pinned standards file before it runs.
bash scripts/grade-receipt.sh --trusted-base > "$work/declared" \
|| { echo 'FAIL: grade-receipt.sh --trusted-base failed' >&2; exit 1; }
mapfile -t flags < <(proof_flags)
"$prover" "${flags[@]}" -i src --dependency-graph="$work/cone.dot" "$(proof_agda_root)" > "$work/agda.log" 2>&1 \
|| { cat "$work/agda.log" >&2; echo 'FAIL: agda could not produce the dependency graph' >&2; exit 1; }
mapfile -t cone < <(sed -n 's/.*label="\([^"]*\)".*/\1/p' "$work/cone.dot" | sort -u)
(( ${#cone[@]} > 0 )) || { echo 'FAIL: empty dependency graph' >&2; exit 1; }
agda_dir="$("$prover" --print-agda-dir)"
bash "$gate" --root "$(proof_agda_root)" --include src \
--expect "$work/declared" --cone-out "$work/cone" -- "${flags[@]}"

# The repository's part of the cone is the Agda input set of the receipt
# 2. The repository's part of the cone is the Agda input set of the receipt
# (PROOF-POLICY §8.5.1). scripts/grade-receipt.sh computes it by a text scan
# of import statements; it must be exactly the set Agda reports.
for m in "${cone[@]}"; do
while IFS= read -r m; do
rel="src/${m//.//}.agda"
[[ -f "$rel" ]] && printf '%s\n' "$rel"
done | LC_ALL=C sort > "$work/cone-repo"
done < "$work/cone" | LC_ALL=C sort > "$work/cone-repo"
bash scripts/grade-receipt.sh --inputs agda > "$work/cone-scan"
if ! diff -u "$work/cone-repo" "$work/cone-scan"; then
echo 'FAIL: the Agda input set of scripts/grade-receipt.sh differs from the cone agda --dependency-graph reports' >&2
exit 1
fi
echo "PASS: Agda input set ($(wc -l < "$work/cone-repo" | tr -d ' ') repository modules) equals the cone Agda reports"

# 3. Scan the prover-supplied modules. Every module of the cone is either the
# development's (under src/) or Agda's (under the prover's lib/prim); a module
# in neither place fails, so nothing in the cone goes unscanned.
supplied=0
: > "$work/found"
for m in "${cone[@]}"; do
rel="${m//.//}.agda"
if [[ -f "src/$rel" ]]; then continue; fi
path="$agda_dir/lib/prim/$rel"
[[ -f "$path" ]] || { echo "FAIL: module $m of the cone is neither under src/ nor under $agda_dir/lib/prim" >&2; exit 1; }
supplied=$((supplied + 1))
awk -v "module=$m" -f "$scan" "$path" >> "$work/found"
done

# 4. Compare with the declared list.
sort -u "$work/found" > "$work/found.sorted"
proof_trusted_base | sort -u > "$work/declared.sorted"
if ! diff -u "$work/declared.sorted" "$work/found.sorted" > "$work/diff"; then
cat "$work/diff" >&2
echo 'FAIL: the prover-supplied postulates of the cone differ from proof_trusted_base (scripts/proof-flags.sh)' >&2
exit 1
fi
echo "PASS: trusted base: $(wc -l < "$work/found.sorted" | tr -d ' ') prover postulates in $supplied prover-supplied modules of the cone, each BUILTIN-bound and listed; no other postulate"
16 changes: 11 additions & 5 deletions scripts/grade-receipt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,28 @@ RECEIPT_SCRIPT=scripts/grade-receipt.sh
# sha256: the generator (scripts/proof-receipt.sh), the reader readProofReceipt
# (1-formats/deed/tools/deed_lint.js), the reference digest
# (scripts/proof-inputs-sha256.sh) and the shared git checker of §8.5.3
# (scripts/check-proof-receipt.sh). They keep the standards layout under
# (scripts/check-proof-receipt.sh), and the shared trusted-base gate of
# §8.4 (scripts/check-agda-trusted-base.sh with scripts/agda-postulates.js,
# run by scripts/check-trusted-base.sh). They keep the standards layout under
# _build/standards, because the checker finds the reader and the digest
# script by their paths. Mathesis pins the same reader and runs the same
# checker.
RECEIPT_STANDARDS_COMMIT="${RECEIPT_STANDARDS_COMMIT_OVERRIDE:-940a27af1e25a73a2d55daa78d0763e6749fd935}"
GENERATOR_SHA256=47e9e5596e69574440260e4372c4b400f6c5f97192ff04292a59bffc4c215fe8
READER_SHA256=29278b46654bdee70e8e1ff4a7ff8cb810e04b618c9ca1520a6979d6c4c91f18
RECEIPT_STANDARDS_COMMIT="${RECEIPT_STANDARDS_COMMIT_OVERRIDE:-5addf98b2531feb7d65a27f52ca229992f26dfea}"
GENERATOR_SHA256=d496cefa0da322d36df6307aac08abda6af62fc4d4faa8091ca744ecd7d4a898
READER_SHA256=bd276e4046066926bdfb65f474271e2ddba57467cc237e9e7ec56c894577b04d
DIGEST_SHA256=dfc6dde01a3a79df638eebe4cad0eae584d8f17280077e149174c0667e9508f4
CHECKER_SHA256=f2375747238464535d1b4a61f658f07cb2f8504c69bfb1812311c79429a4e23e
TB_GATE_SHA256=20bf3a8ddf0864d8ac731a6b6593f032d449067387d45abe821fbc516c1e03ed
TB_READER_SHA256=fe5c49cc36e3e3b7606d94cadfc390eb4c806139e1238785c803ab56a80a9fa8
RECEIPT_STD="${RECEIPT_STD_OVERRIDE:-_build/standards}"

pinned_files() {
printf '%s %s\n' scripts/proof-receipt.sh "$GENERATOR_SHA256" \
1-formats/deed/tools/deed_lint.js "$READER_SHA256" \
scripts/proof-inputs-sha256.sh "$DIGEST_SHA256" \
scripts/check-proof-receipt.sh "$CHECKER_SHA256"
scripts/check-proof-receipt.sh "$CHECKER_SHA256" \
scripts/check-agda-trusted-base.sh "$TB_GATE_SHA256" \
scripts/agda-postulates.js "$TB_READER_SHA256"
}
fetch_pinned() {
local path sum dest raw="https://raw.githubusercontent.com/metadatastician/standards/$RECEIPT_STANDARDS_COMMIT"
Expand Down
151 changes: 0 additions & 151 deletions scripts/scan-agda-postulates.awk

This file was deleted.

6 changes: 0 additions & 6 deletions tests/trusted-base/CarriageReturn.txt

This file was deleted.

Empty file.
8 changes: 0 additions & 8 deletions tests/trusted-base/CommentsOnly.txt

This file was deleted.

11 changes: 0 additions & 11 deletions tests/trusted-base/NestedModule.txt

This file was deleted.

5 changes: 0 additions & 5 deletions tests/trusted-base/Positive.expected

This file was deleted.

Loading
Loading