Skip to content
Merged
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
31 changes: 29 additions & 2 deletions .github/workflows/atoma.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,47 @@ jobs:
if-no-files-found: error
retention-days: 30

byte_translation:
name: Byte source translation validation
runs-on: ubuntu-24.04
timeout-minutes: 25
steps:
- uses: actions/checkout@v7.0.1
with:
persist-credentials: false
- name: Provision pinned Zig
run: bash scripts/atoma-download-zig.sh "$RUNNER_TEMP/atoma-translation-zig"
- name: Provision pinned replay tools
run: bash scripts/atoma-ci-replay-toolchain.sh
- name: Build the actual Atoma emitter
working-directory: tools/atoma
run: zig build
- name: Validate compiled models against the original source bytes
run: bash scripts/atoma-translation-gate.sh
- uses: actions/upload-artifact@v7.0.2
if: always()
with:
name: byte-translation-evidence-${{ github.sha }}
path: build/atoma-evidence/translation.*/
if-no-files-found: error
retention-days: 30

soundness:
name: Atoma soundness gate
needs: [core_soundness, heap_consumers]
needs: [core_soundness, heap_consumers, byte_translation]
if: ${{ always() }}
runs-on: ubuntu-24.04
timeout-minutes: 2
steps:
- name: Require both existing and heap-boundary qualification
- name: Require existing replay, heap pilots and byte translation validation
env:
CORE_RESULT: ${{ needs.core_soundness.result }}
HEAP_RESULT: ${{ needs.heap_consumers.result }}
TRANSLATION_RESULT: ${{ needs.byte_translation.result }}
run: |
test "$CORE_RESULT" = success
test "$HEAP_RESULT" = success
test "$TRANSLATION_RESULT" = success

gate:
name: CI/gate
Expand Down
4 changes: 4 additions & 0 deletions docs/decisions/ATOMA-BETA-SCALAR.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ The model replay remains target independent and its receipt remains INCOMPLETE.
The Zig frontend, lowering and compiler are still trusted for correspondence
with native execution. Proven and UAA retain their alpha proof and consumer
gates.

The follow-on link:ATOMA-BYTE-TRANSLATION.adoc[translation validation profile]
adds an independent check of the closed source and contract against the
compiled model.
42 changes: 42 additions & 0 deletions docs/decisions/ATOMA-BYTE-TRANSLATION.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: CC-BY-SA-4.0
= Independent translation validation for the byte source profile

The existing source replay audits a theorem whose statement is regenerated by
Atoma's emitter. A mistake shared by the emitter and the audit can survive
that check. The byte translation gate adds an independent interpretation of
the original source and contract bytes. It compares that interpretation with
the actual compiled model used by replay.

The new checker accepts a deliberately small subset of the experimental byte
profile. It reads a closed module with one exported function, a named byte
argument, C calling convention, one byte return expression, and an explicit
`@ensures` clause. Its independent grammar handles ASCII source, decimal byte
literals, variable references, grouping and wrapping addition. Unsupported
syntax is refused before a correspondence theorem can be issued.

For all inputs from 0 to 255, the compiled artifact's body must agree with the
raw-source evaluator and its specification must agree with the independently
parsed contract. The two comparisons are separate so an error in either the
body or contract translation can be diagnosed. The raw bytes and compiled
library contribute to the evidence identity. Coq checks the theorem and
coqchk verifies the libraries on the hosted runner.

The negative controls deliberately supply self-consistent compiled models.
One mistranslates a changed body while keeping the original contract. Another
mistranslates a changed contract while leaving the body alone. The semantic
comparisons must reject those models even though their internal model theorem
checks. A source edit also invalidates saved byte evidence, and unsupported
arithmetic must fail admission.

The checker admits at most 2,048 source bytes, including comments. Names use
letters and underscores within the profile, byte literals are decimal with
no leading zero, and the expression parser bounds grouping and addition
chains. A renamed function and a comment-only edit qualify independently.
The comment edit requires a new receipt because its byte identity changed.

