From b021bfb1558a654eddc16167181eb4be9cc565de Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 30 Nov 2026 10:10:24 +0000 Subject: [PATCH 1/2] Bind the validated byte model to the linked Zig export --- .github/workflows/atoma.yml | 4 +- docs/decisions/ATOMA-BYTE-TRANSLATION.adoc | 49 +++- examples/atoma/source-u8/native-observer.zig | 19 ++ scripts/atoma-native-byte.sh | 267 +++++++++++++++++++ scripts/atoma-translation-gate.sh | 114 ++++++++ verification/atoma/consumer/coq/U8Native.v | 36 +++ verification/atoma/consumer/coq/U8Source.v | 9 +- 7 files changed, 487 insertions(+), 11 deletions(-) create mode 100644 examples/atoma/source-u8/native-observer.zig create mode 100644 scripts/atoma-native-byte.sh create mode 100644 verification/atoma/consumer/coq/U8Native.v diff --git a/.github/workflows/atoma.yml b/.github/workflows/atoma.yml index 9962460..55bbdc2 100644 --- a/.github/workflows/atoma.yml +++ b/.github/workflows/atoma.yml @@ -218,7 +218,7 @@ jobs: - name: Build the actual Atoma emitter working-directory: tools/atoma run: zig build - - name: Validate compiled models against the original source bytes + - name: Validate the source model and replay the compiled native export run: bash scripts/atoma-translation-gate.sh - uses: actions/upload-artifact@v7.0.2 if: always() @@ -235,7 +235,7 @@ jobs: runs-on: ubuntu-24.04 timeout-minutes: 2 steps: - - name: Require existing replay, heap pilots and byte translation validation + - name: Require existing replay, heap pilots and native byte validation env: CORE_RESULT: ${{ needs.core_soundness.result }} HEAP_RESULT: ${{ needs.heap_consumers.result }} diff --git a/docs/decisions/ATOMA-BYTE-TRANSLATION.adoc b/docs/decisions/ATOMA-BYTE-TRANSLATION.adoc index 0fd6550..7c8a4d2 100644 --- a/docs/decisions/ATOMA-BYTE-TRANSLATION.adoc +++ b/docs/decisions/ATOMA-BYTE-TRANSLATION.adoc @@ -34,9 +34,46 @@ 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. +== Native byte evidence + +The native gate builds the accepted source snapshot with Zig 0.15.2 for +`x86_64-linux-musl`, using baseline CPU, Debug mode, LLVM and disabled LTO. +The gate checks the translation manifest and the receipt's source and compiled +model identities before building. It finds the unique defined global function +in the ELF object and checks that a separately compiled Zig observer refers +to that symbol as an undefined external. The observer object supplies the Zig +Linux entry point. The gate links the two objects statically without libc and +checks that the executable has no ELF interpreter or shared library +dependencies. The observer calls the export through the C calling convention +and writes exactly one result byte for each input in ascending order from 0 +to 255. The observer has no model or +expected values. Coq checks that the ELF symbol matches the name in the admitted +source and that the entire observed vector equals the compiled model's body. +The per-input theorem ties the vector entries to the model's body and +specification and uses the independent source interpretation theorem. The gate +audits the assumptions and runs `coqchk` on the compiled proof closure. +Before proof and during offline replay, a separate decoder restores the byte +list from the generated Coq input and checks it against the raw trace. + +The required byte translation job checks `advance_five` and the separately +named `nudge_byte`. It also checks that the correct model rejects a freshly +compiled same-symbol wrong body at input 0 and a changed trace at input 255, +and that a 255-byte trace is refused before proof. Substituting a compiled Coq +model, changing even comment-only source bytes, or replacing the recorded +executable invalidates the corresponding evidence. The required workflow +retains the Proven and UAA source and native campaigns. + +On x86-64 Linux with a compatible Coq kernel checker, replay an authenticated +native evidence directory downloaded from its hosted run with +`bash scripts/atoma-native-byte.sh replay PATH_TO_NATIVE_EVIDENCE`. Replay checks +the receipt and relative file digests, regenerates the Coq data input from the +raw trace, checks the compiled proof closure, and runs a copy of the archived +executable with execute permission restored. Its output must match byte for +byte. The receipt binds the build commands, tool digests, objects, executable, +raw trace and proofs. The original hosted receipt and manifest are provenance +inputs and must come from a trusted source before replay executes the binary. + +The `INCOMPLETE` receipt covers one artifact and one execution profile. The +observation depends on the Zig toolchain, linker, collector, host and raw-byte +capture. Coq checks the captured data. General compiler and ABI refinement, +other targets and modes, imports, memory, effects and wider types remain open. diff --git a/examples/atoma/source-u8/native-observer.zig b/examples/atoma/source-u8/native-observer.zig new file mode 100644 index 0000000..27623d6 --- /dev/null +++ b/examples/atoma/source-u8/native-observer.zig @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MPL-2.0 +// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +const std = @import("std"); + +comptime { + _ = std.start; +} + +const Export = struct { + extern fn @"ATOMA_EXPORT"(input: u8) callconv(.c) u8; +}; + +pub fn main() !void { + var trace: [256]u8 = undefined; + for (&trace, 0..) |*result, input| { + result.* = Export.@"ATOMA_EXPORT"(@intCast(input)); + } + try std.fs.File.stdout().writeAll(&trace); +} diff --git a/scripts/atoma-native-byte.sh b/scripts/atoma-native-byte.sh new file mode 100644 index 0000000..7076853 --- /dev/null +++ b/scripts/atoma-native-byte.sh @@ -0,0 +1,267 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: MPL-2.0 +# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell +# The public check builds only the source snapshot that passed translation. + +native_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +native_flags=(-target x86_64-linux-musl -mcpu=baseline -O Debug -fllvm -fno-lto) +native_libraries=(ScalarSource U8Source SourceBytes AtomaProof U8Translation NativeTrace U8Native) +native_translation_files=( + source.zig AtomaProof.vo ScalarSource.{v,vo} U8Source.{v,vo} + SourceBytes.{v,vo} U8Translation.{v,vo} assumptions.txt assumptions.stderr coqchk.txt +) + +native_fail() { echo "NATIVE-BYTE-REFUSED: $*" >&2; exit 1; } +native_tool() { + local found + found=$(command -v "$1") || native_fail "missing tool: $1" + realpath -- "$found" +} + +native_digest() { sha256sum -- "$1" | cut -d ' ' -f 1; } + +native_check_translation() { + sha256sum -c translation-inputs.sha256 > translation-recheck.txt \ + || { cat translation-recheck.txt >&2; native_fail 'translation inputs changed'; } + jq -e -s --arg source "$(native_digest source.zig)" --arg model "$(native_digest AtomaProof.vo)" ' + length == 1 and (.[0] | + .schema == "atoma.translation.u8/1" and .status == "INCOMPLETE" and + .inputs_checked == 256 and .source_sha256 == $source and .model_sha256 == $model and + .coqchk == "checked" and .assumptions == [] and .zig_compiler_refinement == "unproved") + ' translation-receipt.json > /dev/null || native_fail 'translation receipt does not identify this source and model' +} + +native_prepare() ( + local translation=$1 out=$2 + mkdir -- "$out" || native_fail 'evidence directory must be new' + local file + for file in "${native_translation_files[@]}"; do + cp -- "$translation/$file" "$out/$file" + done + cp -- "$translation/inputs.sha256" "$out/translation-inputs.sha256" + cp -- "$translation/receipt.json" "$out/translation-receipt.json" + cp -- "$native_root/verification/atoma/consumer/coq/U8Native.v" "$out/U8Native.v" + cp -- "$native_root/examples/atoma/source-u8/native-observer.zig" "$out/observer-template.zig" + cd "$out" + native_check_translation + sha256sum "${native_translation_files[@]}" translation-{inputs.sha256,receipt.json,recheck.txt} \ + observer-template.zig U8Native.v > accepted.sha256 +) + +native_build() ( + local out=$1 build_source=$2 zig elf coqc coqchk symbol + zig=$(native_tool "${ZIG:-zig}") + elf=$(native_tool readelf) + coqc=$(native_tool "${COQC:-coqc}") + coqchk=$(native_tool "${COQCHK:-coqchk}") + cd "$out" + sha256sum -c accepted.sha256 > /dev/null || native_fail 'accepted inputs changed before build' + uname -sm > host.txt + [[ $(cat host.txt) == 'Linux x86_64' ]] || native_fail 'x86-64 Linux execution is required' + "$zig" version > zig-version.txt + [[ $(cat zig-version.txt) == 0.15.2 ]] || native_fail 'Zig 0.15.2 is required' + printf '%s %s\n' "$(native_digest "$zig")" zig "$(native_digest "$elf")" readelf \ + "$(native_digest "$coqc")" coqc "$(native_digest "$coqchk")" coqchk > tool-digests.txt + { + printf 'zig build-obj %s %s -femit-bin=export.o\n' "$build_source" "${native_flags[*]}" + printf 'zig build-obj observer.zig %s -femit-bin=observer.o\n' "${native_flags[*]}" + printf 'zig build-exe observer.o export.o %s -static -femit-bin=native-observer\n' "${native_flags[*]}" + } > build-commands.txt + sha256sum -- "$build_source" > build-source.sha256 + timeout -k 5 120 "$zig" build-obj "$build_source" "${native_flags[@]}" -femit-bin=export.o \ + > export-build.log 2>&1 || { cat export-build.log >&2; native_fail 'export build failed'; } + "$elf" --wide --file-header --syms export.o > export-elf.txt + # The capsule ties the symbol found in the ELF table to the accepted source. + symbol=$(awk '$4 == "FUNC" && $5 == "GLOBAL" && $6 == "DEFAULT" && $7 != "UND" {print $8}' export-elf.txt) + [[ $symbol =~ ^[A-Za-z_]+$ ]] || native_fail 'expected exactly one defined global ELF function' + printf '%s\n' "$symbol" > export-symbol.txt + sed "s/@\"ATOMA_EXPORT\"/@\"$symbol\"/g" observer-template.zig > observer.zig + timeout -k 5 120 "$zig" build-obj observer.zig "${native_flags[@]}" -femit-bin=observer.o \ + > observer-build.log 2>&1 || { cat observer-build.log >&2; native_fail 'observer build failed'; } + "$elf" --wide --file-header --syms observer.o > observer-elf.txt + awk -v symbol="$symbol" '$5 == "GLOBAL" && $8 == symbol { seen++; if ($7 == "UND") undefined++ } + END { exit !(seen == 1 && undefined == 1) }' observer-elf.txt \ + || native_fail 'observer lacks the required external reference' + awk '$4 == "FUNC" && $5 == "GLOBAL" && $7 != "UND" && $8 == "_start" { found++ } + END { exit !(found == 1) }' observer-elf.txt || native_fail 'observer lacks the Zig Linux entry point' + sha256sum export.o observer.o > link-inputs.sha256 + timeout -k 5 120 "$zig" build-exe observer.o export.o "${native_flags[@]}" -static -femit-bin=native-observer \ + > link.log 2>&1 || { cat link.log >&2; native_fail 'observer link failed'; } + "$elf" --wide --file-header --program-headers --dynamic --syms native-observer > executable-elf.txt + awk -v symbol="$symbol" '$4 == "FUNC" && $5 == "GLOBAL" && $7 != "UND" && $8 == symbol { found++ } + END { exit !(found == 1) }' executable-elf.txt || native_fail 'linked export was not found' + awk '$1 == "INTERP" || $2 == "(NEEDED)" { dependency = 1 } + END { exit dependency }' executable-elf.txt || native_fail 'observer has an ELF interpreter or shared library dependency' + sha256sum -c accepted.sha256 > /dev/null || native_fail 'accepted inputs changed during build' + sha256sum -c build-source.sha256 > /dev/null || native_fail 'compiled source changed during build' + sha256sum -c link-inputs.sha256 > /dev/null || native_fail 'link inputs changed during build' + [[ $(native_digest "$zig") == "$(awk '$2 == "zig" {print $1}' tool-digests.txt)" ]] \ + || native_fail 'Zig executable changed during build' + sha256sum build-commands.txt build-source.sha256 link-inputs.sha256 host.txt zig-version.txt tool-digests.txt \ + export.o export-{build.log,elf.txt,symbol.txt} observer.{zig,o} observer-{build.log,elf.txt} \ + native-observer executable-elf.txt link.log > native-build.sha256 +) + +native_observe() ( + cd "$1" + sha256sum -c native-build.sha256 > /dev/null || native_fail 'native build evidence changed before execution' + timeout -k 5 30 ./native-observer > trace.bin 2> trace.stderr \ + || { cat trace.stderr >&2; native_fail 'native observer execution failed'; } + sha256sum -c native-build.sha256 > /dev/null || native_fail 'native build evidence changed during execution' +) + +native_trace_source() { + local symbol + symbol=$(cat export-symbol.txt) + [[ $symbol =~ ^[A-Za-z_]+$ ]] || native_fail 'invalid export symbol' + [[ -f trace.bin && $(wc -c < trace.bin) -eq 256 ]] || native_fail 'trace must contain exactly 256 bytes' + printf '%s\n' 'From Coq Require Import List String.' 'Import ListNotations.' 'Open Scope string_scope.' + printf 'Definition symbol : string := "%s".\nDefinition bytes : list nat := [\n' "$symbol" + od -An -v -tu1 -- trace.bin | awk ' + {for (i=1; i<=NF; i++) {if (n++) printf "; "; printf "%s", $i} print ""}' + printf '%s\n' '].' +} + +native_decode_trace() ( + export LC_ALL=C + local input='' bytes index byte escaped='' + local prefix=$'From Coq Require Import List String.\nImport ListNotations.\nOpen Scope string_scope.\n' + local symbol='^Definition symbol : string := "[A-Za-z_]+"[.]' + local opening=$'\nDefinition bytes : list nat := [\n' closing=$'\n].\n' + local decimal='^[[:space:]]*(0|[1-9][0-9]{0,2})[[:space:]]*' + if IFS= read -r -d '' input < "$1"; then + native_fail 'Coq trace source contains a NUL' + fi + [[ $input == "$prefix"* ]] || native_fail 'malformed Coq trace header' + input=${input#"$prefix"} + [[ $input =~ $symbol ]] || native_fail 'malformed Coq trace symbol' + input=${input:${#BASH_REMATCH[0]}} + [[ $input == "$opening"*"$closing" ]] || native_fail 'malformed Coq trace list' + bytes=${input#"$opening"} + bytes=${bytes%"$closing"} + for ((index = 0; index < 256; index++)); do + [[ $bytes =~ $decimal ]] || native_fail 'missing or invalid Coq trace byte' + byte=${BASH_REMATCH[1]} + [[ $byte -le 255 ]] || native_fail 'Coq trace byte is outside 0..255' + printf -v escaped '%s\\x%02x' "$escaped" "$byte" + bytes=${bytes:${#BASH_REMATCH[0]}} + if ((index < 255)); then + [[ $bytes == ';'* ]] || native_fail 'missing Coq trace byte separator' + bytes=${bytes:1} + fi + done + [[ -z $bytes ]] || native_fail 'unexpected data after 256 Coq trace bytes' + printf '%b' "$escaped" +) + +native_check_trace_encoding() { + native_decode_trace NativeTrace.v | cmp -s -- trace.bin - \ + || native_fail 'Coq trace data does not round-trip to raw bytes' +} + +native_prove() ( + local coqc coqchk + coqc=$(native_tool "${COQC:-coqc}") + coqchk=$(native_tool "${COQCHK:-coqchk}") + cd "$1" + native_trace_source > NativeTrace.v + native_check_trace_encoding + sha256sum -c accepted.sha256 > /dev/null || native_fail 'accepted inputs changed before proof' + sha256sum -c native-build.sha256 > /dev/null || native_fail 'native build evidence changed before proof' + sha256sum trace.bin trace.stderr NativeTrace.v > raw-trace.sha256 + timeout -k 5 120 "$coqc" -q -Q . '' NativeTrace.v > trace-coqc.log 2>&1 \ + || { cat trace-coqc.log >&2; native_fail 'could not compile trace data'; } + sha256sum NativeTrace.vo > compiled-trace.sha256 + timeout -k 5 120 "$coqc" -q -Q . '' U8Native.v > native-assumptions.txt 2> native-assumptions.stderr \ + || { cat native-assumptions.stderr >&2; native_fail 'trace or export does not agree with the validated model and source'; } + [[ -s U8Native.vo ]] || native_fail 'missing compiled native capsule' + [[ $(grep -c '^Closed under the global context$' native-assumptions.txt) == 3 ]] \ + || native_fail 'native theorems are not closed' + ! grep -q '^Axioms:' native-assumptions.txt || native_fail 'axioms in native theorem closure' + timeout -k 5 120 "$coqchk" -silent -Q . '' "${native_libraries[@]}" > native-coqchk.txt 2>&1 \ + || { cat native-coqchk.txt >&2; native_fail 'compiled native kernel check failed'; } + sha256sum -c accepted.sha256 native-build.sha256 build-source.sha256 raw-trace.sha256 compiled-trace.sha256 \ + > native-recheck.txt || native_fail 'inputs changed during native proof' +) + +native_receipt() ( + cd "$1" + cat accepted.sha256 native-build.sha256 raw-trace.sha256 compiled-trace.sha256 > inputs.sha256 + sha256sum accepted.sha256 native-build.sha256 raw-trace.sha256 compiled-trace.sha256 build-source.sha256 \ + link-inputs.sha256 trace-coqc.log U8Native.vo native-assumptions.{txt,stderr} \ + native-coqchk.txt native-recheck.txt >> inputs.sha256 + sha256sum -c --quiet inputs.sha256 || native_fail 'inputs changed before receipt' + jq -cnS --arg manifest "$(native_digest inputs.sha256)" \ + --arg source "$(native_digest source.zig)" --arg model "$(native_digest AtomaProof.vo)" \ + --arg binary "$(native_digest native-observer)" --arg trace "$(native_digest trace.bin)" \ + --arg symbol "$(cat export-symbol.txt)" ' + {schema:"atoma.native.u8/1",status:"INCOMPLETE",inputs_checked:256, + scope:"observed outputs of the compiled C ABI export agree with the validated byte model", + zig_version:"0.15.2",target:"x86_64-linux-musl",cpu:"baseline",mode:"Debug", + linkage:"static",libc_linked:false,elf_interpreter:null,elf_needed:[], + export_symbol:$symbol,source_sha256:$source,model_sha256:$model, + executable_sha256:$binary,trace_sha256:$trace,manifest_sha256:$manifest, + coqchk:"checked",assumptions:[],zig_compiler_refinement:"unproved"} + ' > receipt.json.tmp + mv -- receipt.json.tmp receipt.json + echo 'NATIVE-BYTE-CHECKED: captured and kernel-checked 256 inputs; INCOMPLETE' +) + +native_replay() ( + local coqchk scratch + coqchk=$(native_tool "${COQCHK:-coqchk}") + cd "$1" + [[ $(uname -sm) == 'Linux x86_64' ]] || native_fail 'x86-64 Linux execution is required' + jq -e -s --arg manifest "$(native_digest inputs.sha256)" ' + length == 1 and (.[0] | + .schema == "atoma.native.u8/1" and .status == "INCOMPLETE" and + .inputs_checked == 256 and .manifest_sha256 == $manifest and + .coqchk == "checked" and .assumptions == [] and .zig_compiler_refinement == "unproved") + ' receipt.json > /dev/null || native_fail 'receipt does not identify the evidence manifest' + sha256sum -c inputs.sha256 >&2 || native_fail 'archived inputs changed' + jq -e --arg source "$(native_digest source.zig)" --arg model "$(native_digest AtomaProof.vo)" \ + --arg binary "$(native_digest native-observer)" --arg trace "$(native_digest trace.bin)" \ + --arg symbol "$(cat export-symbol.txt)" ' + .source_sha256 == $source and .model_sha256 == $model and .executable_sha256 == $binary and + .trace_sha256 == $trace and .export_symbol == $symbol and .zig_version == "0.15.2" and + .target == "x86_64-linux-musl" and .cpu == "baseline" and .mode == "Debug" and + .linkage == "static" and .libc_linked == false and .elf_interpreter == null and .elf_needed == [] + ' receipt.json > /dev/null || native_fail 'receipt does not identify the archived native observation' + scratch=$(mktemp -d) + trap 'rm -f -- "$scratch/NativeTrace.v" "$scratch/native-observer" "$scratch/trace.bin"; rmdir -- "$scratch"' EXIT + native_trace_source > "$scratch/NativeTrace.v" + cmp -s -- NativeTrace.v "$scratch/NativeTrace.v" || native_fail 'compiled trace input differs from raw bytes' + native_check_trace_encoding + [[ $(grep -c '^Closed under the global context$' native-assumptions.txt) == 3 ]] \ + || native_fail 'archived assumption audit is incomplete' + ! grep -q '^Axioms:' native-assumptions.txt || native_fail 'axioms in archived native theorem closure' + timeout -k 5 120 "$coqchk" -silent -Q . '' "${native_libraries[@]}" \ + || native_fail 'archived native kernel check failed' + # Artifact downloads do not retain execute permissions. Never alter the archive. + cp -- native-observer "$scratch/native-observer" + cmp -s -- native-observer "$scratch/native-observer" || native_fail 'replay executable copy changed' + chmod u+x "$scratch/native-observer" + timeout -k 5 30 "$scratch/native-observer" > "$scratch/trace.bin" \ + || native_fail 'archived native observer execution failed' + cmp -s -- trace.bin "$scratch/trace.bin" || native_fail 'archived executable produced different trace bytes' + sha256sum -c --quiet inputs.sha256 || native_fail 'archived inputs changed during replay' + echo 'NATIVE-BYTE-REPLAYED: archived executable and kernel closure agree; INCOMPLETE' +) + +if [[ ${BASH_SOURCE[0]} == "$0" ]]; then + set -euo pipefail + export LC_ALL=C + if [[ $# == 3 && $1 == check ]]; then + native_prepare "$2" "$3" + native_build "$3" source.zig + native_observe "$3" + native_prove "$3" + native_receipt "$3" + elif [[ $# == 2 && $1 == replay ]]; then + native_replay "$2" + else + echo 'usage: atoma-native-byte.sh check TRANSLATION_DIRECTORY NEW_EVIDENCE_DIRECTORY' >&2 + echo ' atoma-native-byte.sh replay TRUSTED_NATIVE_EVIDENCE_DIRECTORY' >&2 + exit 2 + fi +fi diff --git a/scripts/atoma-translation-gate.sh b/scripts/atoma-translation-gate.sh index 5051bb4..f56040f 100644 --- a/scripts/atoma-translation-gate.sh +++ b/scripts/atoma-translation-gate.sh @@ -131,3 +131,117 @@ 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' + +native="$root/scripts/atoma-native-byte.sh" +source "$native" +for case_name in advance-five nudge; do + case_dir="$work/$case_name" + bash "$native" check "$case_dir/translation" "$case_dir/native" + # Match the executable mode of downloaded GitHub Actions artifacts. + chmod a-x "$case_dir/native/native-observer" + bash "$native" replay "$case_dir/native" > "$case_dir/native-replay.log" 2>&1 \ + || { cat "$case_dir/native-replay.log" >&2; exit 1; } +done + +expect_native_refusal() { + local out=$1 reason=$2 + if native_prove "$out" > "$out/refusal.log" 2>&1; then + echo "FAIL native proof accepted $(basename "$out")" >&2 + exit 1 + fi + grep -Fxq "NATIVE-BYTE-REFUSED: $reason" "$out/refusal.log" \ + || { cat "$out/refusal.log" >&2; return 1; } + [[ ! -e $out/receipt.json && ! -e $out/U8Native.vo ]] +} + +check_native_counterexample() ( + local out=$1 input=$2 actual=$3 expected=$4 + cd "$out" + cat > NativeRefusal.v < $expected. +Proof. + split; [vm_compute; reflexivity |]. + split; [vm_compute; reflexivity |]. + split; [vm_compute; reflexivity | discriminate]. +Qed. +Print Assumptions native_counterexample. +COQ + timeout -k 5 120 "$COQC" -q -Q . '' NativeRefusal.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) == 1 ]] + if grep -q '^Axioms:' refusal-assumptions.txt; then + native_fail 'axioms in native refusal theorem closure' + fi + timeout -k 5 120 "$COQCHK" -silent -Q . '' ScalarSource U8Source SourceBytes AtomaProof \ + U8Translation NativeTrace NativeRefusal > refusal-coqchk.txt 2>&1 + sha256sum -c accepted.sha256 native-build.sha256 build-source.sha256 raw-trace.sha256 compiled-trace.sha256 \ + > refusal-recheck.txt + sha256sum trace.bin NativeTrace.{v,vo} NativeRefusal.{v,vo} refusal.log refusal-assumptions.{txt,stderr} \ + refusal-coqchk.txt refusal-recheck.txt > refusal.sha256 + printf 'NATIVE-BYTE-FALSIFIER-KILLED %s input=%s actual=%s expected=%s\n' \ + "$(basename "$out")" "$input" "$actual" "$expected" +) + +base_translation="$work/advance-five/translation" +bad_object="$work/native-wrong-object" +native_prepare "$base_translation" "$bad_object" +cp -- "$pilot/advance-five-wrong-body.zig" "$bad_object/mutant.zig" +native_build "$bad_object" mutant.zig +native_observe "$bad_object" +semantic_refusal='trace or export does not agree with the validated model and source' +expect_native_refusal "$bad_object" "$semantic_refusal" +check_native_counterexample "$bad_object" 0 4 5 + +# Test the imported capture independently of the executable. Leave every +# earlier row unchanged so the last row is necessary for the proof. +bad_trace="$work/native-changed-trace" +short_trace="$work/native-short-trace" +native_prepare "$base_translation" "$bad_trace" +native_build "$bad_trace" source.zig +native_observe "$bad_trace" +cp -a -- "$bad_trace" "$short_trace" +printf '\005' | dd of="$bad_trace/trace.bin" bs=1 seek=255 conv=notrunc status=none +expect_native_refusal "$bad_trace" "$semantic_refusal" +check_native_counterexample "$bad_trace" 255 5 4 +truncate -s 255 "$short_trace/trace.bin" +expect_native_refusal "$short_trace" 'trace must contain exactly 256 bytes' +[[ ! -e $short_trace/NativeTrace.vo ]] +echo 'NATIVE-BYTE-FALSIFIER-KILLED short trace (255 bytes)' + +control_scratch=$(mktemp -d) +trap 'rm -rf -- "$control_scratch"' EXIT +cp -a -- "$base_translation" "$control_scratch/model-swap" +cp -- "$work/nudge/translation/AtomaProof.vo" "$control_scratch/model-swap/AtomaProof.vo" +if native_prepare "$control_scratch/model-swap" "$work/native-cross-model" \ + > "$work/native-cross-model.log" 2>&1; then + echo 'FAIL native preparation accepted a different compiled model' >&2 + exit 1 +fi +grep -Fxq 'AtomaProof.vo: FAILED' "$work/native-cross-model.log" +grep -Fxq 'NATIVE-BYTE-REFUSED: translation inputs changed' "$work/native-cross-model.log" +[[ ! -e $work/native-cross-model/receipt.json ]] +echo 'NATIVE-BYTE-FALSIFIER-KILLED substituted compiled model' + +expect_archive_refusal() { + local name=$1 baseline=$2 file=$3 replacement=$4 + local archive="$control_scratch/$name" + cp -a -- "$baseline" "$archive" + cp -- "$replacement" "$archive/$file" + if bash "$native" replay "$archive" > "$work/$name.log" 2>&1; then + echo "FAIL native replay accepted $name" >&2 + exit 1 + fi + grep -Fxq "$file: FAILED" "$work/$name.log" + grep -Fxq 'NATIVE-BYTE-REFUSED: archived inputs changed' "$work/$name.log" + ! grep -q '^NATIVE-BYTE-REPLAYED:' "$work/$name.log" + printf 'NATIVE-BYTE-FALSIFIER-KILLED %s\n' "$name" +} +expect_archive_refusal native-stale-source "$work/nudge/native" source.zig "$work/comment-change/translation/source.zig" +expect_archive_refusal native-stale-binary "$work/advance-five/native" native-observer "$bad_object/native-observer" + +echo 'NATIVE BYTE GATE PASS: both exports replayed and six controls refused; INCOMPLETE' diff --git a/verification/atoma/consumer/coq/U8Native.v b/verification/atoma/consumer/coq/U8Native.v new file mode 100644 index 0000000..77781af --- /dev/null +++ b/verification/atoma/consumer/coq/U8Native.v @@ -0,0 +1,36 @@ +(* SPDX-License-Identifier: MPL-2.0 *) +(* SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell *) +From Coq Require Import List Arith. +Require AtomaProof NativeTrace SourceBytes U8Source U8Translation. + +Definition byte_domain := seq 0 256. + +Theorem native_symbol_matches_source : + option_map fst (U8Source.parse_named SourceBytes.bytes) = Some NativeTrace.symbol. +Proof. vm_compute. reflexivity. Qed. + +Theorem native_trace_matches_model : + NativeTrace.bytes = map AtomaProof.body byte_domain. +Proof. vm_compute. reflexivity. Qed. + +Theorem native_byte_agrees : forall input, input < 256 -> + nth_error NativeTrace.bytes input = Some (AtomaProof.body input) /\ + nth_error NativeTrace.bytes input = Some (AtomaProof.specification input) /\ + U8Source.run SourceBytes.bytes input = + Some (AtomaProof.body input, AtomaProof.specification input). +Proof. + intros input H. + assert (Hbody : nth_error NativeTrace.bytes input = Some (AtomaProof.body input)). + { rewrite native_trace_matches_model. + apply map_nth_error. + unfold byte_domain. + rewrite (@nth_error_nth' nat (seq 0 256) input 0) by now rewrite seq_length. + now rewrite seq_nth by exact H. } + split; [exact Hbody | split]. + - now rewrite <- (AtomaProof.atoma_u8 input H). + - exact (U8Translation.byte_translation_agrees input H). +Qed. + +Print Assumptions native_symbol_matches_source. +Print Assumptions native_trace_matches_model. +Print Assumptions native_byte_agrees. diff --git a/verification/atoma/consumer/coq/U8Source.v b/verification/atoma/consumer/coq/U8Source.v index ca53fe1..f8d3c60 100644 --- a/verification/atoma/consumer/coq/U8Source.v +++ b/verification/atoma/consumer/coq/U8Source.v @@ -178,20 +178,20 @@ Fixpoint parse_expression (depth : nat) (parameter : string) end. Definition parse_module (line : list nat) (tokens : list string) - : option (expression * nat) := + : option (string * (expression * nat)) := match tokens with | "export" :: "fn" :: name :: "(" :: parameter :: ":" :: "u8" :: ")" :: "callconv" :: "(" :: "." :: "c" :: ")" :: "u8" :: "{" :: "return" :: rest => if identifier name && identifier parameter && negb (String.eqb name parameter) then match parse_expression 16 parameter rest, parse_contract parameter line with - | Some (e, [";"; "}"]), Some n => Some (e, n) + | Some (e, [";"; "}"]), Some n => Some (name, (e, n)) | _, _ => None end else None | _ => None end. -Definition parse (bytes : list nat) : option (expression * nat) := +Definition parse_named (bytes : list nat) : option (string * (expression * nat)) := if (List.length bytes <=? 2048) && valid_bytes bytes then match lex (List.length bytes) bytes with | Some (documentation line :: rest) => @@ -200,6 +200,9 @@ Definition parse (bytes : list nat) : option (expression * nat) := end else None. +Definition parse (bytes : list nat) : option (expression * nat) := + option_map snd (parse_named bytes). + Fixpoint evaluate (e : expression) (x : nat) : nat := match e with | parameter_value => x From b26d0cf30c3635631d4f652787fcb1a5a38ef10b Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 30 Nov 2026 10:26:04 +0000 Subject: [PATCH 2/2] Refuse the reserved Linux entry point explicitly in native validation --- docs/decisions/ATOMA-BYTE-TRANSLATION.adoc | 4 ++++ scripts/atoma-native-byte.sh | 1 + scripts/atoma-translation-gate.sh | 14 +++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/decisions/ATOMA-BYTE-TRANSLATION.adoc b/docs/decisions/ATOMA-BYTE-TRANSLATION.adoc index 7c8a4d2..2aacd01 100644 --- a/docs/decisions/ATOMA-BYTE-TRANSLATION.adoc +++ b/docs/decisions/ATOMA-BYTE-TRANSLATION.adoc @@ -36,6 +36,10 @@ The comment edit requires a new receipt because its byte identity changed. == Native byte evidence +The x86-64 native profile reserves `_start` for the observer's Linux entry +point. A source with that export can still be checked by the source-to-model +gate. The native gate refuses it before compiling the observer. + The native gate builds the accepted source snapshot with Zig 0.15.2 for `x86_64-linux-musl`, using baseline CPU, Debug mode, LLVM and disabled LTO. The gate checks the translation manifest and the receipt's source and compiled diff --git a/scripts/atoma-native-byte.sh b/scripts/atoma-native-byte.sh index 7076853..fd80a2b 100644 --- a/scripts/atoma-native-byte.sh +++ b/scripts/atoma-native-byte.sh @@ -74,6 +74,7 @@ native_build() ( # The capsule ties the symbol found in the ELF table to the accepted source. symbol=$(awk '$4 == "FUNC" && $5 == "GLOBAL" && $6 == "DEFAULT" && $7 != "UND" {print $8}' export-elf.txt) [[ $symbol =~ ^[A-Za-z_]+$ ]] || native_fail 'expected exactly one defined global ELF function' + [[ $symbol != _start ]] || native_fail 'export _start is reserved for the native observer entry point' printf '%s\n' "$symbol" > export-symbol.txt sed "s/@\"ATOMA_EXPORT\"/@\"$symbol\"/g" observer-template.zig > observer.zig timeout -k 5 120 "$zig" build-obj observer.zig "${native_flags[@]}" -femit-bin=observer.o \ diff --git a/scripts/atoma-translation-gate.sh b/scripts/atoma-translation-gate.sh index f56040f..099edef 100644 --- a/scripts/atoma-translation-gate.sh +++ b/scripts/atoma-translation-gate.sh @@ -244,4 +244,16 @@ expect_archive_refusal() { expect_archive_refusal native-stale-source "$work/nudge/native" source.zig "$work/comment-change/translation/source.zig" expect_archive_refusal native-stale-binary "$work/advance-five/native" native-observer "$bad_object/native-observer" -echo 'NATIVE BYTE GATE PASS: both exports replayed and six controls refused; INCOMPLETE' +sed 's/export fn advance_five(/export fn _start(/' "$pilot/advance-five.zig" > "$work/reserved.zig" +check_translation "$work/reserved.zig" reserved-export +reserved="$work/reserved-export/native" +if bash "$native" check "$work/reserved-export/translation" "$reserved" > "$work/reserved-export.log" 2>&1; then + echo 'FAIL native observer accepted its own entry point as the subject' >&2 + exit 1 +fi +grep -Fxq 'NATIVE-BYTE-REFUSED: export _start is reserved for the native observer entry point' "$work/reserved-export.log" \ + || { cat "$work/reserved-export.log" >&2; exit 1; } +[[ ! -e $reserved/receipt.json && ! -e $reserved/observer.o ]] +echo 'NATIVE-BYTE-FALSIFIER-KILLED observer entry collision after successful source translation' + +echo 'NATIVE BYTE GATE PASS: both exports replayed and seven controls refused; INCOMPLETE'