feat(ffi/zig): formal ABI verification — comptime proofs + boundary tests#247
Merged
Conversation
…y tests Adds two new Zig modules that establish the FFI ABI invariants as machine-checked axioms and verify them exhaustively: - `ffi/zig/src/abi_axioms.zig`: standalone file (no imports) declaring every ABI-crossing numeric constant as a comptime_int and proving invariants at compile time via `@compileError`. Four axiom domains: invocation (RC_* codes), catalogue (status/protocol/domain/tier/bounds), loader (hash lengths, LOADER_MATCH≠CAT_OK trap), safety (SAFETY_SAFE≠0 trap). `zig build abi-axioms` is a pure compile-time proof step. - `ffi/zig/src/abi_verify.zig`: cross-checks live Zig enum/constant values against the axioms at compile time (§A), then runs 40 runtime boundary tests (§B catalogue, §C invocation shim, §D hash constants, §E safety, §F thread-safety). `zig build abi-verify` runs 40 tests. Trust taxonomy used throughout: [STATIC] comptime in-file, [CROSS] comptime cross-module, [RUNTIME] boundary test, [ASSUMED] cross-language contract. Also fixes Zig 0.16 API break: `std.Thread.Mutex` was removed. Nine FFI modules (catalogue, loader, sla, coprocessor, community, sdp, guardian, verisimdb, federation) are migrated to a local Mutex wrapper over `std.atomic.Mutex` + `spinLoopHint()`. The wrapper preserves the `.lock()/.unlock()` API so call sites are unchanged. Adds `docs/zig-ffi-verification.adoc` documenting the verification methodology, evidence taxonomy, known gaps (loader import conflict, C header alignment, Idris2 cross-language contract), and how to run. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F8pqMfJViUaKabWKNQ9wUg
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
boj-server | e259f83 | Jun 24 2026, 04:02 PM |
| @@ -0,0 +1,726 @@ | |||
| // SPDX-License-Identifier: MPL-2.0 | |||
🔍 Hypatia Security ScanFindings: 218 issues detected
View findings[
{
"reason": "Action actions/checkout@v4 needs attention",
"type": "unpinned_action",
"file": "pages-deploy.yml",
"action": "pin_sha",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in pages-deploy.yml",
"type": "missing_timeout_minutes",
"file": "pages-deploy.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in scorecard-enforcer.yml",
"type": "missing_timeout_minutes",
"file": "scorecard-enforcer.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "Issue in scorecard-enforcer.yml",
"type": "scorecard_publish_with_run_step",
"file": "scorecard-enforcer.yml",
"action": "split_scorecard_publish_job",
"rule_module": "workflow_audit",
"severity": "high"
},
{
"reason": "Issue in instant-sync.yml",
"type": "secret_action_without_presence_gate",
"file": "instant-sync.yml",
"action": "peter-evans/repository-dispatch",
"rule_module": "workflow_audit",
"severity": "high"
},
{
"reason": "Issue in codeql.yml",
"type": "codeql_missing_actions_language",
"file": "codeql.yml",
"action": "flag",
"rule_module": "workflow_audit",
"severity": "medium"
},
{
"reason": "TypeScript file detected -- banned language",
"type": "banned_language_file",
"file": "/home/runner/work/boj-server/boj-server/cartridges/academic-workflow-mcp/adapter/mod.ts",
"action": "flag",
"rule_module": "cicd_rules",
"severity": "critical"
},
{
"reason": "TypeScript file detected -- banned language",
"type": "banned_language_file",
"file": "/home/runner/work/boj-server/boj-server/cartridges/ephapax-mcp/adapter/mod.ts",
"action": "flag",
"rule_module": "cicd_rules",
"severity": "critical"
},
{
"reason": "TypeScript file detected -- banned language",
"type": "banned_language_file",
"file": "/home/runner/work/boj-server/boj-server/cartridges/bofig-mcp/adapter/mod.ts",
"action": "flag",
"rule_module": "cicd_rules",
"severity": "critical"
},
{
"reason": "TypeScript file detected -- banned language",
"type": "banned_language_file",
"file": "/home/runner/work/boj-server/boj-server/cartridges/fireflag-mcp/adapter/mod.ts",
"action": "flag",
"rule_module": "cicd_rules",
"severity": "critical"
}
]Powered by Hypatia Neurosymbolic CI/CD Intelligence |
🏁 path-claims benchCommit NumbersHost-dependent — compare deltas across commits, not absolute values. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
ffi/zig/src/abi_axioms.zig— standalone file (no imports) declaring every ABI-crossing numeric constant ascomptime_intand proving invariants via@compileError. Pure compile-time step:zig build abi-axioms.ffi/zig/src/abi_verify.zig— 40 tests: §A comptime cross-module proofs (live Zig types vs axioms), §B–E exhaustive C-ABI boundary tests (catalogue, invocation shim, hash constants, safety), §F thread-safety spot check. Run withzig build abi-verify.std.Thread.Mutexwas removed; 9 FFI modules patched with a localMutexwrapper overstd.atomic.Mutex+spinLoopHint(). Call sites unchanged.docs/zig-ffi-verification.adoc— documents the verification methodology, evidence taxonomy ([STATIC]/[CROSS]/[RUNTIME]/[ASSUMED]), trust chain (Idris2 → axioms → comptime → tests), known gaps, and how to run.Verification results
Trust taxonomy
comptimein same file — binary cannot violate itcomptimecross-module inabi_verify.zig— fires at compile timeKnown gaps (documented in §A.6 / docs)
loader.ziguses@import("catalogue.zig")(relative path), preventing it from being imported alongsidecatalogueinabi_verify.zig. Fix: change to@import("catalogue").generated/abi/boj_catalogue.h#definevalues are not auto-checked against axioms. Manual cross-check confirms parity at time of writing.Test plan
zig build abi-axioms— compile-time proofs greenzig build abi-verify— 40/40 tests passzig build seams shim— existing tests unaffected (38/38 pass)docs/zig-ffi-verification.adocfor accuracy🤖 Generated with Claude Code
https://claude.ai/code/session_01F8pqMfJViUaKabWKNQ9wUg
Generated by Claude Code