diff --git a/.github/workflows/actions.lock b/.github/workflows/actions.lock index c026608..2766049 100644 --- a/.github/workflows/actions.lock +++ b/.github/workflows/actions.lock @@ -4,6 +4,7 @@ version: 'v0.0.3' workflows: '.github/workflows/atoma.yml': + - 'actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9' - 'actions/checkout@v7.0.1' - 'actions/upload-artifact@v7.0.2' '.github/workflows/build-notification.yml': diff --git a/.github/workflows/atoma.yml b/.github/workflows/atoma.yml index 55bbdc2..099f068 100644 --- a/.github/workflows/atoma.yml +++ b/.github/workflows/atoma.yml @@ -36,10 +36,13 @@ jobs: - uses: actions/checkout@v7.0.1 with: persist-credentials: false - - name: Provision independent Coq checker - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends coq=8.18.0+dfsg-1build2 + - name: Cache pinned Coq packages + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ runner.temp }}/atoma-coq-debs + key: coq-8.18-debs-${{ hashFiles('ci/coq-8.18.debs.sha256') }} + - name: Provision independent Coq checker (pinned, sha-checked) + run: bash scripts/atoma-provision-coq.sh "$RUNNER_TEMP/atoma-coq-debs" - name: Guarded decoder and imported encoder source run: bash scripts/atoma-word-source-proof-gate.sh - name: Actual registry state-kernel source @@ -62,10 +65,13 @@ jobs: - uses: actions/checkout@v7.0.1 with: persist-credentials: false - - name: Provision independent Coq checker - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends coq=8.18.0+dfsg-1build2 + - name: Cache pinned Coq packages + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ runner.temp }}/atoma-coq-debs + key: coq-8.18-debs-${{ hashFiles('ci/coq-8.18.debs.sha256') }} + - name: Provision independent Coq checker (pinned, sha-checked) + run: bash scripts/atoma-provision-coq.sh "$RUNNER_TEMP/atoma-coq-debs" - name: Actual wrapper source and conditional effects run: bash scripts/atoma-wrapper-source-proof-gate.sh - uses: actions/upload-artifact@v7.0.2 @@ -83,11 +89,17 @@ jobs: - uses: actions/checkout@v7.0.1 with: persist-credentials: false + - name: Cache pinned Coq packages + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ runner.temp }}/atoma-coq-debs + key: coq-8.18-debs-${{ hashFiles('ci/coq-8.18.debs.sha256') }} - name: Provision scalar proof profile run: | set -euo pipefail sudo apt-get update - sudo apt-get install -y --no-install-recommends agda-bin=2.6.3-1build1 coq=8.18.0+dfsg-1build2 zstd + sudo apt-get install -y --no-install-recommends agda-bin=2.6.3-1build1 zstd + bash scripts/atoma-provision-coq.sh "$RUNNER_TEMP/atoma-coq-debs" bash scripts/atoma-download-zig.sh "$RUNNER_TEMP/scalar-zig" cd "$RUNNER_TEMP" curl --proto '=https' --proto-redir '=https' --connect-timeout 20 --max-time 240 -fL --retry 1 https://github.com/leanprover/lean4/releases/download/v4.15.0/lean-4.15.0-linux.tar.zst -o scalar-lean.tar.zst @@ -125,10 +137,13 @@ jobs: - uses: actions/checkout@v7.0.1 with: persist-credentials: false - - name: Provision independent Coq checker - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends coq=8.18.0+dfsg-1build2 + - name: Cache pinned Coq packages + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ runner.temp }}/atoma-coq-debs + key: coq-8.18-debs-${{ hashFiles('ci/coq-8.18.debs.sha256') }} + - name: Provision independent Coq checker (pinned, sha-checked) + run: bash scripts/atoma-provision-coq.sh "$RUNNER_TEMP/atoma-coq-debs" - name: Actual public header entry run: bash scripts/atoma-public-header-source-gate.sh - name: Actual registry destruction and retained regions @@ -156,6 +171,11 @@ jobs: persist-credentials: false - name: Provision pinned proof tools run: bash scripts/atoma-ci-toolchain.sh + - name: Cache pinned Coq packages + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ runner.temp }}/atoma-coq-debs + key: coq-8.18-debs-${{ hashFiles('ci/coq-8.18.debs.sha256') }} - name: Provision independent replay tools run: bash scripts/atoma-ci-replay-toolchain.sh - name: Provision pinned Proven Tests and Benches contract @@ -185,6 +205,11 @@ jobs: persist-credentials: false - name: Provision pinned proof tools run: bash scripts/atoma-ci-toolchain.sh + - name: Cache pinned Coq packages + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ runner.temp }}/atoma-coq-debs + key: coq-8.18-debs-${{ hashFiles('ci/coq-8.18.debs.sha256') }} - name: Provision source-model replay tools run: bash scripts/atoma-ci-replay-toolchain.sh - name: Provision pinned Proven Tests and Benches contract @@ -213,6 +238,11 @@ jobs: persist-credentials: false - name: Provision pinned Zig run: bash scripts/atoma-download-zig.sh "$RUNNER_TEMP/atoma-translation-zig" + - name: Cache pinned Coq packages + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ runner.temp }}/atoma-coq-debs + key: coq-8.18-debs-${{ hashFiles('ci/coq-8.18.debs.sha256') }} - name: Provision pinned replay tools run: bash scripts/atoma-ci-replay-toolchain.sh - name: Build the actual Atoma emitter @@ -228,9 +258,25 @@ jobs: if-no-files-found: error retention-days: 30 + coq_pin_selftest: + name: Pinned Coq rejects a corrupted checksum + runs-on: ubuntu-24.04 + timeout-minutes: 10 + steps: + - uses: actions/checkout@v7.0.1 + with: + persist-credentials: false + - name: Cache pinned Coq packages + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ${{ runner.temp }}/atoma-coq-debs + key: coq-8.18-debs-${{ hashFiles('ci/coq-8.18.debs.sha256') }} + - name: Negative self-test (a flipped sha256 must fail verification) + run: bash scripts/atoma-provision-coq.sh --self-test-bad-sha "$RUNNER_TEMP/atoma-coq-debs" + soundness: name: Atoma soundness gate - needs: [core_soundness, heap_consumers, byte_translation] + needs: [core_soundness, heap_consumers, byte_translation, coq_pin_selftest] if: ${{ always() }} runs-on: ubuntu-24.04 timeout-minutes: 2 @@ -240,10 +286,12 @@ jobs: CORE_RESULT: ${{ needs.core_soundness.result }} HEAP_RESULT: ${{ needs.heap_consumers.result }} TRANSLATION_RESULT: ${{ needs.byte_translation.result }} + COQ_PIN_RESULT: ${{ needs.coq_pin_selftest.result }} run: | test "$CORE_RESULT" = success test "$HEAP_RESULT" = success test "$TRANSLATION_RESULT" = success + test "$COQ_PIN_RESULT" = success gate: name: CI/gate diff --git a/ci/README.adoc b/ci/README.adoc index 933aae6..b53af96 100644 --- a/ci/README.adoc +++ b/ci/README.adoc @@ -14,6 +14,10 @@ Non-GitHub CI configuration lives here. GitHub Actions workflows stay in | `.pre-commit-config.yaml` | The `pre-commit` framework, when invoked with `--config`. + +| `coq-8.18.debs.sha256` +| `scripts/atoma-provision-coq.sh`: the pinned, sha-checked Coq 8.18.0 package + closure (noble, amd64) installed by every Atoma replay job. |=== == Required out-of-band setting (GitLab) diff --git a/ci/coq-8.18.debs.sha256 b/ci/coq-8.18.debs.sha256 new file mode 100644 index 0000000..3654399 --- /dev/null +++ b/ci/coq-8.18.debs.sha256 @@ -0,0 +1,17 @@ +# Coq 8.18.0 install closure for ubuntu-24.04 (noble, amd64): the 12 .debs that +# `apt-get install coq=8.18.0+dfsg-1build2` adds on a fresh runner. +# sha256s taken from the noble archive packages (apt-get download pkg=version, +# then sha256sum). Consumed by scripts/atoma-provision-coq.sh, which is the +# only place pool paths live. Change a line only by re-deriving it from the archive. +22897a17a75d8930276f5eedd5cd29ac940f1ab4d4661b6a49ccc63577e54d3b coq_8.18.0+dfsg-1build2_amd64.deb +8d166ae82cec28e6f20f175574cccb91f931b0add4cb1e4380c53d7999b415dd libcompiler-libs-ocaml-dev_4.14.1-1ubuntu1_amd64.deb +027c8fb39db20de4910f8a75e0b9a32c0fbc27c6f532375ed7604757f71c12a9 libcoq-core-ocaml_8.18.0+dfsg-1build2_amd64.deb +af139bb3af8c71b5e991944a61eef5bba28038a715f71146fa046241bb614b23 libcoq-stdlib_8.18.0+dfsg-1build2_amd64.deb +c22df5a71fc8c59ddcf5d3dd0d9f07eecb07440f7bb41f0681e4727dc1b76640 libfindlib-ocaml_1.9.6-1build4_amd64.deb +14f54d8fc3d643d3c92cecb61e10ca04cea5f81775adfdb62cba752bed563d06 libstdlib-ocaml-dev_4.14.1-1ubuntu1_amd64.deb +0cfd085866f8b215b22bb47c5da9ff9a04fddb25b75e131ba76542d8e3027287 libstdlib-ocaml_4.14.1-1ubuntu1_amd64.deb +b7319d0b5567916991fd2d76ad6e07eb41cba377f66c4979f5fbefbd90153861 libzarith-ocaml_1.13-2build4_amd64.deb +58efc8df3c84db7ca31a7b5312a60ec416ed417953882c0cbe108f69d1dd35d7 ocaml-base_4.14.1-1ubuntu1_amd64.deb +558065a8d99b61841471bb622784d01badeaadc85e91cf50d71aa88efff63888 ocaml-findlib_1.9.6-1build4_amd64.deb +3d7cdd56b28b26cfe6240d67dffecce84ecc7aed3448ccde4665f47678bbc315 ocaml-interp_4.14.1-1ubuntu1_amd64.deb +8f15e32a7fa98461a6d15e71643131d2e04cc62ee8c49435d43496f2590bf275 ocaml_4.14.1-1ubuntu1_amd64.deb diff --git a/scripts/atoma-ci-replay-toolchain.sh b/scripts/atoma-ci-replay-toolchain.sh index eb003cb..31db2b3 100644 --- a/scripts/atoma-ci-replay-toolchain.sh +++ b/scripts/atoma-ci-replay-toolchain.sh @@ -8,7 +8,9 @@ set -euo pipefail task="$RUNNER_TEMP/atoma-replay-toolchain" mkdir -p "$task" sudo apt-get update -sudo apt-get install -y --no-install-recommends coq=8.18.0+dfsg-1build2 jq libssl-dev pkg-config +sudo apt-get install -y --no-install-recommends jq libssl-dev pkg-config +# Coq comes from pinned, sha-checked packages, not a live apt resolve. +bash "$(dirname "${BASH_SOURCE[0]}")/atoma-provision-coq.sh" "$RUNNER_TEMP/atoma-coq-debs" rustup toolchain install 1.99.0 --profile minimal git init "$task/echidna" git -C "$task/echidna" remote add origin https://github.com/hyperpolymath/echidna.git diff --git a/scripts/atoma-provision-coq.sh b/scripts/atoma-provision-coq.sh new file mode 100644 index 0000000..4d49ac5 --- /dev/null +++ b/scripts/atoma-provision-coq.sh @@ -0,0 +1,120 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +# Install Coq 8.18.0 for CI from a pinned, sha-checked set of .debs instead of +# a live apt resolve (run 46426329421 failed on security.ubuntu.com 503s). +# +# atoma-provision-coq.sh [lock-file] +# atoma-provision-coq.sh --self-test-bad-sha [lock-file] +# +# The lock (default ci/coq-8.18.debs.sha256) lists every .deb with its sha256. +# Any missing file, any sha mismatch, a failed install or a wrong coqc version +# is a hard failure. Nothing is installed before every file has been verified. +set -euo pipefail + +here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +default_lock="$here/../ci/coq-8.18.debs.sha256" +primary=http://archive.ubuntu.com/ubuntu +# One fixed snapshot used only when the primary mirror fails for a file. +snapshot=https://snapshot.ubuntu.com/ubuntu/20241001T000000Z + +# deb file name -> pool directory (noble amd64; from `apt-cache show` Filename). +declare -A pool=( + ["coq_8.18.0+dfsg-1build2_amd64.deb"]=pool/universe/c/coq + ["libcoq-core-ocaml_8.18.0+dfsg-1build2_amd64.deb"]=pool/universe/c/coq + ["libcoq-stdlib_8.18.0+dfsg-1build2_amd64.deb"]=pool/universe/c/coq + ["libcompiler-libs-ocaml-dev_4.14.1-1ubuntu1_amd64.deb"]=pool/universe/o/ocaml + ["libstdlib-ocaml-dev_4.14.1-1ubuntu1_amd64.deb"]=pool/universe/o/ocaml + ["libstdlib-ocaml_4.14.1-1ubuntu1_amd64.deb"]=pool/universe/o/ocaml + ["ocaml-base_4.14.1-1ubuntu1_amd64.deb"]=pool/universe/o/ocaml + ["ocaml-interp_4.14.1-1ubuntu1_amd64.deb"]=pool/universe/o/ocaml + ["ocaml_4.14.1-1ubuntu1_amd64.deb"]=pool/universe/o/ocaml + ["libzarith-ocaml_1.13-2build4_amd64.deb"]=pool/universe/o/ocaml-zarith + ["libfindlib-ocaml_1.9.6-1build4_amd64.deb"]=pool/universe/f/findlib + ["ocaml-findlib_1.9.6-1build4_amd64.deb"]=pool/universe/f/findlib +) + +die() { echo "atoma-provision-coq: FAIL: $*" >&2; exit 1; } + +lock_files() { grep -v '^[[:space:]]*#' "$1" | awk 'NF { print $2 }'; } + +fetch_one() { + local f=$1 dir=$2 p=${pool[$1]:-} base + [[ -n $p ]] || die "no pool path recorded for $f" + for base in "$primary" "$snapshot"; do + if curl --fail --silent --show-error --location --proto '=http,https' \ + --connect-timeout 20 --max-time 300 --retry 5 --retry-all-errors \ + -o "$dir/$f.part" "$base/$p/$f"; then + mv "$dir/$f.part" "$dir/$f" + return 0 + fi + echo "atoma-provision-coq: $f unavailable from $base" >&2 + done + rm -f "$dir/$f.part" + die "could not download $f from the archive or the snapshot" +} + +fetch_missing() { + local cache=$1 lock=$2 f + mkdir -p "$cache" + while read -r f; do + if [[ -f $cache/$f ]]; then + echo "cached: $f" + else + echo "fetch: $f" + fetch_one "$f" "$cache" + fi + done < <(lock_files "$lock") +} + +# Hard failure on any missing file or mismatch. +verify() { + local cache=$1 lock=$2 + ( cd "$cache" && sha256sum --check --strict "$lock" ) +} + +if [[ ${1:-} == --self-test-bad-sha ]]; then + cache=${2:?usage: $0 --self-test-bad-sha [lock-file]} + lock=$(realpath "${3:-$default_lock}") + cache=$(realpath -m "$cache") + fetch_missing "$cache" "$lock" + work=$(mktemp -d) + trap 'rm -rf "$work"' EXIT + bad="$work/bad.sha256" + # Flip the first hex digit of the first entry (0 <-> 1 always changes it). + awk '!done && /^[0-9a-f]/ { $0 = (substr($0, 1, 1) == "0" ? "1" : "0") substr($0, 2); done = 1 } { print }' "$lock" > "$bad" + if cmp -s "$lock" "$bad"; then die "self-test could not corrupt the lock copy"; fi + victim=$(grep -v '^[[:space:]]*#' "$bad" | awk 'NF { print $2; exit }') + set +e + out=$(verify "$cache" "$bad" 2>&1) + rc=$? + set -e + echo "$out" + # The rejection must be the sha mismatch on the victim, not a side effect + # such as an unreadable file or a malformed lock line. + if [[ $rc -ne 0 && $out == *"$victim: FAILED"* && $out != *"open or read"* \ + && $out != *"improperly formatted"* ]]; then + echo "SELF-TEST PASS: corrupted sha for $victim was rejected (exit $rc)" + exit 0 + fi + echo "SELF-TEST FAIL: corrupted sha for $victim was NOT rejected as expected (exit $rc)" >&2 + exit 1 +fi + +cache=${1:?usage: $0 [lock-file]} +lock=$(realpath "${2:-$default_lock}") +cache=$(realpath -m "$cache") +[[ -f $lock ]] || die "lock file $lock not found" + +fetch_missing "$cache" "$lock" +verify "$cache" "$lock" || die "sha256 verification failed; refusing to install" +mapfile -t debs < <(lock_files "$lock") +(( ${#debs[@]} > 0 )) || die "lock lists no packages" +paths=() +for f in "${debs[@]}"; do paths+=("$cache/$f"); done +sudo dpkg -i "${paths[@]}" +dpkg-query -W coq +ver=$(coqc --version | head -n1) +echo "$ver" +[[ $ver == *"version 8.18.0"* ]] || die "coqc reports '$ver', expected 8.18.0" +echo "atoma-provision-coq: OK"