Skip to content

ABI Layer 4: prove the FFI result-code seam is injective + faithful#38

Merged
hyperpolymath merged 5 commits into
mainfrom
claude/new-session-znxgm7
Jun 28, 2026
Merged

ABI Layer 4: prove the FFI result-code seam is injective + faithful#38
hyperpolymath merged 5 commits into
mainfrom
claude/new-session-znxgm7

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Summary

Layer 4 (seal the ABI↔FFI seam): proves the FFI result-code encoding (resultToInt) is a sound, lossless wire encoding — decoder intToResult with resultRoundTrip, from which resultToIntInjective is derived. Distinct ABI outcomes never collide on the C wire. Complements the structural abi-ffi-gate.py.

New module *.ABI.FfiSeam (imports Types). Positive + non-vacuity controls.

Testing

Idris2 0.7.0 --build → exit 0, zero warnings. Adversarial rejection confirmed. build/ removed. No believe_me/postulate/sorry.

🤖 Generated with Claude Code

https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx


Generated by Claude Code

claude and others added 5 commits June 27, 2026 19:44
Add Nimiser.ABI.Semantics, a machine-checked semantic proof that the
Nim->C code generator preserves source signatures: same name, same
arity, and every argument/return type lowered by the canonical injective
nimToC mapping. An arity or type mismatch is unrepresentable as a
SigPreserved witness.

Contents:
- Faithful model: NimT / CT type universes, NimSig / CSig signatures,
  total nimToC lowering, genBinding code generator.
- Headline property SigPreserved with no constructor for any mismatch.
- genBindingPreserves: the generator ALWAYS preserves (soundness).
- nimToCInjective: the lowering is injective (non-vacuity engine).
- decSigPreserved: sound + complete Dec decision procedure.
- certifyBinding + certifyBindingSound tied to the project Result type;
  generatedAlwaysCertifies corollary.
- Positive control samplePreserved (explicit witness) and three
  negative controls (wrong return type, wrong arity, wrong arg type),
  all machine-checked.

Build: idris2 --build nimiser-abi.ipkg exits 0, zero warnings.
Adversarial false proof (claiming a type-mismatched binding is
preserved) is rejected by the type-checker, confirming non-vacuity.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
Adds Nimiser.ABI.Invariants over the existing Semantics codegen model
(NimT/CT/nimToC/NimSig/CSig/genBinding/ArgsLower), proving two facts
deeper than and distinct from the Layer-2 signature-preservation theorem:

1. Composition/distributivity: lowering is a homomorphism over argument-
   list concatenation (lowerAppendDistrib), lifted relationally
   (argsLowerAppend) and to signature extension (genBindingExtendComposes,
   extendedArgsLower) — codegen of a grown proc is the grown codegen.
2. Whole-signature injectivity: genBindingInjective shows distinct Nim
   signatures lower to distinct C bindings (no symbol/ABI aliasing),
   strictly stronger than the Layer-2 per-type nimToCInjective lemma.

Includes a sound+complete DecEq NimSig, a positive control (composed
ArgsLower witness on concrete data) and negative/non-vacuity controls
(distinctSigsDistinctBindings, extensionChangesBinding, decEqDistinctIsNo).
Builds clean (exit 0, zero warnings); adversarial false-equality proof via
genBindingInjective is rejected. No believe_me/postulate/assert_total/etc.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
Seals the ABI<->FFI seam on the proof side: proves the Result result-code
encoding is sound, complementing the structural abi-ffi-gate.py check.

- intToResult: total Bits32 -> Maybe Result decoder
- resultRoundTrip: faithful/lossless encoding (decode . encode = Just)
- resultToIntInjective: distinct outcomes never collide on the wire,
  derived from the round-trip via justInjective . cong
- positive controls (decode 0/7/8) and a non-vacuity negative control
  (Not (resultToInt Ok = resultToInt Error)), all machine-checked

No ProofStatus/statusToInt or other FFI enum encoder exists in this ABI,
so Result is the sole seam. Genuine total proof: no believe_me, postulate,
assert_total, idris_crash, or %hint hacks. Builds clean with zero warnings.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A6PSzJWpRxtzGDjUCEh7Mx
Signed-off-by: Jonathan D.A. Jewell <6759885+hyperpolymath@users.noreply.github.com>
@hyperpolymath hyperpolymath marked this pull request as ready for review June 28, 2026 06:42
@hyperpolymath hyperpolymath merged commit 8e0badc into main Jun 28, 2026
6 checks passed
@hyperpolymath hyperpolymath deleted the claude/new-session-znxgm7 branch June 28, 2026 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants