Skip to content
Closed
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
45 changes: 45 additions & 0 deletions .github/workflows/atoma.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,41 @@ concurrency:
cancel-in-progress: true

jobs:
scalar:
name: Scalar source proof gate
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- uses: actions/checkout@v7.0.1
with:
persist-credentials: false
- 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
cd "$RUNNER_TEMP"
curl --proto '=https' --proto-redir '=https' -fL --retry 3 https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz -o scalar-zig.tar.xz
echo '02aa270f183da276e5b5920b1dac44a63f1a49e55050ebde3aecc9eb82f93239 scalar-zig.tar.xz' | sha256sum -c -
tar -xf scalar-zig.tar.xz
echo "$RUNNER_TEMP/zig-x86_64-linux-0.15.2" >> "$GITHUB_PATH"
curl --proto '=https' --proto-redir '=https' -fL --retry 3 https://github.com/leanprover/lean4/releases/download/v4.15.0/lean-4.15.0-linux.tar.zst -o scalar-lean.tar.zst
tar --zstd -xf scalar-lean.tar.zst
echo "$RUNNER_TEMP/lean-4.15.0-linux/bin" >> "$GITHUB_PATH"
mkdir -p "$GITHUB_WORKSPACE/build/scalar-proof-evidence"
sha256sum scalar-lean.tar.zst > "$GITHUB_WORKSPACE/build/scalar-proof-evidence/lean-archive.sha256"
- name: Agda then Lean and Coq, Cubical, source falsifiers
run: bash scripts/atoma-scalar-proof-gate.sh
- uses: actions/upload-artifact@v7.0.2
if: always()
with:
name: scalar-proof-evidence-${{ github.sha }}
path: build/scalar-proof-evidence/
if-no-files-found: error

soundness:
name: Atoma soundness gate
needs: [scalar]
runs-on: ubuntu-24.04
timeout-minutes: 45
steps:
Expand All @@ -40,3 +73,15 @@ jobs:
examples/atoma/frame-v1/witness/
if-no-files-found: error
retention-days: 30

gate:
name: CI/gate
needs: [soundness]
if: ${{ always() }}
runs-on: ubuntu-24.04
timeout-minutes: 2
steps:
- name: Require successful source, contract and proof checks
env:
SOUNDNESS_RESULT: ${{ needs.soundness.result }}
run: test "$SOUNDNESS_RESULT" = success
21 changes: 14 additions & 7 deletions docs/decisions/2026-11-16-consumer-boundary-proof-design.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ Probe inputs, in order: lone CR, lone LF, CRLF, `clean`, embedded CR in
`a\rZ`. Idris2 0.8.0 RefC output: `True True True False True`.
Zig 0.15.2 output: `false false true false false`, each with status 0.
This is executable evidence of disagreement, not just two models disagreeing.
Reproduce with `ZIG=/path/to/zig-0.15.2 IDRIS2=/path/to/idris2
bash tests/consumer-boundary/proven-header-probe.sh /path/to/proven`.
The diagnostic deliberately exits 1 on disagreement and retains its
input identities, build output and differing results outside the repository.
These are historical results for the pinned Proven revision above. To replay
that mismatch, use the diagnostic from Atoma commit
`8377513cb93beec96148c5995bec8aadb8e74c09` with Proven at `c13619f9a67a1b9e8234e22e22dae0940d2480cb`.
That diagnostic exits 1 on disagreement and retains the input identities,
build output and differing results outside the repository. The current
diagnostic instead requires the repaired RefC bundle builder and checks the
five matching rows; follow link:../../tests/consumer-boundary/README.adoc[its instructions]
with Proven at `24fd48e954b7c124a195412a35c9c0be6f54990b` or a compatible later repair.

== Decision 1: preserve boundary semantics, not spelling conventions

Expand Down Expand Up @@ -177,9 +181,12 @@ behavioral disagreement, not the unproved source/compiler refinement relation.
The adapter's finite decoder now has both decoding laws and its partial
registration model has a no-fabricated-handler theorem. Its executable RefC
matrix covers all 256 tags and four registration states. The actual Zig
registration table and network transports are still pending. See
link:../../tests/consumer-boundary/README.adoc[the consumer diagnostic] for
reproduction and the explicit receipt boundary.
registration table and network transports are still pending. Reproduce that
matrix at unified-api-adapter commit `259eff356e72fde2dadb1e144442f7a736da3601`
with `bash scripts/check-registry.sh`; see
link:https://github.com/hyperpolymath/unified-api-adapter/blob/259eff356e72fde2dadb1e144442f7a736da3601/scripts/check-registry.sh[the pinned registry gate].
The link:../../tests/consumer-boundary/README.adoc[consumer diagnostic]
documents only the Proven experiment and its explicit receipt boundary.

