Repository navigation
Bind registry state proofs to the pure Zig kernel used by the FFI #23
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
4 commits
Select commit
Hold shift + click to select a range
e81904b
Route the registry FFI through a pure Zig state-transition kernel
hyperpolymath 5e3db4e
Replay fresh Idris registry traces against pure Zig kernel in four modes
hyperpolymath 759cffa
Place emitting oracle runner outside the effect-free FFI source tree
hyperpolymath 44f9945
Apply FFI side-effect gate to runtime sources while permitting oracle…
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| set -euo pipefail | ||
| root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) | ||
| out=${EVIDENCE_DIR:-"$root/build/runtime-registry-evidence/state"} | ||
| mkdir -p "$out" | ||
| out=$(cd "$out" && pwd) | ||
| echo INCOMPLETE > "$out/result.txt" | ||
| work=$(mktemp -d) | ||
| trap 'status=$?; if ((status)); then echo FAIL > "$out/result.txt"; tail -n 35 "$out"/*.txt >&2; fi; rm -rf "$work"' EXIT | ||
| [[ $(zig version) == 0.15.2 ]] | ||
| cp -R "$root/src/interface/Abi" "$work/" | ||
| cp "$root/src/interface/RegistryStateOracle.idr" "$work/Main.idr" | ||
| cp "$root/src/interface/RegistryStateRunner.zig" "$work/runner.zig" | ||
| cp "$root/src/interface/ffi/src/registry_state.zig" "$work/" | ||
| (cd "$work"; sha256sum Main.idr Abi/*.idr *.zig) > "$out/inputs.sha256" | ||
|
Check warning on line 16 in scripts/check-registry-state.sh
|
||
| (cd "$work"; idris2 --total -Werror --codegen refc -o oracle Main.idr) > "$out/idris-build.txt" 2>&1 | ||
| if grep -q '^Error:' "$out/idris-build.txt"; then exit 1; fi | ||
| (cd "$work"; printf ':m\n:q\n' | idris2 --no-banner Main.idr) > "$out/idris-holes.txt" 2>&1 | ||
| grep -q 'No holes' "$out/idris-holes.txt" | ||
| if grep -q '^Error:' "$out/idris-holes.txt"; then exit 1; fi | ||
| "$work/build/exec/oracle" > "$out/contract.tsv" | ||
| [[ $(wc -l < "$out/contract.tsv") == 917 ]] | ||
| for mode in Debug ReleaseSafe ReleaseFast ReleaseSmall; do | ||
| zig build-exe "$work/runner.zig" -O "$mode" -femit-bin="$work/native" > "$out/build-$mode.txt" 2>&1 | ||
| "$work/native" > "$out/native-$mode.tsv" | ||
| cmp "$out/contract.tsv" "$out/native-$mode.tsv" | ||
| done | ||
| cp "$work/registry_state.zig" "$work/original" | ||
| for mutation in frame busy restoration identity status; do | ||
| case "$mutation" in | ||
|
Check failure on line 31 in scripts/check-registry-state.sh
|
||
| frame) sed 's/.rest = s.rest, .mcp = endpoint/.rest = endpoint, .mcp = endpoint/' "$work/original" ;; | ||
| busy) sed '/if (s.active)/d' "$work/original" ;; | ||
| restoration) sed 's/return mark(E, s, false)/return mark(E, s, true)/' "$work/original" ;; | ||
| identity) sed 's/.selected = endpoint/.selected = null/;s/const endpoint = get/_ = get/' "$work/original" ;; | ||
| status) sed 's/status <= 11/status <= 12/' "$work/original" ;; | ||
| esac > "$work/registry_state.zig" | ||
| ! cmp -s "$work/original" "$work/registry_state.zig" | ||
| zig build-exe "$work/runner.zig" -O ReleaseSafe -femit-bin="$work/mutant" > "$out/mutant-$mutation-build.txt" 2>&1 | ||
| "$work/mutant" > "$out/mutant-$mutation.tsv" | ||
| if cmp -s "$out/contract.tsv" "$out/mutant-$mutation.tsv"; then echo "FAIL $mutation escaped"; exit 1; fi | ||
| done | ||
| cp "$work/original" "$work/registry_state.zig" | ||
| (cd "$work"; sha256sum -c "$out/inputs.sha256") > "$out/recheck.txt" | ||
| cp "$work/"*.zig "$out/" | ||
| cp "$work/Abi/RegistryState.idr" "$out/" | ||
| idris2 --version > "$out/idris-version.txt" | ||
| zig version > "$out/zig-version.txt" | ||
| echo PASS > "$out/result.txt" | ||
| echo 'REGISTRY PASS: 900 two-operation traces, 17 signed statuses, four modes, five compiled mutants' | ||
|
|
||
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,54 @@ | ||
| -- SPDX-License-Identifier: MPL-2.0 | ||
| module Main | ||
| import Abi.Registry | ||
| import Abi.RegistryState | ||
| import Abi.Status | ||
| %default total | ||
|
|
||
| record Observation where | ||
| constructor Observe | ||
| code : Bits8 | ||
| state : State Nat | ||
| chosen : Maybe Nat | ||
|
|
||
| fromReply : Reply Nat -> Observation | ||
| fromReply r = Observe (statusTag (status r)) (next r) Nothing | ||
|
|
||
| step : Nat -> Slot -> State Nat -> Observation | ||
| step 0 k s = fromReply (register k 11 s) | ||
| step 1 k s = fromReply (register k 22 s) | ||
| step 2 k s = fromReply (unregister k s) | ||
| step 3 k s = case beginCall k s of | ||
| Left r => fromReply r | ||
| Right call => Observe 0 (duringCall call) (Just (selected call)) | ||
| step _ k s = Observe 0 (normalReturn (MkInvocation (entries s) 0)) Nothing | ||
|
|
||
| endpoint : Nat -> Maybe Nat | ||
| endpoint 0 = Nothing | ||
| endpoint 1 = Just 11 | ||
| endpoint _ = Just 22 | ||
|
|
||
| number : Maybe Nat -> String | ||
| number Nothing = "0" | ||
| number (Just n) = show n | ||
|
|
||
| render : Observation -> String | ||
| render (Observe code s chosen) = | ||
| show code ++ " " ++ number (restEndpoint (entries s)) ++ " " ++ | ||
| number (mcpEndpoint (entries s)) ++ " " ++ | ||
| (if busy s then "1" else "0") ++ " " ++ number chosen | ||
|
|
||
| main : IO () | ||
| main = do | ||
| for_ [0,1,2] $ \r => | ||
| for_ [0,1,2] $ \m => | ||
| for_ [False,True] $ \b => | ||
| for_ [RESTSlot,MCPSlot] $ \k => | ||
| for_ [0,1,2,3,4] $ \a => | ||
| for_ [0,1,2,3,4] $ \z => do | ||
| let first = step a k (MkState (MkRegistry (endpoint r) (endpoint m)) b) | ||
| let second = step z k (state first) | ||
| putStrLn (render first ++ " " ++ render second) | ||
| for_ [-2147483648,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,256,2147483647] $ \z => | ||
| putStrLn ("status " ++ show z ++ " " ++ show (statusTag (sanitize z))) | ||
|
|
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,41 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| const std = @import("std"); | ||
| const source = @import("registry_state.zig"); | ||
| const E = u32; | ||
| fn step(op: u8, slot: source.Slot, s: source.State(E)) source.Reply(E) { | ||
| return switch (op) { | ||
| 0 => source.register(E, s, slot, 11), | ||
| 1 => source.register(E, s, slot, 22), | ||
| 2 => source.unregister(E, s, slot), | ||
| 3 => source.begin(E, s, slot), | ||
| else => .{ .status = 0, .next = source.finish(E, s) }, | ||
| }; | ||
| } | ||
| pub fn main() !void { | ||
| var buf: [256]u8 = undefined; | ||
| const endpoints = [_]?E{ null, 11, 22 }; | ||
| for (endpoints) |r| { | ||
| for (endpoints) |m| { | ||
| for ([_]bool{ false, true }) |busy| { | ||
| for ([_]source.Slot{ .rest, .mcp }) |slot| { | ||
| for (0..5) |a| { | ||
| for (0..5) |z| { | ||
| const first = step(@intCast(a), slot, .{ .rest = r, .mcp = m, .active = busy }); | ||
| const second = step(@intCast(z), slot, first.next); | ||
| const line = try std.fmt.bufPrint(&buf, "{d} {d} {d} {d} {d} {d} {d} {d} {d} {d}\n", .{ | ||
| first.status, first.next.rest orelse 0, first.next.mcp orelse 0, @intFromBool(first.next.active), first.selected orelse 0, | ||
| second.status, second.next.rest orelse 0, second.next.mcp orelse 0, @intFromBool(second.next.active), second.selected orelse 0, | ||
| }); | ||
| try std.fs.File.stdout().writeAll(line); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| for ([_]c_int{ -2147483648, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 256, 2147483647 }) |z| { | ||
| const line = try std.fmt.bufPrint(&buf, "status {d} {d}\n", .{ z, source.sanitize(z) }); | ||
| try std.fs.File.stdout().writeAll(line); | ||
| } | ||
| } | ||
|
|
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,45 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| // Copyright (c) 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk> | ||
| // Pure state transitions used by the actual registry FFI. Endpoint values | ||
| // retain callback/context identity; ownership of their pointees is external. | ||
| pub const Slot = enum { mcp, rest }; | ||
|
|
||
| pub fn State(comptime E: type) type { | ||
| return struct { rest: ?E = null, mcp: ?E = null, active: bool = false }; | ||
| } | ||
| pub fn Reply(comptime E: type) type { | ||
| return struct { status: u8, next: State(E), selected: ?E = null }; | ||
| } | ||
| pub fn get(comptime E: type, s: State(E), slot: Slot) ?E { | ||
| return switch (slot) { .mcp => s.mcp, .rest => s.rest }; | ||
| } | ||
| pub fn put(comptime E: type, s: State(E), slot: Slot, endpoint: ?E) State(E) { | ||
| return switch (slot) { | ||
| .mcp => .{ .rest = s.rest, .mcp = endpoint, .active = s.active }, | ||
| .rest => .{ .rest = endpoint, .mcp = s.mcp, .active = s.active }, | ||
| }; | ||
| } | ||
| pub fn mark(comptime E: type, s: State(E), active: bool) State(E) { | ||
| return .{ .rest = s.rest, .mcp = s.mcp, .active = active }; | ||
| } | ||
| pub fn register(comptime E: type, s: State(E), slot: Slot, endpoint: E) Reply(E) { | ||
| if (s.active) return .{ .status = 6, .next = s }; | ||
| if (get(E, s, slot) != null) return .{ .status = 9, .next = s }; | ||
| return .{ .status = 0, .next = put(E, s, slot, endpoint) }; | ||
| } | ||
| pub fn unregister(comptime E: type, s: State(E), slot: Slot) Reply(E) { | ||
| if (s.active) return .{ .status = 6, .next = s }; | ||
| if (get(E, s, slot) == null) return .{ .status = 8, .next = s }; | ||
| return .{ .status = 0, .next = put(E, s, slot, null) }; | ||
| } | ||
| pub fn begin(comptime E: type, s: State(E), slot: Slot) Reply(E) { | ||
| if (s.active) return .{ .status = 6, .next = s }; | ||
| const endpoint = get(E, s, slot) orelse return .{ .status = 11, .next = s }; | ||
| return .{ .status = 0, .next = mark(E, s, true), .selected = endpoint }; | ||
| } | ||
| pub fn finish(comptime E: type, s: State(E)) State(E) { | ||
| return mark(E, s, false); | ||
| } | ||
| pub fn sanitize(status: c_int) c_int { | ||
| return if (status >= 0 and status <= 11) status else 6; | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
check-runtime-registry.shis run withZIG=/path/to/zig(orIDRIS2=/path/to/idris2), its existing checks use those configured binaries, but this newly invoked script switches back to barezigandidris2commands throughout. Consequently, environments where the selected compiler is not onPATH, or wherePATHcontains a different Zig version, now fail after the original runtime checks succeed or generate evidence with a different toolchain. Resolve the compiler paths once fromZIG/IDRIS2and use them for every command in this script.Useful? React with 👍 / 👎.