Repository navigation
Interpret borrowed Zig wrappers under explicit ownership and foreign-call contracts #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f355a9e
Interpret actual wrapper call and loop bodies under explicit ownershi…
hyperpolymath 07ed661
Bind imported protocol semantics and require fresh wrapper consumer r…
hyperpolymath 99a4c41
Disambiguate source literals and prove checked loop state bounds
hyperpolymath 37329a7
Parse Zig error return types separately from wrapper bodies and retai…
hyperpolymath 05d3974
Use a structural wrapper grammar and state the byte-domain call contract
hyperpolymath 503ea1b
Preserve the protocol guard during the frame proof and qualify streng…
hyperpolymath 0f172c0
Require unchanged pinned consumer inputs across native and proof replay
hyperpolymath 6823ff0
Bind protocol exports and align native consumer compiler profile
hyperpolymath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // SPDX-License-Identifier: CC-BY-SA-4.0 | ||
| = Conditional ownership and actual Zig wrappers | ||
| :revdate: 2026-11-25 | ||
|
|
||
| == Admitted source and result | ||
|
|
||
| This experimental slice parses the original complete `registry.zig` and | ||
| `header_refc.zig` modules. It admits closed signatures, imports, surrounding | ||
| declarations, and an ordered call/loop grammar. Numeric guards become operands | ||
| of the operational interpretation. Changed callback arguments, missing cleanup, | ||
| reordered state updates, changed span guards and changed loop bounds must refuse. | ||
| It is not a general Zig parser or a compiler-refinement theorem. | ||
|
|
||
| UAA's theorem covers `uaa_registry_call`: initial idle state, all normal exits, | ||
| busy refusal, invalid-span callback refusal and preservation of endpoint | ||
| identities under a callback-frame premise. The actual imported state kernel is | ||
| checked independently; the protocol-tag source must export `known` and parse as | ||
| the 1..9 range. A renamed-export mutation must be rejected. | ||
| The surrounding create/destroy/register/unregister declarations are closed by | ||
| the grammar and exercised natively, but do not acquire ownership theorems merely | ||
| because their tokens match. Allocator correctness remains assumed. | ||
|
|
||
| Proven's theorem covers the actual `header_refc.detect` loop: under the explicit | ||
| foreign-step contract, its checked execution equals the authoritative Boolean | ||
| fold. Every iteration consumes one element of the borrowed list; the read count | ||
| is bounded by its length. The whole public `core.headerHasCrlf` entry, conversion | ||
| from machine pointer to slice, private RefC runtime and compiler remain outside | ||
| this refinement. The retained `bits8.zig` bytes identify that assumed carrier; | ||
| they are not promoted to a pointer-validity proof by appearing in a capsule. | ||
|
|
||
| == Ownership premises | ||
|
|
||
| * One live registry allocation, serialized owner access, no stale-pointer use. | ||
| * Callback and context are valid when invoked; registration retains their | ||
| identities. The owner must keep them valid while registration can be called, | ||
| or unregister before their storage/code lifetime ends. | ||
| * The callback may change its own disjoint context. It must preserve registry | ||
| storage, keep borrowed input readable and immutable, and return normally. | ||
| * No concurrent writes, asynchronous retention, non-local exit, process abort, | ||
| arbitrary raw-alias mutation or compiler correctness is established here. | ||
| * Proven receives a readable immutable span for its synchronous call. The | ||
| foreign RefC step returns a canonical state implementing the Idris contract | ||
| and does not write the borrowed span. Immediate tagged values are not heap | ||
| objects and must not be dereferenced as pointers. | ||
|
|
||
| These are quantified or stated premises, not facts inferred from non-nullness. | ||
| The UAA native raw-alias fixture deliberately deletes an endpoint during a | ||
| callback and demonstrates that `finish` does not restore the original frame. | ||
| That counterexample must remain visible; it prevents unconditional safety claims. | ||
|
|
||
| == Evidence and status | ||
|
|
||
| Idris2 owns both engineering contracts. UAA's linear Lease checks use of an | ||
| already-acquired logical owner: acquisition, unforgeability and machine aliases | ||
| are not proved by its constructors. Constructors are hidden, the resource | ||
| payload is linear, and release requires a consuming finalizer. Neither direct | ||
| duplication nor destruct-and-reconstruct duplication may type check. Wrapping | ||
| an already-copyable value does not establish exclusive machine ownership. | ||
| Proven proves checked scanning against its actual ByteKernel fold. Native tests | ||
| exercise real Zig wrappers and exported ABI; no FFI/API is implemented in C. | ||
|
|
||
| Compatible Agda is checked with safe, without-K, cubical-compatible and | ||
| double-check flags, followed by an audited Lean re-proof and full Cubical paths. | ||
| The independent Coq source interpretation adds kernel checking and ECHIDNA | ||
| replay. Hand re-proofs remain BRIDGE-PENDING; full Cubical is not an independent | ||
| kernel. No PWG promotion, universal native-memory safety or COMPLETE receipt. | ||
|
|
||
| The required source/theory jobs and combined consumer replay must pass on the | ||
| exact PR head before this slice is accepted. Qualification evidence is recorded | ||
| in https://github.com/hyperpolymath/atoma/pull/33[the implementation PR]; the | ||
| presence of these files alone is not a successful check or a promotion. | ||
|
|
||
| == Next obligations | ||
|
|
||
| Connect acquisition/release and callback registration lifetimes to an actual | ||
| heap model; prove the public pointer-to-slice entry; extend beyond normal return; | ||
| discharge or precisely retain foreign-call assumptions; reconcile statement | ||
| identity across kernels. Checked generation handles may support a future | ||
| versioned ABI, but this slice changes no ABI and silently repairs no stale handle. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| set -euo pipefail | ||
| root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) | ||
| mkdir -p "$root/build/atoma-evidence/wrapper-consumers" | ||
| out=$(mktemp -d "$root/build/atoma-evidence/wrapper-consumers/run.XXXXXXXX") | ||
| work=$(mktemp -d) | ||
| trap 'rm -rf "$work"' EXIT | ||
| for profile in header registry; do | ||
| if [[ $profile == header ]]; then | ||
| repo=proven; pin=ownership-proven.pin | ||
| source=ffi/zig/src/header_refc.zig; dependency=ffi/zig/src/refc/bits8.zig | ||
| else | ||
| repo=unified-api-adapter; pin=ownership-uaa.pin | ||
| source=src/interface/ffi/src/registry.zig; dependency=src/interface/ffi/src/registry_state.zig | ||
| fi | ||
| revision=$(cat "$root/tests/consumer-word/$pin") | ||
| [[ $revision =~ ^[0-9a-f]{40}$ ]] | ||
| checkout="$work/$repo" | ||
| git init -q "$checkout" | ||
| git -C "$checkout" remote add origin "https://github.com/hyperpolymath/$repo.git" | ||
| git -C "$checkout" fetch -q --depth 1 origin "$revision" | ||
| git -C "$checkout" checkout -q --detach FETCH_HEAD | ||
| [[ $(git -C "$checkout" rev-parse HEAD) == "$revision" ]] | ||
| git -C "$checkout" diff --exit-code "$revision" -- | ||
| mkdir "$out/$profile" | ||
| echo "$revision" > "$out/$profile/revision.txt" | ||
| if [[ $profile == header ]]; then | ||
| EVIDENCE_DIR="$out/$profile/native" bash "$checkout/scripts/test-header-bridge.sh" | ||
| [[ $(cat "$out/$profile/native/result.txt") == PASS ]] | ||
| [[ $(cat "$out/$profile/native/ownership/result.txt") == PASS ]] | ||
| [[ $(cat "$out/$profile/native/ownership-controls/result.txt") == PASS ]] | ||
| else | ||
| EVIDENCE_DIR="$out/$profile/native" bash "$checkout/scripts/check-registry-ownership.sh" | ||
| [[ $(cat "$out/$profile/native/result.txt") == PASS ]] | ||
| EVIDENCE_DIR="$out/$profile/native-controls" bash "$checkout/scripts/check-registry-ownership-controls.sh" | ||
| [[ $(cat "$out/$profile/native-controls/result.txt") == PASS ]] | ||
| fi | ||
| git -C "$checkout" diff --exit-code "$revision" -- > "$out/$profile/consumer-recheck.txt" | ||
| bash "$root/scripts/atoma-source-profile-replay.sh" "$profile-wrapper" "$checkout/$source" "$checkout/$dependency" "$out/$profile/replay" | ||
| git -C "$checkout" diff --exit-code "$revision" -- > "$out/$profile/post-replay-recheck.txt" | ||
| done | ||
| echo 'WRAPPER CONSUMERS PASS: fresh native qualification and conditional original-source replay; ownership premises remain' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| set -euo pipefail | ||
| [[ $# == 4 && -f $2 && -f $3 ]] | ||
| profile=$1 | ||
| [[ $profile == registry || $profile == header ]] | ||
| for source in "$2" "$3"; do [[ $(wc -c < "$source") -le 65536 ]]; done | ||
| cat <<'COQ' | ||
| From Coq Require Import List Bool ZArith String. | ||
| Require Import WrapperSource RegistrySource. | ||
| Import ListNotations. | ||
| Open Scope string_scope. | ||
| Open Scope nat_scope. | ||
| COQ | ||
| bytes() { | ||
| printf 'Definition %s : list nat := ' "$1" | ||
| od -An -v -tu1 "$2" | awk 'BEGIN {printf "["} {for(i=1;i<=NF;i++) {if(n++) printf ";"; printf "%s",$i}} END {print "]."}' | ||
|
Check warning on line 17 in scripts/atoma-wrapper-capsule.sh
|
||
| } | ||
| bytes wrapper_bytes "$2" | ||
| bytes dependency_bytes "$3" | ||
| if [[ $profile == registry ]]; then | ||
| [[ -f $4 && $(wc -c < "$4") -le 65536 ]] | ||
| bytes protocol_bytes "$4" | ||
| cat <<'COQ' | ||
| Lemma source_accepted : WrapperSource.check_registry wrapper_bytes = true. | ||
| Proof. vm_compute. reflexivity. Qed. | ||
| Lemma dependency_accepted : RegistrySource.check dependency_bytes = true. | ||
| Proof. vm_compute. reflexivity. Qed. | ||
| Definition protocol_exports_known : bool := | ||
| match ScalarSource.lex (List.length protocol_bytes) protocol_bytes with | ||
| | Some ("pub" :: "fn" :: "known" :: _) => true | ||
| | _ => false | ||
| end. | ||
| Lemma protocol_accepted : protocol_exports_known = true /\ | ||
| ScalarSource.parse protocol_bytes = Some (ScalarSource.inclusive_range 1 9). | ||
| Proof. vm_compute. split; reflexivity. Qed. | ||
| Theorem source_checked : forall A present (s : RegistrySource.state A) tag valid callback, | ||
| RegistrySource.active s = false -> WrapperSource.callback_frames callback -> | ||
| exists p, WrapperSource.parse_registry wrapper_bytes = Some p /\ | ||
| WrapperSource.final_registry (WrapperSource.registry_run p present s tag valid callback) = s. | ||
| Proof. intros. eapply WrapperSource.registry_normal_frame; eauto using source_accepted. Qed. | ||
| Print Assumptions source_checked. | ||
| Print Assumptions dependency_accepted. | ||
| Print Assumptions protocol_accepted. | ||
| COQ | ||
| else | ||
| # The pointer carrier / RefC runtime remain an explicit call contract. Preserve | ||
| # their actual bytes in the capsule rather than pretending this is a proof of them. | ||
| cat <<'COQ' | ||
| Lemma source_accepted : WrapperSource.check_header wrapper_bytes = true. | ||
| Proof. vm_compute. reflexivity. Qed. | ||
| Theorem source_checked : forall step foreign bs, | ||
| Forall (fun b => b < 256) bs -> | ||
| (forall s b, b < 256 -> foreign (WrapperSource.encode s) b = Some (WrapperSource.encode (step s b))) -> | ||
| exists p, WrapperSource.parse_header wrapper_bytes = Some p /\ | ||
| WrapperSource.header_run p foreign bs = Some (WrapperSource.fold step false bs). | ||
| Proof. intros. eapply WrapperSource.header_source_fold; eauto using source_accepted. Qed. | ||
| Print Assumptions source_checked. | ||
| COQ | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| set -euo pipefail | ||
| root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) | ||
| out="$root/build/scalar-proof-evidence/wrapper-theory" | ||
| mkdir -p "$out" | ||
| work=$(mktemp -d) | ||
| trap 'status=$?; if ((status)); then tail -n 50 "$out"/*.txt >&2; fi; rm -rf "$work"' EXIT | ||
| cp "$root/verification/atoma/consumer/agda/WrapperEffects"*.agda "$work/" | ||
| cp "$root/verification/atoma/consumer/lean4/WrapperEffects.lean" "$work/" | ||
| cd "$work" | ||
| agda --safe --without-K --cubical-compatible --double-check --warning=error WrapperEffects.agda > "$out/agda.txt" 2>&1 | ||
| lean WrapperEffects.lean > "$out/lean.txt" 2>&1 | ||
| awk ' | ||
| BEGIN {names["normalReturnFrame"]=1; names["invalidSpanCleanup"]=1; names["aliasCounterexample"]=1; names["aliasBreaksFrame"]=1; names["scanRefinesFold"]=1} | ||
| { | ||
| found=0 | ||
| for (n in names) { | ||
| expected="\047WrapperEffects." n "\047 does not depend on any axioms" | ||
| if ($0 == expected && names[n] == 1) {names[n]=2; found=1; count++} | ||
| } | ||
| if (!found) exit 1 | ||
| } | ||
| END {if (count != 5) exit 1}' "$out/lean.txt" | ||
| agda --safe --cubical --double-check --warning=error WrapperEffectsCubical.agda > "$out/cubical.txt" 2>&1 | ||
| sed -e 's/module WrapperEffects where/module WrapperEffectsMutant where/' \ | ||
| -e 's/finish s = registry (rest s) (mcp s) false/finish s = registry (rest s) (mcp s) true/' WrapperEffects.agda > WrapperEffectsMutant.agda | ||
| if agda --safe --cubical-compatible --double-check --warning=error WrapperEffectsMutant.agda > "$out/reject-cleanup.txt" 2>&1; then exit 1; fi | ||
| grep -q '!=' "$out/reject-cleanup.txt" | ||
| sha256sum ./*.agda ./*.lean > "$out/inputs.sha256" | ||
| echo 'WRAPPER THEORY PASS: compatible Agda, audited Lean, Cubical and rejecting cleanup control' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.