This is translation validation for each checked artifact against the
independent byte semantics. The native witness from the first beta slice
still supplies execution evidence for the pinned Zig compiler and target.
General Zig parsing, compiler and native correspondence, wider types,
imports, memory and effects remain open. Receipts remain `INCOMPLETE`.
The required workflow retains the Proven and UAA source and native campaigns.
133 changes: 133 additions & 0 deletions scripts/atoma-translation-gate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
set -euo pipefail
export LC_ALL=C
root=$(cd "$(dirname "$0")/.." && pwd)
export ATOMA=${ATOMA:-$root/tools/atoma/zig-out/bin/atoma}
export COQC=${COQC:-coqc} COQCHK=${COQCHK:-coqchk}
replay="$root/scripts/atoma-replay.sh"
validate="$root/scripts/atoma-translation-validate.sh"
pilot="$root/examples/atoma/source-u8"
mkdir -p "$root/build/atoma-evidence"
work=$(mktemp -d "$root/build/atoma-evidence/translation.XXXXXX")
echo "Translation evidence directory: $work"

check_translation() {
local source=$1 case_dir="$work/$2"
mkdir "$case_dir"
"$ATOMA" source-coq "$source" > "$case_dir/generated.v"
bash "$replay" "$source" "$case_dir/generated.v" "$case_dir/replay"
bash "$validate" "$case_dir/replay/source.zig" "$case_dir/replay/AtomaProof.vo" "$case_dir/translation"
(cd "$case_dir/replay" && sha256sum -c inputs.sha256)
(cd "$case_dir/translation" && sha256sum -c inputs.sha256)
}

check_translation "$pilot/advance-five.zig" advance-five
cat > "$work/nudge.zig" <<'ZIG'
/// @ensures result == sample +% 7
export fn nudge_byte(sample: u8) callconv(.c) u8 {
return (7) +% (sample +% 247) +% 9;
}
ZIG
check_translation "$work/nudge.zig" nudge
cp "$work/nudge.zig" "$work/comment-change.zig"
printf '%s\n' '// Equivalent source with different bytes.' >> "$work/comment-change.zig"
check_translation "$work/comment-change.zig" comment-change
grep ' source\.zig$' "$work/nudge/translation/inputs.sha256" > "$work/comment-change/old-source.sha256"
(
cd "$work/comment-change/translation"
if sha256sum -c ../old-source.sha256 > ../old-source-check.txt 2>&1; then
echo 'FAIL old source digest accepted changed bytes' >&2
exit 1
fi
grep -qFx 'source.zig: FAILED' ../old-source-check.txt
)

# Model a common-mode emitter defect in both legacy generation and legacy
# audit. ECHIDNA, coqc and coqchk remain the genuine tools.
cat > "$work/paired-emitter" <<'SH'
#!/usr/bin/env bash
set -euo pipefail
[[ $# == 2 && -f $2 ]] || exit 2
case $1 in
source-coq) cat "$CONTROL_MODEL" ;;
source-coq-audit) cat "$CONTROL_AUDIT" ;;
*) exit 2 ;;
esac
SH
chmod +x "$work/paired-emitter"

