Repository navigation
test(ffi): fail-closed Rustler/libproven ABI symbol contract with planted controls #236
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
Open
hyperpolymath
wants to merge
11
commits into
main
Choose a base branch
from
test/nif-real-abi-link-contract
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
de5ee81
test(ffi): add fail-closed native Rustler symbol contract and planted…
hyperpolymath ead5185
test(ffi): add fail-closed native Rustler symbol contract and planted…
hyperpolymath fe46aba
test(ffi): add fail-closed native Rustler symbol contract and planted…
hyperpolymath 254bd07
ci(ffi): exercise planted controls and gate real Idris-Zig artifact s…
hyperpolymath e1a8778
fix(ffi): fail closed when private Idris2 bridge dependency is unavai…
hyperpolymath 597e440
fix(refc): reject missing or stale Idris2 C output and eliminate dupl…
hyperpolymath 9c95a13
test(refc): plant empty, stale, fresh and compiler-failure staging co…
hyperpolymath 788daff
ci(refc): run adversarial fresh-output staging controls
hyperpolymath 60b636f
docs(ffi): record measured Idris2 RefC package scope and fresh-stage …
hyperpolymath 8f75c7f
fix(ffi): handle qualified Rust declarations and default-version symb…
coderabbitai[bot] e757802
test(refc): verify stale staged sources are removed without --clean
coderabbitai[bot] 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,80 @@ | ||
| // SPDX-License-Identifier: CC-BY-SA-4.0 | ||
| // SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell | ||
| = Native libproven / Rustler ABI boundary | ||
|
|
||
| This repository currently has a *broken consumer boundary*, not a missing | ||
| search directory alone. `bindings/elixir/native/proven_nif/src/lib.rs` | ||
| declares 66 `proven_*` C ABI functions. The current | ||
| `ffi/zig/src/main.zig` exports 17 `proven_*` functions and does not | ||
| define most of the required functions, such as `proven_math_div`. | ||
| The shared name `proven_init` also has incompatible return types: | ||
| Rust declares `i32` while Zig returns an optional `*Handle`. | ||
| These are source observations, not a verified inventory of any | ||
| generated Idris2 RefC C output. | ||
|
|
||
| == Actual Idris2 RefC package scope | ||
|
|
||
| On 2026-11-15 an isolated checkout ran `idris2 --build proven-ffi.ipkg` | ||
| and `idris2 --codegen refc --build proven-ffi.ipkg` using Idris2 | ||
| 0.8.0. Both compiled successfully. The package currently lists | ||
| `Proven.Core`, `Proven.SafeUrl.Parser`, | ||
| `Proven.FFI.SafeUrl` and `Proven.FFI.Main`; compilation also loads | ||
| the imported SafeUrl/Query modules. `Proven.FFI.Main` references | ||
| *SafeUrl only*. This package does not presently include an Idris2 FFI | ||
| implementation for the Rustler NIF's math, crypto, string and other | ||
| API families. A successfully generated `proven-ffi.c` is **not** a | ||
| complete 66-function Idris-backed ABI. | ||
|
|
||
| The existing `scripts/build-refc.sh` also previously scanned | ||
| `build/exec` and its parent `build` (double-counting the same | ||
| source), and could report success even when the compiler produced no | ||
| C. It now requires at least one *fresh* generated C source, deduplicates | ||
| the scan, and replaces stale staged sources. The five fake-compiler | ||
| controls in `tests/check-refc-staging.sh` exercise empty, stale, | ||
| fresh and failed generation, while an independent live Idris2/RefC | ||
| build has confirmed one generated source file. Neither fixture | ||
| testing nor one generated C source proves complete ABI parity. | ||
|
|
||
| == A mandatory precondition, not a substitute for proof | ||
|
|
||
| Run `bash scripts/check-native-nif-exports.sh /path/to/libproven.so` | ||
| *after* the authentic Idris2 -> RefC -> Zig library build. | ||
| For a static library, pass `libproven.a` instead. | ||
|
|
||
| The checker extracts required C symbols from the Rust `extern "C"` block | ||
| and confirms that the compiled library *defines* all of them. Missing | ||
| names cause exit 1; missing tools/inputs or unreadable artifacts cause | ||
| exit 2 (NOT RUN); only a complete symbol list gives exit 0. | ||
|
|
||
| The script expressly **does not verify ABI types, memory ownership, | ||
| verified Idris2 provenance, dynamic dependencies, or behavioural | ||
| semantics**. Its positive controls are fixture libraries, not | ||
| `libproven` evidence. Type/layout compatibility must additionally be | ||
| checked against an authoritative C header, with compiled calls and | ||
| negative fixtures, before declaring the full interface safe. | ||
| Actual runtime behaviour must be exercised from Elixir and Rust. | ||
|
|
||
| == Required upstream repairs | ||
|
|
||
| . Resolve the currently private `nextgen-languages/language-bridges` | ||
| dependency with correctly scoped credentials or a reviewed vendor pin. | ||
| . Produce genuine Idris2 RefC code, with pinned compiler/runtime inputs, | ||
| and include the required ABI implementation in the Zig linker. | ||
| . Agree whether the consumer links a static or shared `libproven`. | ||
| The Zig build currently emits a static target while Rust explicitly | ||
| requests `dylib=proven`. | ||
| . Repair all 66 function contracts, including `proven_init` return | ||
| type and correct ownership of returned buffers. | ||
| . Check exported symbols on *the exact artifact to be consumed*; run | ||
| typed calls against it and the real Elixir/Rustler integration. | ||
| . Publish immutable, attestable artifact provenance and a pinned, | ||
| reproducible consumer configuration. Never silently substitute | ||
| `build_standalone.zig`, which builds a narrower pure Zig ABI. | ||
|
|
||
| == Positive and negative gate controls | ||
|
|
||
| `bash tests/check-native-nif-exports.sh` runs six isolated cases: | ||
| a defined shared and static fixture, deliberately missing symbols, | ||
| missing input, an empty contract, and a corrupt binary. These tests | ||
| establish only that the name-presence gate fails closed; they do | ||
| not certify this repository's actual `libproven` ABI. |
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,94 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell | ||
| # | ||
| # Verify the *defined* exported symbols in a compiled libproven artifact | ||
| # cover the Rustler consumer's declared C ABI. This is a necessary, not | ||
| # sufficient, ABI condition: it does not establish compatible signatures, | ||
| # ownership, verified Idris provenance, or correct behaviour. | ||
| # | ||
| # Usage: bash scripts/check-native-nif-exports.sh LIBPROVEN [NIF_LIB_RS] | ||
| # Exit 0: all required names are defined; 1: missing symbols; 2: NOT RUN. | ||
| set -euo pipefail | ||
|
|
||
| if [[ $# -lt 1 || $# -gt 2 ]]; then | ||
| echo 'PROVEN_NIF_ABI_CLASS=not_run:usage' >&2 | ||
| echo 'usage: check-native-nif-exports.sh LIBPROVEN [NIF_LIB_RS]' >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) | ||
| lib=$1 | ||
| nif=${2:-"$root/bindings/elixir/native/proven_nif/src/lib.rs"} | ||
|
|
||
| if [[ ! -f $lib || ! -r $lib || ! -f $nif || ! -r $nif ]]; then | ||
| echo 'PROVEN_NIF_ABI_CLASS=not_run:missing_input' >&2 | ||
| exit 2 | ||
| fi | ||
| for cmd in awk comm nm sort wc; do | ||
| command -v "$cmd" >/dev/null 2>&1 || { | ||
| echo "PROVEN_NIF_ABI_CLASS=not_run:missing_tool:$cmd" >&2 | ||
| exit 2 | ||
| } | ||
| done | ||
|
|
||
| tmp=$(mktemp -d) | ||
| trap 'rm -rf -- "$tmp"' EXIT | ||
|
|
||
| # Scan only the Rust extern-C block. Do not count Rust NIF wrappers or | ||
| # incidental function names elsewhere in the file. | ||
| awk ' | ||
| /^[[:space:]]*extern "C"[[:space:]]*\{/ { in_extern=1; next } | ||
| in_extern && /^[[:space:]]*\}/ { in_extern=0 } | ||
| in_extern && /^[[:space:]]*((pub(\([^)]*\))?|safe|unsafe)[[:space:]]+)*fn[[:space:]]+proven_[A-Za-z0-9_]+[[:space:]]*\(/ { | ||
| line=$0 | ||
| sub(/^[[:space:]]*((pub(\([^)]*\))?|safe|unsafe)[[:space:]]+)*fn[[:space:]]+/, "", line) | ||
| sub(/[[:space:]]*\(.*/, "", line) | ||
| print line | ||
| } | ||
| ' "$nif" | LC_ALL=C sort -u > "$tmp/required" | ||
|
|
||
| if [[ ! -s $tmp/required ]]; then | ||
| echo 'PROVEN_NIF_ABI_CLASS=not_run:empty_contract' >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| case $lib in | ||
| *.a) nm -g --defined-only "$lib" > "$tmp/nm" 2>"$tmp/nm-error" || { | ||
| echo 'PROVEN_NIF_ABI_CLASS=not_run:unreadable_archive' >&2 | ||
| cat "$tmp/nm-error" >&2 | ||
| exit 2 | ||
| } ;; | ||
| *.so|*.so.*) nm -D --defined-only "$lib" > "$tmp/nm" 2>"$tmp/nm-error" || { | ||
| echo 'PROVEN_NIF_ABI_CLASS=not_run:unreadable_shared_lib' >&2 | ||
| cat "$tmp/nm-error" >&2 | ||
| exit 2 | ||
| } ;; | ||
| *) | ||
| echo 'PROVEN_NIF_ABI_CLASS=not_run:unsupported_artifact' >&2 | ||
| exit 2 ;; | ||
| esac | ||
|
|
||
| # Use only defined symbols; never mistake an undefined (U) reference for | ||
| # evidence that a function exists. nm --defined-only excludes those. | ||
| # Default-version definitions satisfy unversioned consumers; single-@ aliases do not. | ||
| awk '{ | ||
| symbol=$NF | ||
| sub(/@@[^@[:space:]]+$/, "", symbol) | ||
| if (symbol ~ /^proven_[A-Za-z0-9_]+$/) print symbol | ||
| }' "$tmp/nm" | | ||
| LC_ALL=C sort -u > "$tmp/defined" | ||
|
|
||
| LC_ALL=C comm -23 "$tmp/required" "$tmp/defined" > "$tmp/missing" | ||
|
|
||
| required_count=$(wc -l < "$tmp/required") | ||
| defined_count=$(wc -l < "$tmp/defined") | ||
| missing_count=$(wc -l < "$tmp/missing") | ||
| echo "NIF ABI symbols: required=$required_count artifact_defined=$defined_count missing=$missing_count" | ||
| if [[ -s $tmp/missing ]]; then | ||
| echo 'PROVEN_NIF_ABI_CLASS=missing_symbols' >&2 | ||
| sed 's/^/ missing C ABI symbol: /' "$tmp/missing" >&2 | ||
| exit 1 | ||
| fi | ||
| echo 'PROVEN_NIF_ABI_CLASS=symbols_present_only' | ||
| echo 'NOTE: symbol coverage is NOT ABI type conformance or formal proof.' |
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.