From f7ea5806e417b2ea546909c721a5bf9c4e6b6db3 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:27:50 +0000 Subject: [PATCH 1/4] feat(abi): specify registry transition frames and call ownership boundary --- .../2026-11-24-registry-state-ownership.adoc | 33 ++++ scripts/check-registry.sh | 8 +- src/interface/Abi/RegistryState.idr | 146 ++++++++++++++++++ 3 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 docs/decisions/2026-11-24-registry-state-ownership.adoc create mode 100644 src/interface/Abi/RegistryState.idr diff --git a/docs/decisions/2026-11-24-registry-state-ownership.adoc b/docs/decisions/2026-11-24-registry-state-ownership.adoc new file mode 100644 index 0000000..6bec1f7 --- /dev/null +++ b/docs/decisions/2026-11-24-registry-state-ownership.adoc @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 +// Copyright (c) 2026 Jonathan D.A. Jewell += Registry state and ownership proof boundary + +The executable FFI/API remains pure Zig. `Abi.RegistryState` develops the +authoritative Idris2 transition contract alongside the existing registry and +protocol contracts. Each endpoint is one value containing callback/context +identity, not merely a Boolean registration flag. + +The total module proves selected-slot replacement, preservation of the other +slot, busy registration/unregistration refusal, duplicate/absent refusal +framing, exact selected endpoint identity, reentrant call refusal, and endpoint +frame restoration on normal callback return. The existing 1,024-case native +ABI differential campaign remains mandatory. These theorems are development +work until their fresh hosted totality/no-hole check passes. + +== Ownership assumptions + +The caller owns a live registry exclusively and serializes access. Registered +callback code and context remain live until unregister/destroy, and throughout +any synchronous callback. Input bytes remain readable for the callback's +duration. Foreign code must not mutate registry memory through raw aliases. + +An `Invocation` is an ordinary logical snapshot, not an unforgeable runtime +capability and not a linear ownership proof. Busy restoration applies when the +callback returns normally; it establishes neither termination nor safe +non-local jumps, arbitrary foreign corruption, unwinding, or concurrent calls. + +Pending implementation correspondence: connect every Zig state transition to +these Idris definitions, bind imported helpers/source bytes, and validate +lease/provenance rules for actual handles and borrowed buffers. Agda then +Lean/Coq state-model witnesses and independent replay must precede any broader +proof claim. No Mathesis admission or proof grade is asserted here. diff --git a/scripts/check-registry.sh b/scripts/check-registry.sh index 360527f..a771288 100644 --- a/scripts/check-registry.sh +++ b/scripts/check-registry.sh @@ -12,9 +12,14 @@ rm -f "$evidence/result.txt" work=$(mktemp -d -t uapi-registry-check.XXXXXXXX) trap 'rm -rf -- "$work"' EXIT mkdir -p "$work/Abi" -for module in Protocol ProtocolFinite Status Registry; do +for module in Protocol ProtocolFinite Status Registry RegistryState; do cp "$root/src/interface/Abi/$module.idr" "$work/Abi/" done +(cd "$work"; "$idris" --total -Werror --check Abi/RegistryState.idr) > "$evidence/state-build.log" 2>&1 +if grep -q '^Error:' "$evidence/state-build.log"; then cat "$evidence/state-build.log" >&2; exit 1; fi +(cd "$work"; printf ':m\n:q\n' | "$idris" --no-banner Abi/RegistryState.idr) > "$evidence/state-holes.log" 2>&1 +grep -q 'No holes' "$evidence/state-holes.log" +if grep -q '^Error:' "$evidence/state-holes.log"; then cat "$evidence/state-holes.log" >&2; exit 1; fi cp "$root/src/interface/RegistryCheck.idr" "$work/" cp "$root/src/interface/ProtocolTagOracle.idr" "$work/Main.idr" (cd "$work"; sha256sum Abi/*.idr RegistryCheck.idr Main.idr) > "$evidence/inputs.sha256" @@ -52,4 +57,3 @@ grep -q 'finiteDecodeSound' "$evidence/reject.log" } > "$evidence/identity.log" echo PASS > "$evidence/result.txt" printf 'PASS: total proof modules, no holes, executable matrix, rejecting decoder mutation.\nEvidence: %s\n' "$evidence" - diff --git a/src/interface/Abi/RegistryState.idr b/src/interface/Abi/RegistryState.idr new file mode 100644 index 0000000..2e6096c --- /dev/null +++ b/src/interface/Abi/RegistryState.idr @@ -0,0 +1,146 @@ +-- SPDX-License-Identifier: MPL-2.0 +-- Copyright (c) 2026 Jonathan D.A. Jewell +||| State contract for one live, exclusively owned Zig registry. +||| Endpoint values include callback/context identity; no callback is executed +||| by this model. Raw-pointer validity and caller serialization are premises. +module Abi.RegistryState +import Abi.Registry +import Abi.Status + +%default total + +public export +data Slot = RESTSlot | MCPSlot + +public export +record State endpoint where + constructor MkState + entries : Registry endpoint + busy : Bool + +public export +lookup : Slot -> Registry endpoint -> Maybe endpoint +lookup RESTSlot r = restEndpoint r +lookup MCPSlot r = mcpEndpoint r + +public export +replace : Slot -> Maybe endpoint -> Registry endpoint -> Registry endpoint +replace RESTSlot e r = MkRegistry e (mcpEndpoint r) +replace MCPSlot e r = MkRegistry (restEndpoint r) e + +public export +other : Slot -> Slot +other RESTSlot = MCPSlot +other MCPSlot = RESTSlot + +||| Updating a slot neither changes nor fabricates the other endpoint. +public export +replaceFramesOther : (slot : Slot) -> (e : Maybe endpoint) -> + (r : Registry endpoint) -> lookup (other slot) (replace slot e r) = lookup (other slot) r +replaceFramesOther RESTSlot e r = Refl +replaceFramesOther MCPSlot e r = Refl + +public export +replaceSelectsExact : (slot : Slot) -> (e : Maybe endpoint) -> + (r : Registry endpoint) -> lookup slot (replace slot e r) = e +replaceSelectsExact RESTSlot e r = Refl +replaceSelectsExact MCPSlot e r = Refl + +public export +record Reply endpoint where + constructor MkReply + status : Status + next : State endpoint + +public export +register : Slot -> endpoint -> State endpoint -> Reply endpoint +register slot e (MkState r True) = MkReply ProcessFailed (MkState r True) +register slot e (MkState r False) = case lookup slot r of + Just _ => MkReply AlreadyExists (MkState r False) + Nothing => MkReply Ok (MkState (replace slot (Just e) r) False) + +public export +unregister : Slot -> State endpoint -> Reply endpoint +unregister slot (MkState r True) = MkReply ProcessFailed (MkState r True) +unregister slot (MkState r False) = case lookup slot r of + Nothing => MkReply NotFound (MkState r False) + Just _ => MkReply Ok (MkState (replace slot Nothing r) False) + +public export +busyRegisterRefuses : (slot : Slot) -> (e : endpoint) -> (r : Registry endpoint) -> + register slot e (MkState r True) = MkReply ProcessFailed (MkState r True) +busyRegisterRefuses slot e r = Refl + +public export +busyUnregisterRefuses : (slot : Slot) -> (r : Registry endpoint) -> + unregister slot (MkState r True) = MkReply ProcessFailed (MkState r True) +busyUnregisterRefuses slot r = Refl + +public export +duplicateRegisterFrames : (slot : Slot) -> (e old : endpoint) -> (r : Registry endpoint) -> + lookup slot r = Just old -> + register slot e (MkState r False) = MkReply AlreadyExists (MkState r False) +duplicateRegisterFrames slot e old r found = rewrite found in Refl + +public export +absentUnregisterFrames : (slot : Slot) -> (r : Registry endpoint) -> + lookup slot r = Nothing -> + unregister slot (MkState r False) = MkReply NotFound (MkState r False) +absentUnregisterFrames slot r absent = rewrite absent in Refl + +||| This is a logical call ticket, not an unforgeable machine pointer or a +||| proof of linear ownership. The snapshot is held across a NORMAL return. +public export +record Invocation endpoint where + constructor MkInvocation + snapshot : Registry endpoint + selected : endpoint + +public export +beginCall : Slot -> State endpoint -> Either (Reply endpoint) (Invocation endpoint) +beginCall slot (MkState r True) = Left (MkReply ProcessFailed (MkState r True)) +beginCall slot (MkState r False) = case lookup slot r of + Nothing => Left (MkReply Unsupported (MkState r False)) + Just e => Right (MkInvocation r e) + +public export +duringCall : Invocation endpoint -> State endpoint +duringCall call = MkState (snapshot call) True + +public export +normalReturn : Invocation endpoint -> State endpoint +normalReturn call = MkState (snapshot call) False + +public export +beginPreservesIdentity : (slot : Slot) -> (r : Registry endpoint) -> (e : endpoint) -> + lookup slot r = Just e -> + beginCall slot (MkState r False) = Right (MkInvocation r e) +beginPreservesIdentity slot r e found = rewrite found in Refl + +public export +normalReturnRestoresFrame : (call : Invocation endpoint) -> + entries (normalReturn call) = entries (duringCall call) +normalReturnRestoresFrame call = Refl + +public export +reentrantCallRefuses : (slot : Slot) -> (call : Invocation endpoint) -> + beginCall slot (duringCall call) = Left (MkReply ProcessFailed (duringCall call)) +reentrantCallRefuses slot call = Refl + +||| Decode foreign signed status BEFORE narrowing it; values outside the +||| declared ABI range become ProcessFailed, never a fabricated status. +public export +sanitize : Integer -> Status +sanitize 0 = Ok +sanitize 1 = Err +sanitize 2 = InvalidParam +sanitize 3 = OutOfMemory +sanitize 4 = NullPointer +sanitize 5 = PathDenied +sanitize 6 = ProcessFailed +sanitize 7 = Timeout +sanitize 8 = NotFound +sanitize 9 = AlreadyExists +sanitize 10 = SlotExhausted +sanitize 11 = Unsupported +sanitize _ = ProcessFailed From b79296533adfa72cac3f7668dfb89df425b4b9b6 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:30:28 +0000 Subject: [PATCH 2/4] fix(evidence): retain fresh Idris failure diagnostics --- scripts/check-registry.sh | 5 ++++- scripts/check-runtime-registry.sh | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/check-registry.sh b/scripts/check-registry.sh index a771288..9ca8ae2 100644 --- a/scripts/check-registry.sh +++ b/scripts/check-registry.sh @@ -15,7 +15,10 @@ mkdir -p "$work/Abi" for module in Protocol ProtocolFinite Status Registry RegistryState; do cp "$root/src/interface/Abi/$module.idr" "$work/Abi/" done -(cd "$work"; "$idris" --total -Werror --check Abi/RegistryState.idr) > "$evidence/state-build.log" 2>&1 +if ! (cd "$work"; "$idris" --total -Werror --check Abi/RegistryState.idr) > "$evidence/state-build.log" 2>&1; then + cat "$evidence/state-build.log" >&2 + exit 1 +fi if grep -q '^Error:' "$evidence/state-build.log"; then cat "$evidence/state-build.log" >&2; exit 1; fi (cd "$work"; printf ':m\n:q\n' | "$idris" --no-banner Abi/RegistryState.idr) > "$evidence/state-holes.log" 2>&1 grep -q 'No holes' "$evidence/state-holes.log" diff --git a/scripts/check-runtime-registry.sh b/scripts/check-runtime-registry.sh index e704bec..cbd6471 100644 --- a/scripts/check-runtime-registry.sh +++ b/scripts/check-runtime-registry.sh @@ -8,7 +8,14 @@ evidence="$root/build/runtime-registry-evidence" mkdir -p "$evidence" echo INCOMPLETE > "$evidence/result.txt" work=$(mktemp -d -t uaa-runtime-registry.XXXXXXXX) -trap 'status=$?; rm -rf -- "$work"; if ((status)); then echo FAIL > "$evidence/result.txt"; fi' EXIT +finish() { + local status=$? + # Preserve a failed fresh oracle's diagnostics before deleting its directory. + if [[ -d "$work/idris-evidence" ]]; then cp -R "$work/idris-evidence" "$evidence/"; fi + rm -rf -- "$work" + if ((status)); then echo FAIL > "$evidence/result.txt"; fi +} +trap finish EXIT zig=$(command -v "${ZIG:-zig}") zig=$(cd "$(dirname "$zig")" && pwd)/$(basename "$zig") test "$("$zig" version)" = 0.15.2 @@ -47,4 +54,3 @@ if "$work/caller" > "$evidence/mutant.csv" 2> "$evidence/mutant.log"; then fi echo PASS > "$evidence/result.txt" echo 'PASS: real C ABI, Idris differential matrix, lifetime/refusal regressions and rejecting Zig mutant' - From d54b8a3bdb305c63e38f911d32a2fa1b3c3e5881 Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:32:33 +0000 Subject: [PATCH 3/4] fix(abi): separate Idris endpoint binders --- src/interface/Abi/RegistryState.idr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interface/Abi/RegistryState.idr b/src/interface/Abi/RegistryState.idr index 2e6096c..2509075 100644 --- a/src/interface/Abi/RegistryState.idr +++ b/src/interface/Abi/RegistryState.idr @@ -77,7 +77,7 @@ busyUnregisterRefuses : (slot : Slot) -> (r : Registry endpoint) -> busyUnregisterRefuses slot r = Refl public export -duplicateRegisterFrames : (slot : Slot) -> (e old : endpoint) -> (r : Registry endpoint) -> +duplicateRegisterFrames : (slot : Slot) -> (e : endpoint) -> (old : endpoint) -> (r : Registry endpoint) -> lookup slot r = Just old -> register slot e (MkState r False) = MkReply AlreadyExists (MkState r False) duplicateRegisterFrames slot e old r found = rewrite found in Refl From eefd7f719797bd82d68bd95389574d0a71c922ac Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Tue, 24 Nov 2026 23:46:05 +0000 Subject: [PATCH 4/4] Record hosted registry contract and native boundary evidence --- docs/decisions/2026-11-24-registry-state-ownership.adoc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/decisions/2026-11-24-registry-state-ownership.adoc b/docs/decisions/2026-11-24-registry-state-ownership.adoc index 6bec1f7..89ce483 100644 --- a/docs/decisions/2026-11-24-registry-state-ownership.adoc +++ b/docs/decisions/2026-11-24-registry-state-ownership.adoc @@ -11,8 +11,12 @@ The total module proves selected-slot replacement, preservation of the other slot, busy registration/unregistration refusal, duplicate/absent refusal framing, exact selected endpoint identity, reentrant call refusal, and endpoint frame restoration on normal callback return. The existing 1,024-case native -ABI differential campaign remains mandatory. These theorems are development -work until their fresh hosted totality/no-hole check passes. +ABI differential campaign remains mandatory. Hosted run +https://github.com/hyperpolymath/unified-api-adapter/actions/runs/45510851199[45510851199] +checked commit `d54b8a3bdb305c63e38f911d32a2fa1b3c3e5881`: the fresh Idris2 +totality check and no-hole query passed, alongside the native ABI campaign, +lifetime/reentrancy controls and rejection mutant. This validates the model +and the recorded executable tests, not the pending implementation correspondence. == Ownership assumptions