expect_refusal() {
local case_dir=$1 source=$2 model=$3 verdict=$4
local translation="$case_dir/translation"
if bash "$validate" "$source" "$model" "$translation" > "$case_dir/refusal.log" 2>&1; then
echo "FAIL translation accepted $case_dir" >&2
exit 1
fi
grep -qFx 'TRANSLATION-REFUSED: source and compiled model did not validate' "$case_dir/refusal.log" \
|| { cat "$case_dir/refusal.log" >&2; return 1; }
[[ ! -e $translation/receipt.json && ! -e $translation/U8Translation.vo ]]
(
cd "$translation"
cmp -- "$source" source.zig
cmp -- "$model" AtomaProof.vo
sha256sum -c submitted.sha256
sha256sum -c dependencies.sha256
cat > Refusal.v <<COQ
Require AtomaProof SourceBytes U8Source.
Theorem refusal_reason :
U8Source.check SourceBytes.bytes AtomaProof.body AtomaProof.specification = $verdict.
Proof. vm_compute. reflexivity. Qed.
Print Assumptions refusal_reason.
Print Assumptions AtomaProof.atoma_u8.
COQ
timeout -k 5 120 "$COQC" -q -Q . '' Refusal.v > refusal-assumptions.txt 2> refusal-assumptions.stderr \
|| { cat refusal-assumptions.stderr >&2; exit 1; }
[[ $(grep -c '^Closed under the global context$' refusal-assumptions.txt) == 2 ]]
! grep -q '^Axioms:' refusal-assumptions.txt
timeout -k 5 120 "$COQCHK" -silent -Q . '' ScalarSource U8Source SourceBytes AtomaProof Refusal \
> refusal-coqchk.txt 2>&1 || { cat refusal-coqchk.txt >&2; exit 1; }
sha256sum -c submitted.sha256
sha256sum -c dependencies.sha256
sha256sum source.zig AtomaProof.vo ./*.v ./*.vo assumptions.stderr ../refusal.log \
refusal-assumptions.txt refusal-coqchk.txt > refusal.sha256
)
printf 'TRANSLATION-FALSIFIER-KILLED %s (%s)\n' "$(basename "$case_dir")" "$verdict"
}

wrong_model_control() {
local source=$1 case_dir="$work/$2" verdict=$3
local correct="$work/advance-five/replay"
mkdir "$case_dir"
"$ATOMA" source-coq "$source" > "$case_dir/actual-model.v"
"$ATOMA" source-coq-audit "$source" > "$case_dir/actual-audit.v"
# Preserve the true source marker while substituting the self-consistent
# advance-five model and its audit. A digest difference cannot kill it.
{
head -n 1 "$case_dir/actual-model.v"
tail -n +2 "$correct/AtomaProof.v"
} > "$case_dir/wrong-model.v"
{
head -n 1 "$case_dir/actual-audit.v"
tail -n +2 "$correct/Audit.v"
} > "$case_dir/wrong-audit.v"
CONTROL_MODEL="$case_dir/wrong-model.v" CONTROL_AUDIT="$case_dir/wrong-audit.v" \
ATOMA="$work/paired-emitter" bash "$replay" "$source" "$case_dir/wrong-model.v" "$case_dir/replay"
expect_refusal "$case_dir" "$case_dir/replay/source.zig" "$case_dir/replay/AtomaProof.vo" "$verdict"
(cd "$case_dir/replay" && sha256sum -c inputs.sha256)
}

wrong_model_control "$pilot/advance-five-wrong-body.zig" wrong-body 'Some (false, true)'
cat > "$work/wrong-contract.zig" <<'ZIG'
/// @ensures result == value +% 4
export fn advance_five(value: u8) callconv(.c) u8 {
return (value +% 253) +% 8;
}
ZIG
wrong_model_control "$work/wrong-contract.zig" wrong-contract 'Some (true, false)'
mkdir "$work/unsupported"
expect_refusal "$work/unsupported" "$pilot/advance-five-unsupported.zig" \
"$work/advance-five/replay/AtomaProof.vo" 'None'

echo 'TRANSLATION GATE PASS: validated raw bytes, equivalent edit, and three independent refusals; INCOMPLETE'
59 changes: 59 additions & 0 deletions scripts/atoma-translation-validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
set -euo pipefail
export LC_ALL=C
[[ $# == 3 ]] || { echo 'usage: atoma-translation-validate.sh SOURCE ATOMA_PROOF_VO NEW_EVIDENCE_DIRECTORY' >&2; exit 2; }
root=$(cd "$(dirname "$0")/.." && pwd)
coqc=$(command -v "${COQC:-coqc}") || { echo 'TRANSLATION-REFUSED: missing compiler' >&2; exit 1; }
coqchk=$(command -v "${COQCHK:-coqchk}") || { echo 'TRANSLATION-REFUSED: missing kernel checker' >&2; exit 1; }
coqc=$(realpath "$coqc")
coqchk=$(realpath "$coqchk")
fail() { echo "TRANSLATION-REFUSED: $*" >&2; exit 1; }
[[ -f $1 && -r $1 && -s $1 && $(wc -c < "$1") -le 2048 ]] || fail 'source must be a readable regular file of 1..2048 bytes'
[[ -f $2 && -r $2 && -s $2 ]] || fail 'compiled model must be a readable regular file'
source=$(realpath -- "$1")
model=$(realpath -- "$2")
out=$(realpath -m -- "$3")
mkdir -- "$out" || fail 'evidence directory must be new'
cp -- "$source" "$out/source.zig"
cp -- "$model" "$out/AtomaProof.vo"
for library in ScalarSource U8Source U8Translation; do
cp "$root/verification/atoma/consumer/coq/$library.v" "$out/"
done
cd "$out"
[[ -s source.zig && $(wc -c < source.zig) -le 2048 ]] || fail 'source snapshot is outside the byte limit'
{
printf '%s\n' 'From Coq Require Import List.' 'Import ListNotations.' 'Definition bytes : list nat := ['
od -An -v -tu1 -- source.zig | awk '{for (i=1; i<=NF; i++) {if (n++) printf "; "; printf "%s", $i} print ""}'
printf '%s\n' '].'
} > SourceBytes.v
sha256sum source.zig AtomaProof.vo SourceBytes.v ScalarSource.v U8Source.v U8Translation.v > submitted.sha256
for library in ScalarSource U8Source SourceBytes; do
timeout -k 5 120 "$coqc" -q -Q . '' "$library.v" > "$library.log" 2>&1 \
|| { cat "$library.log" >&2; fail "could not compile $library"; }
done
sha256sum ScalarSource.vo U8Source.vo SourceBytes.vo > dependencies.sha256
timeout -k 5 120 "$coqc" -q -Q . '' U8Translation.v > assumptions.txt 2> assumptions.stderr \
|| { cat assumptions.stderr >&2; fail 'source and compiled model did not validate'; }
[[ -s U8Translation.vo ]] || fail 'missing compiled translation capsule'
[[ $(grep -c '^Closed under the global context$' assumptions.txt) == 2 ]] || fail 'translation theorems are not closed'
! grep -q '^Axioms:' assumptions.txt || fail 'axioms in translation theorem closure'
timeout -k 5 120 "$coqchk" -silent -Q . '' ScalarSource U8Source SourceBytes AtomaProof U8Translation \
> coqchk.txt 2>&1 || { cat coqchk.txt >&2; fail 'compiled translation kernel check failed'; }
sha256sum -c submitted.sha256 > submitted-recheck.txt || fail 'source, model or checker changed'
sha256sum -c dependencies.sha256 > dependencies-recheck.txt || fail 'compiled checker dependencies changed'
cmp -s -- "$source" source.zig || fail 'source changed during validation'
cmp -s -- "$model" AtomaProof.vo || fail 'model changed during validation'
sha256sum source.zig AtomaProof.vo ./*.v ScalarSource.vo U8Source.vo SourceBytes.vo U8Translation.vo \
assumptions.txt assumptions.stderr coqchk.txt > inputs.sha256
sha256sum "$coqc" "$coqchk" > tools.sha256
source_digest=$(sha256sum source.zig | cut -d ' ' -f 1)
model_digest=$(sha256sum AtomaProof.vo | cut -d ' ' -f 1)
jq -cnS --arg source "$source_digest" --arg model "$model_digest" \
'{schema:"atoma.translation.u8/1",status:"INCOMPLETE",inputs_checked:256,
scope:"independent byte-profile body and postcondition agree with the compiled Coq model",
source_sha256:$source,model_sha256:$model,coqchk:"checked",assumptions:[],
zig_compiler_refinement:"unproved"}' > receipt.json.tmp
mv receipt.json.tmp receipt.json
echo 'TRANSLATION-CHECKED: 256 inputs; INCOMPLETE, Zig compiler refinement unproved'
Loading
Loading