[cols="1,3,4",options="header"]
|===
Expand Down
19 changes: 19 additions & 0 deletions scripts/atoma-scalar-capsule.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
# Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
# Independently bind the emitted literal bytes/table to the original inputs.
set -euo pipefail
[[ $# == 3 ]] || { echo 'usage: atoma-scalar-capsule.sh SOURCE TABLE PROOF' >&2; exit 2; }
expected=$(mktemp)
actual=$(mktemp)
trap 'rm -f "$expected" "$actual"' EXIT
{
printf 'Definition source_bytes : list nat := ['
od -An -v -tu1 "$1" | awk '{for(i=1;i<=NF;i++){printf "%s%s", sep, $i; sep="; "}}'
printf '].\nDefinition specification : list N := ['
awk 'NF != 2 || $1 !~ /^[0-9]+$/ || $2 !~ /^[0-9]+$/ || $1 != NR-1 {exit 1}
{printf "%s%s%%N", sep, $2; sep="; "} END {if(NR != 256) exit 1}' "$2"
printf '].\n'
} > "$expected"
grep '^Definition \(source_bytes\|specification\) :' "$3" > "$actual"
cmp -s "$expected" "$actual" || { echo 'SCALAR-REFUSED: capsule differs from source/contract bytes' >&2; exit 1; }
69 changes: 69 additions & 0 deletions scripts/atoma-scalar-proof-gate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
# Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
# Proof development and adversarial controls; consumer CI adds Idris authority.
set -euo pipefail
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
cd "$root"
for tool in zig agda lean coqc coqchk; do command -v "$tool" >/dev/null; done
[[ $(zig version) == 0.15.2 ]]
[[ $(lean --version) == 'Lean (version 4.15.0,'* ]]
out="$root/build/scalar-proof-evidence"
mkdir -p "$out"
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
cp verification/atoma/consumer/agda/ScalarReflection.agda "$work/"
cp verification/atoma/consumer/agda/ScalarReflectionCubical.agda "$work/"
cp verification/atoma/consumer/lean4/ScalarReflection.lean "$work/"
cp verification/atoma/consumer/coq/ScalarSource.v "$work/"
(
cd "$work"
agda --safe --without-K --cubical-compatible --double-check ScalarReflection.agda
lean ScalarReflection.lean > "$out/lean-assumptions.txt" 2>&1
[[ $(grep -c 'does not depend on any axioms' "$out/lean-assumptions.txt") == 2 ]]
coqc -q ScalarSource.v > "$out/coq-assumptions.txt" 2>&1
[[ $(grep -c '^Closed under the global context$' "$out/coq-assumptions.txt") == 2 ]]
coqchk -silent -Q . '' ScalarSource > "$out/coqchk.txt" 2>&1
agda --safe --cubical --double-check ScalarReflectionCubical.agda
) > "$out/theory.txt" 2>&1
(cd tools/atoma && zig build test && zig build)
atoma="$root/tools/atoma/zig-out/bin/atoma"
# These fixture tables are test data only. Real consumer receipts require fresh
# tables from the pinned Idris ABI modules; never promote these fixtures.
awk 'BEGIN {for(i=0;i<256;i++) printf "%d %.0f\n",i,i*4294967296+1}' > "$work/encode.tsv"
awk 'BEGIN {for(i=0;i<256;i++) print i,(i>=1 && i<=9 ? 1 : 0)}' > "$work/known.tsv"
for fixture in encode known; do
"$atoma" scalar-coq "tests/consumer-scalar/$fixture.zig" "$work/$fixture.tsv" > "$work/AtomaProof.v"
bash scripts/atoma-scalar-capsule.sh "tests/consumer-scalar/$fixture.zig" "$work/$fixture.tsv" "$work/AtomaProof.v"
(cd "$work" && coqc -q AtomaProof.v && coqchk -silent -Q . '' AtomaProof) > "$out/$fixture.txt" 2>&1
"$atoma" scalar-coq-audit "tests/consumer-scalar/$fixture.zig" "$work/$fixture.tsv" > "$work/Audit.v"
(cd "$work" && coqc -q Audit.v) > "$out/$fixture-audit.txt" 2>&1
[[ $(grep -c '^Closed under the global context$' "$out/$fixture-audit.txt") == 2 ]]
done
reject_proof() {
local name=$1 source=$2 table=$3
"$atoma" scalar-coq "$source" "$table" > "$work/Bad.v"
if (cd "$work" && coqc -q Bad.v) > "$out/$name.txt" 2>&1; then
echo "FAIL accepted $name" >&2; exit 1
fi
grep -q 'Unable to unify' "$out/$name.txt"
}
sed 's/<< 32/<< 31/' tests/consumer-scalar/encode.zig > "$work/shift.zig"
reject_proof wrong-shift "$work/shift.zig" "$work/encode.tsv"
sed 's/| 1/| 0/' tests/consumer-scalar/encode.zig > "$work/tag.zig"
reject_proof wrong-tag "$work/tag.zig" "$work/encode.tsv"
sed 's/<= 9/<= 10/' tests/consumer-scalar/known.zig > "$work/range.zig"
reject_proof wrong-range "$work/range.zig" "$work/known.tsv"
cat tests/consumer-scalar/known.zig > "$work/import.zig"
printf '\nconst hidden = @import("hidden.zig");\n' >> "$work/import.zig"
reject_proof unsupported-import "$work/import.zig" "$work/known.tsv"
cp "$work/known.tsv" "$work/wrong-contract.tsv"
sed -i 's/^9 1$/9 0/' "$work/wrong-contract.tsv"
reject_proof wrong-contract tests/consumer-scalar/known.zig "$work/wrong-contract.tsv"
"$atoma" scalar-coq tests/consumer-scalar/known.zig "$work/known.tsv" > "$work/stale.v"
if bash scripts/atoma-scalar-capsule.sh "$work/range.zig" "$work/known.tsv" "$work/stale.v" > "$out/stale-source.txt" 2>&1; then
echo 'FAIL accepted stale source capsule' >&2; exit 1
fi
grep -q 'capsule differs' "$out/stale-source.txt"
sha256sum verification/atoma/consumer/{coq,agda,lean4}/* tools/atoma/src/scalar.zig > "$out/inputs.sha256"
echo 'SCALAR THEORY PASS: finite reflection and raw-source fixtures; consumer and compiler boundaries remain separate'
57 changes: 57 additions & 0 deletions scripts/atoma-scalar-replay.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
# Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
set -euo pipefail
[[ $# == 3 ]] || { echo 'usage: atoma-scalar-replay.sh SOURCE TABLE NEW_EVIDENCE_DIRECTORY' >&2; exit 2; }
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
ATOMA=${ATOMA:-$root/tools/atoma/zig-out/bin/atoma}
fail() { echo "SCALAR-REPLAY-REFUSED: $*" >&2; exit 1; }
for tool in "$ATOMA" echidna coqc coqchk jq timeout sha256sum; do
command -v "$tool" >/dev/null || fail "missing tool: $tool"
done
ATOMA=$(realpath "$(command -v "$ATOMA")")
source_path=$(realpath "$1")
table_path=$(realpath "$2")
out=$(realpath -m "$3")
mkdir "$out" || fail 'evidence directory must be new'
cp "$source_path" "$out/source.zig"
cp "$table_path" "$out/contract.tsv"
cp "$root/verification/atoma/consumer/coq/ScalarSource.v" "$out/"
"$ATOMA" scalar-coq "$out/source.zig" "$out/contract.tsv" > "$out/AtomaProof.v"
bash "$root/scripts/atoma-scalar-capsule.sh" "$out/source.zig" "$out/contract.tsv" "$out/AtomaProof.v"
cd "$out"
coqc --version > coqc-version.txt
case $(head -n 1 coqc-version.txt) in
'The Coq Proof Assistant, version 8.18.0'|'The Rocq Prover, version 9.2') ;;
*) fail 'unsupported Coq/Rocq profile' ;;
esac
timeout -k 5 120 coqc -q ScalarSource.v > library-assumptions.txt 2>&1
[[ $(grep -c '^Closed under the global context$' library-assumptions.txt) == 2 ]]
checker_digest=$(sha256sum ScalarSource.vo)
timeout -k 5 120 echidna prove "$out/AtomaProof.v" --prover coq --timeout 90 --output json > echidna.json 2> echidna.stderr \
|| fail 'ECHIDNA did not verify the source interpretation'
jq -e -s --arg goal "$out/AtomaProof.v" '
length == 1 and (.[0] | .schema == "echidna.prove.result/1" and
.status == "verified" and .prover == "Coq" and .goal == $goal and
.trust.axioms == [] and .trust.confidence == null)' echidna.json >/dev/null
[[ -s AtomaProof.vo ]] || fail 'missing compiled proof'
[[ $(sha256sum ScalarSource.vo) == "$checker_digest" ]] || fail 'backend changed the independently compiled source checker'
timeout -k 5 120 coqchk -silent -Q . '' ScalarSource AtomaProof > coqchk.txt 2>&1
"$ATOMA" scalar-coq-audit source.zig contract.tsv > Audit.v
bash "$root/scripts/atoma-scalar-capsule.sh" source.zig contract.tsv Audit.v
timeout -k 5 120 coqc -q -Q . '' Audit.v > assumptions.txt 2>&1
[[ $(grep -c '^Closed under the global context$' assumptions.txt) == 2 ]] || fail 'unexpected assumption closure'
! grep -q '^Axioms:' assumptions.txt
cmp -s source.zig "$source_path" || fail 'source changed during replay'
cmp -s contract.tsv "$table_path" || fail 'contract changed during replay'
cmp -s ScalarSource.v "$root/verification/atoma/consumer/coq/ScalarSource.v" || fail 'checker changed during replay'
bash "$root/scripts/atoma-scalar-capsule.sh" source.zig contract.tsv AtomaProof.v
sha256sum source.zig contract.tsv ScalarSource.v ScalarSource.vo AtomaProof.v AtomaProof.vo Audit.v Audit.vo echidna.json coqchk.txt assumptions.txt > inputs.sha256
for tool in "$ATOMA" echidna coqc coqchk; do sha256sum "$(command -v "$tool")"; done > tools.sha256
jq -cnS --arg source "$(sha256sum source.zig | cut -d ' ' -f 1)" \
--arg contract "$(sha256sum contract.tsv | cut -d ' ' -f 1)" \
'{schema:"atoma.scalar.source/1",status:"INCOMPLETE",scope:"closed scalar source interpretation",
source_sha256:$source,contract_sha256:$contract,inputs:256,source_parser:"checked-in-Coq",
coqchk:"checked",assumptions:[],compiler_refinement:"unproved",
contract_authority:"caller must bind the table producer; see consumer evidence"}' > receipt.json
echo 'SCALAR-SOURCE-CHECKED: original bytes independently interpreted; compiler and foreign-boundary obligations remain'
7 changes: 7 additions & 0 deletions tests/consumer-boundary/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
Run `bash tests/consumer-boundary/proven-header-probe.sh /path/to/proven` with
Idris2 `b6cbc25d5cd2ef2a250556266fd7b68dfc360f8b` and Zig 0.15.2 on native
Linux x86_64 GNU. `IDRIS2`, `ZIG` and `EVIDENCE_DIR` may select explicit paths.
The repaired experiment was checked against Proven commit
`24fd48e954b7c124a195412a35c9c0be6f54990b`; older revisions without
`scripts/build-header-refc.sh` cannot run this version of the diagnostic.
To reproduce the historical mismatch at Proven `c13619f9a67a1b9e8234e22e22dae0940d2480cb`,
use this script from Atoma `8377513cb93beec96148c5995bec8aadb8e74c09` instead.
For that historical script, set both `IDRIS2` and `ZIG` to absolute executable
paths; its directory changes do not preserve relative tool overrides.

The diagnostic compiles the existing Idris String predicate independently,
builds Proven's actual RefC byte kernel and SDK bundle, then links the exported
Expand Down
13 changes: 11 additions & 2 deletions tests/consumer-boundary/proven-header-probe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@
# Execute the actual Idris predicate and Zig export, not handwritten oracles.
# A disagreement is exit 1. This is a diagnostic, not a proof certificate.
set -euo pipefail
# A caller's CDPATH must not add stdout to captured directory resolutions.
unset CDPATH
proven=${1:?usage: proven-header-probe.sh /path/to/proven}
proven=$(cd "$proven" && pwd)
zig=${ZIG:-zig}
idris=${IDRIS2:-idris2}
command -v "$zig" >/dev/null
command -v "$idris" >/dev/null
# Resolve overrides before any subshell changes directory. Preserve the
# executable's basename (Idris wrappers may locate their data through $0).
zig=$(command -v "$zig")
zig=$(cd "$(dirname "$zig")" && printf '%s/%s' "$PWD" "$(basename "$zig")")
idris=$(command -v "$idris")
idris=$(cd "$(dirname "$idris")" && printf '%s/%s' "$PWD" "$(basename "$idris")")
evidence=${EVIDENCE_DIR:-$(mktemp -d -t atoma-header-evidence.XXXXXXXX)}
mkdir -p "$evidence"
evidence=$(cd "$evidence" && pwd)
Expand All @@ -23,6 +29,9 @@ cp -R "$proven/src/Proven" "$work/src/Proven"
"$zig" version
git -C "$proven" diff --stat
sha256sum "$proven/src/Proven/SafeHeader/Types.idr" "$proven/src/Proven/Core.idr" "$proven/src/Proven/SafeHeader/ByteKernel.idr" "$proven/ffi/zig/src/core.zig" "$proven/ffi/zig/src/header_refc.zig" "$proven/ffi/zig/src/main_refc.zig"
if [[ -d "$proven/ffi/zig/src/refc" ]]; then
find "$proven/ffi/zig/src/refc" -type f -name '*.zig' -exec sha256sum {} +
fi
} > "$evidence/inputs.log"
cat > "$work/src/AtomaHeaderProbe.idr" <<'IDRIS'
module AtomaHeaderProbe
Expand Down
5 changes: 5 additions & 0 deletions tests/consumer-scalar/encode.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
pub fn encodeWord(value: u8) u64 {
return (@as(u64, value) << 32) | 1;
}
5 changes: 5 additions & 0 deletions tests/consumer-scalar/known.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-License-Identifier: MPL-2.0
// Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
pub fn known(tag: u8) bool {
return tag >= 1 and tag <= 9;
}
2 changes: 1 addition & 1 deletion tools/atoma/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn build(b: *std.Build) void {
run_step.dependOn(&run_cmd.step);

const test_step = b.step("test", "Run the unit tests");
for ([_][]const u8{ "src/canon.zig", "src/frontend.zig", "src/vc.zig", "src/source.zig" }) |path| {
for ([_][]const u8{ "src/canon.zig", "src/frontend.zig", "src/vc.zig", "src/source.zig", "src/scalar.zig" }) |path| {
const unit_tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path(path),
Expand Down
25 changes: 23 additions & 2 deletions tools/atoma/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const canon = @import("canon.zig");
const frontend = @import("frontend.zig");
const vc = @import("vc.zig");
const source = @import("source.zig");
const scalar = @import("scalar.zig");

const gpa = std.heap.page_allocator;

Expand Down Expand Up @@ -71,7 +72,7 @@ fn sourceReport(comptime fmt: []const u8, args: anytype) void {
}

fn usage() noreturn {
sayLine("usage: atoma <canon|hash|vc-hash|dk-hash|src-hash|extract|check|vc|source-vc|source-coq|source-coq-audit|source-check|equiv|mutate|ops|selftest> [args]");
sayLine("usage: atoma <canon|hash|vc-hash|dk-hash|src-hash|extract|check|vc|source-vc|source-coq|source-coq-audit|source-check|scalar-coq|scalar-coq-audit|equiv|mutate|ops|selftest> [args]");
std.process.exit(2);
}

Expand All @@ -85,7 +86,27 @@ pub fn main() !void {
if (args.len < 2) usage();
const cmd = args[1];

if (std.mem.eql(u8, cmd, "source-vc") or std.mem.eql(u8, cmd, "source-coq") or std.mem.eql(u8, cmd, "source-coq-audit") or std.mem.eql(u8, cmd, "source-check")) {
if (std.mem.eql(u8, cmd, "scalar-coq") or std.mem.eql(u8, cmd, "scalar-coq-audit")) {
if (args.len != 4) usage();
const src = readFile(args[2]) catch |e| {
std.debug.print("SCALAR-IO-ERROR: {s}\n", .{@errorName(e)});
std.process.exit(3);
};
const table = readFile(args[3]) catch |e| {
std.debug.print("SCALAR-IO-ERROR: {s}\n", .{@errorName(e)});
std.process.exit(3);
};
var out = std.Io.Writer.Allocating.init(gpa);
defer out.deinit();
scalar.emit(&out.writer, src, table, std.mem.eql(u8, cmd, "scalar-coq-audit")) catch |e| {
std.debug.print("SCALAR-REFUSED: {s}\n", .{@errorName(e)});
std.process.exit(1);
};
std.fs.File.stdout().writeAll(out.written()) catch |e| {
std.debug.print("SCALAR-IO-ERROR: {s}\n", .{@errorName(e)});
std.process.exit(3);
};
} else if (std.mem.eql(u8, cmd, "source-vc") or std.mem.eql(u8, cmd, "source-coq") or std.mem.eql(u8, cmd, "source-coq-audit") or std.mem.eql(u8, cmd, "source-check")) {
if (args.len != 3) usage();
const src = readFile(args[2]) catch |e| {
print("SOURCE-IO-ERROR {s}: {s}\n", .{ args[2], @errorName(e) });
Expand Down
Loading
Loading