Skip to content

[cargo-anneal] Add Receipt v3 ForeignEntryContract and verify.rs wiring - #591

Merged
joshlf merged 1 commit into
mainfrom
joshlf/ffi-export-entry-spine-p2
Dec 6, 2026
Merged

joshlf merged 1 commit into
mainfrom
joshlf/ffi-export-entry-spine-p2

Conversation

@joshlf

@joshlf joshlf commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Wire cargo-anneal to opt into and enforce Phase 1 non-variadic, non-unwinding extern "C" and Linux extern "system" export verification on top of the Ring-0 Body.abi metadata and ffi_exports.json manifest capture infrastructure:

  • Foreign-entry manifest parsing and ForeignEntryContract builder (trusted/cargo-anneal/src/core/foreign_entry.rs, trusted/cargo-anneal/src/core/mod.rs): Strictly parse and validate capture/ffi_exports.json (#[serde(deny_unknown_fields)], schema version, target, 64-bit pointer width, ambient_obligations, record and enum layout tables including Vec, FnPtr.c_variadic, payload enums, FfiEnumTagEncoding, and "uninhabited"/"untagged"/"none" discriminants, structural extra-validity classification, and exact per-export signature_sha256 recomputation), cross-check captured foreign-ABI bodies (abi != .rust) 1:1 against capture.json, and emit deterministic ForeignEntryContract records with explicit per-parameter entry_validity clauses, safety_pre (for unsafe exports only), fixed ambient.* clauses, non-suppressible D3 extra-validity warnings (extra_validity_parameter), and an explicit baseline byte-initialization validity caveat (MaybeUninit<T> contrast) so non-flagged scalar/pointer parameters are never implied to be validity-free.
  • verify.rs wiring (trusted/cargo-anneal/src/verify.rs): Pass --allow-foreign-exports to anneal-rustc-capture on non-stdlib runs, authenticate configuration.allow_foreign_exports in capture.json fail-closed whenever foreign-ABI bodies or ffi_exports.json appear, refuse foreign exports on MirEnvelope (#[spec]) requests, hash ffi_exports.json into ffi_exports_manifest_sha256, record FOREIGN_ENTRY_RECEIPT_ASSUMPTION in assumptions, and attach foreign_entry_contracts to Receipt v3.
  • Receipt v3 inspect & human output (trusted/cargo-anneal/src/core/inspect/{schema,render,diff}.rs, trusted/cargo-anneal/src/inspect.rs, trusted/cargo-anneal/src/output.rs): Enforce strict envelope validation (symmetric allow_foreign_exports, assumptions, ffi_exports_manifest_sha256, foreign_entry_contracts, Phase 1 residual-only discharge), verify capture/ffi_exports.json SHA-256 and re-derived contracts in --verify-artifacts, render human/ledger/ card disclosures and warnings, and classify foreign-entry changes and regressions in three-tier diff_receipts.
  • End-to-end tests, docs, and taxonomy lockstep (tests/cargo-anneal/tests/suite/ffi_export_entry_e2e.rs, tests/cargo-anneal/tests/cli/sharding_and_limits/, tests/cargo-anneal/tests/cli/foreign_entry_guards.rs, tests/testkit/src/assertions.rs, .config/nextest.toml, docs/alpha.md, docs/trust-model.md, tools/anneal-corpus-scan/canonical_taxonomy_v1.json, ci/test_check_taxonomy_lockstep.py, ci/verify_zerocopy.py, ci/test_verify_zerocopy.py): Add E2E scalar extern "C" verification under panic=unwind + overflow_checks: true, tamper and missing-flag controls, extra-validity warning + safety_pre test, and safe-export precondition refusal control, and promote item_extern_c_export_non_unwinding to SUPPORTED_END_TO_END.

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf
joshlf force-pushed the joshlf/ffi-export-entry-spine-p2 branch from 38cb035 to 0f59386 Compare December 4, 2026 14:55
@joshlf

joshlf commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

🤖 Exact-HEAD verification receipt for PR 2 (HEAD=0f59386928458ad9028b69a3028329344688859e, TREE=f79bd9fda922eb9110409427b852aaec1dca52cd, BASE=93166ae3c4fc30c6852dace54223ad2eccebaa16), implementing cargo-anneal Receipt v3 ForeignEntryContract, inspect, and verify.rs wiring on top of #460 .

PR State: Strictly Draft (--draft) pending cross-family Gate-1 R3 0/0/0 CLEAN and green ci-core execute shards.

  • Cross-family Gate-1 R1: 0 P0 / 0 P1 / 1 P2 (rejected unrecognized or non-residual ambient_obligations fail-closed; fixed and unit-tested).
  • Cross-family Gate-1 R2: 0 P0 / 0 P1 / 2 P2 (same-symbol signature_hash/abi change classified Tier A in diff.rs; added tests/cargo-anneal/tests/cli/foreign_entry_guards.rs covering --allow-foreign-exports forwarding and 8 capture-side fail-closed gates; fixed in 38cb035a2637).
  • CI shard 7/8 fix (0f5938692845, Python-only delta over 38cb035a2637): updated ci/verify_zerocopy.py (VALID_RECEIPT_CONFIGURATION_KEYS + fail-closed checks on non-True allow_foreign_exports and unexpected ffi_exports_manifest_sha256 / foreign_entry_contracts) and added unit tests in ci/test_verify_zerocopy.py.

Human review surface

  • ci/test_check_taxonomy_lockstep.py
  • ci/test_verify_zerocopy.py
  • ci/verify_zerocopy.py
  • docs/trust-model.md
  • trusted/cargo-anneal/src/core/foreign_entry.rs
  • trusted/cargo-anneal/src/core/inspect/diff.rs
  • trusted/cargo-anneal/src/core/inspect/render.rs
  • trusted/cargo-anneal/src/core/inspect/schema.rs
  • trusted/cargo-anneal/src/core/mod.rs
  • trusted/cargo-anneal/src/inspect.rs
  • trusted/cargo-anneal/src/output.rs
  • trusted/cargo-anneal/src/verify.rs

Verification ([real measurement])

  • Exact HEAD=0f5938692845 (Python/CI delta + repo gates):
    • PYTHONPATH=ci python3 -B -m unittest ci/test_verify_zerocopy.py — 31 passed, 0 failed (1.149s)
    • PYTHONPATH=ci python3 -B -m unittest ci/test_perf_tracking.py — 32 passed, 0 failed (8.282s)
    • ./ci/check_todo.sh — pass
    • python3 -B ci/check_contract_lockstep.py — OK (1 contract(s) verified)
    • python3 -B ci/check_taxonomy_lockstep.py — OK (18 enums, 335 variants, 101 constructs, 215 source refs)
    • python3 -B ci/run_fast_checks.py — 3/3 pass (ci-manifest-and-workflow-hygiene, docs-and-agents-path-sync, skills-and-docs-drift)
    • python3 -B ci/check_pr_hygiene.py --base 93166ae3c4fc30c6852dace54223ad2eccebaa16 --head HEAD --receipt-file ... — 0 findings
  • Identical Rust/Lean tree (38cb035a2637; zero Rust/Lean files changed in 0f5938692845):
    • cargo test --locked --offline -p cargo-anneal --lib -- foreign_entry inspect:: — 63 passed, 0 failed (1.59s; 382 unrelated tests filtered out)
    • cargo test --locked --offline -p cargo-anneal-tests --no-default-features --test cli --test inspect — 129/129 cli passed (11.60s), 46/46 inspect passed (14.07s)
    • cargo test --locked --offline -p cargo-anneal-tests --test suite -- ffi_export_entry (pinned Lean v4.35.0) — 3 passed, 0 failed (193.49s; 79 unrelated tests filtered out)
    • RUSTFLAGS="-D warnings" cargo clippy --locked --offline -p cargo-anneal --lib --bins -- -D warnings and -p cargo-anneal-tests --no-default-features --test cli -- -D warnings — pass
    • RUSTFLAGS="-D warnings" cargo check --locked --offline -p cargo-anneal --no-default-features --lib --target wasm32-unknown-unknown — pass
    • python3 -B -m unittest ci/test_check_taxonomy_lockstep.py — 4 tests OK
    • GitHub Actions ci-core on 38cb035a2637: 36/38 execute shards passed (only shards 7 & 8 failed on ci/verify_zerocopy.py unexpected configuration keys=['allow_foreign_exports'], fixed here; fresh CI re-running on 0f5938692845).

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf

joshlf commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

🤖 Exact-HEAD verification receipt for PR 2 (HEAD=2fb9d54b3c1b59caad2f11230947a5c2f2519fff, TREE=0cded65e7aa81d0928c850b3721602c83a44c420, BASE=3dd88838b1dc1dc8794ba9c1075e55003a7bc0b4), implementing cargo-anneal Receipt v3 ForeignEntryContract, inspect, and verify.rs wiring on top of #460 .

PR State: Strictly Draft (--draft, autoMergeRequest=null), rebased onto 3dd88838b1dc1dc8794ba9c1075e55003a7bc0b4 with cross-family Gate-1 review CLEAN (0 P0 / 0 P1 / 0 P2) across all 23 changed files (--tcb human review surface listed below).

Review Hardening Incorporated

  • Rejected unrecognized or non-residual ambient_obligations entries fail-closed in foreign_entry.rs.
  • Removed dead visiting_enums plumbing in ty_requires_structural_extra_validity (matching ValidityReasonCollector, where every enum carries restricted discriminant validity).
  • Rejected captured bodies with is_external = true and non-Rust ABI fail-closed in both verify.rs and foreign_entry.rs (inspect --verify-artifacts), with unit and CLI guard coverage.
  • Enforced strict 1:1 source <-> id binding in parse_foreign_entry_contracts_strict (safety_pre, REQUIRED_AMBIENT_CLAUSE_IDS, and entry_validity.baseline_byte_initialization / entry_validity.param.<index>.<name>).
  • Hardened diff_foreign_entry_contracts: reusing an existing link symbol with a different rust_identity, signature_hash, or abi (including symbol swaps) is Tier A; safety_pre evidence_hash changes follow require_unchanged_specs and Specs.safety <-> SpecsV2.safety predicate migration stays Tier B without false --no-regressions failures.
  • Added tests/cargo-anneal/tests/cli/foreign_entry_guards.rs covering --allow-foreign-exports forwarding and capture-side fail-closed gates, and updated ci/verify_zerocopy.py (VALID_RECEIPT_CONFIGURATION_KEYS + fail-closed foreign-export receipt assertions).

Human review surface (--tcb)

  • ci/test_check_taxonomy_lockstep.py
  • ci/test_verify_zerocopy.py
  • ci/verify_zerocopy.py
  • docs/trust-model.md
  • trusted/cargo-anneal/src/core/foreign_entry.rs
  • trusted/cargo-anneal/src/core/inspect/diff.rs
  • trusted/cargo-anneal/src/core/inspect/render.rs
  • trusted/cargo-anneal/src/core/inspect/schema.rs
  • trusted/cargo-anneal/src/core/mod.rs
  • trusted/cargo-anneal/src/inspect.rs
  • trusted/cargo-anneal/src/output.rs
  • trusted/cargo-anneal/src/verify.rs

Verification ([real measurement] on exact HEAD=2fb9d54b3c1b59caad2f11230947a5c2f2519fff)

  • cargo test --locked --offline -p cargo-anneal --lib -- foreign_entry inspect:: — 63 passed, 0 failed (1.78s; 382 unrelated tests filtered out)
  • cargo test --locked --offline -p cargo-anneal-tests --no-default-features --test cli --test inspect — 129/129 cli passed (11.95s), 46/46 inspect passed (16.76s)
  • cargo test --locked --offline -p cargo-anneal-tests --test suite -- ffi_export_entry (with anneal-rustc-capture built on pinned nightly-2026-05-31 and Lean 4.36.0) — 3 passed, 0 failed (202.28s; 79 unrelated tests filtered out)
  • cargo clippy --locked --offline --no-deps -p cargo-anneal --no-default-features --lib --bins -- -A clippy::type_complexity -D warnings — pass (10.25s)
  • cargo clippy --locked --offline --no-deps -p cargo-anneal-tests --no-default-features --test cli --test inspect -- -A clippy::type_complexity -D warnings — pass (5.02s)
  • RUSTFLAGS="-D warnings" cargo check --locked --offline -p cargo-anneal --no-default-features --lib --target wasm32-unknown-unknown — pass (13.15s)
  • PYTHONPATH=ci python3 -B -m unittest ci/test_verify_zerocopy.py ci/test_perf_tracking.py — 64 tests OK (15.467s)
  • python3 -B -m unittest ci/test_check_taxonomy_lockstep.py — 4 tests OK (75.033s)
  • ./ci/check_todo.sh — pass
  • python3 -B ci/check_contract_lockstep.py — OK (1 contract(s) verified)
  • python3 -B ci/check_taxonomy_lockstep.py — OK (18 enums, 335 variants, 101 constructs, 215 source refs)
  • python3 -B ci/run_fast_checks.py — 3/3 pass (ci-manifest-and-workflow-hygiene, docs-and-agents-path-sync, skills-and-docs-drift)
  • python3 -B ci/check_pr_hygiene.py --base 3dd88838b1dc1dc8794ba9c1075e55003a7bc0b4 --head HEAD --receipt-file ... — 0 findings
  • Cross-family Gate-1 review: CLEAN (0 P0 / 0 P1 / 0 P2; 23/23 changed files inspected).
  • Not yet exercised on 2fb9d54b3c1b: full GitHub Actions ci-core matrix (runs upon push).

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf
joshlf force-pushed the joshlf/ffi-export-entry-spine-p2 branch from 0f59386 to 2fb9d54 Compare December 5, 2026 00:44

@joshlf joshlf left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Authored by an AI agent acting on joshlf's behalf.

Gate 2 Independent Cross-Family Review — FINDINGS (tier2a_core_tcb, Round 1)

  • Identity: multi:01ff20e13ed8a2b3e0ff3ef598355e92255f7f8a:2fb9d54b3c1b59caad2f11230947a5c2f2519fff (base=01ff20e13ed8, head=2fb9d54b3c1b, tree=0cded65e7aa8)
  • Separation: author_family=agent vs. reviewer_family=multi
  • Coverage: 23 inspected, 0 inapplicable, 0 blocked (of 23 changed file(s))
Seat Family Role Status Verdict Findings Latency
seat1 claude-frontier-thinking tcb_and_api_critic completed clean 0 1352s
seat2 gemini-frontier-thinking tcb_and_spec_critic completed findings 3 1061s
seat3 gemini-executable-falsifier sandboxed_probe_runner completed clean 0 1591s

Deduplicated Findings

ID Sev Consensus Verification Location Summary
G2-R1-01 P2 1 (seat2) static_verified trusted/cargo-anneal/src/core/foreign_entry.rs:770 ty_requires_structural_extra_validity traverses FfiType::Record DAGs without memoization, causing O(2^N) exponential hangs on diamond record DAGs.
G2-R1-02 P2 1 (seat2) static_verified trusted/cargo-anneal/src/core/foreign_entry.rs:1197 build_foreign_entry_contracts and parse_foreign_entry_contracts_strict admit abi.kind == "system" on non-Linux targets instead of enforcing the Linux-only extern "system" boundary.
G2-R1-03 P2 1 (seat2) static_verified trusted/cargo-anneal/src/core/foreign_entry.rs:1739 parse_discharge_strict rewrites forbidden Phase-1 string discharges (by_c_typing, by_build_assert, by_ffi_check) to CallerClauseDischarge::Residual, corrupting parsed JSON output and hiding mutations in diff_receipts.

G2-R1-01 [P2] (trusted/cargo-anneal/src/core/foreign_entry.rs:770, Pass 2 §3 (trusted/cargo-anneal), static_verified): ty_requires_structural_extra_validity traverses FfiType::Record DAGs without memoization, causing O(2^N) exponential hangs on diamond record DAGs.

  • Invariant: Manifest validation in trusted/cargo-anneal must run in linear/polynomial time on valid acyclic ffi_exports.json record graphs, matching rustc-capture's memoized ValidityReasonCollector (trusted/rustc-capture/src/ffi_exports.rs:1754-1763,1897-1944).
  • Evidence: In trusted/cargo-anneal/src/core/foreign_entry.rs:798-814, the FfiType::Record arm inserts rust_name into visiting_records, evaluates rec.fields.iter().any(...), and removes rust_name on exit with no acyclic memo table. For a 40-level diamond DAG of baseline-initialized structs (e.g. zero-sized #[repr(C)] struct S_k(S_{k-1}, S_{k-1}) within MAX_FFI_TYPE_DEPTH=64, or a ~6 KiB retained capture/ffi_exports.json), rustc, LayoutCollector (record_tys dedup), ValidityReasonCollector (memo), and collect_referenced_layouts (foreign_entry.rs:711) all run in O(N) time, whereas ty_requires_structural_extra_validity performs 2^40 - 1 recursive calls because every branch returns false and .any(...) cannot short-circuit. Because validate_ffi_exports_manifest runs twice in verify.rs (parse_ffi_exports_manifest and build_foreign_entry_contracts) and once in inspect --verify-artifacts, this hangs both verify and inspect indefinitely.

G2-R1-02 [P2] (trusted/cargo-anneal/src/core/foreign_entry.rs:1197, Pass 2 §3 (trusted/cargo-anneal), static_verified): build_foreign_entry_contracts and parse_foreign_entry_contracts_strict admit abi.kind == "system" on non-Linux targets instead of enforcing the Linux-only extern "system" boundary.

  • Invariant: Phase 1 foreign-ABI export admission allows extern "system" strictly on Linux targets (docs/trust-model.md:731-735, docs/alpha.md:208, trusted/rustc-capture/src/extract.rs:8222-8226), and cargo-anneal independently enforces capture/receipt ABI admission invariants fail-closed.
  • Evidence: build_foreign_entry_contracts (trusted/cargo-anneal/src/core/foreign_entry.rs:1197-1202) checks only matches!(export.abi.kind.as_str(), "c" | "system") without verifying that manifest.target is a Linux target, and parse_foreign_entry_contracts_strict (trusted/cargo-anneal/src/core/foreign_entry.rs:1491-1493, called from trusted/cargo-anneal/src/core/inspect/schema.rs:2024 without passing target) likewise accepts "system" for any configuration.target. A manifest or standalone Receipt v3 targeting a non-Linux triple (such as x86_64-pc-windows-msvc or aarch64-apple-darwin) with abi = {"kind": "system", "unwind": false} therefore passes build_foreign_entry_contracts and cargo anneal inspect with zero invariant violations.

G2-R1-03 [P2] (trusted/cargo-anneal/src/core/foreign_entry.rs:1739, Pass 2 §3 (trusted/cargo-anneal), static_verified): parse_discharge_strict rewrites forbidden Phase-1 string discharges (by_c_typing, by_build_assert, by_ffi_check) to CallerClauseDischarge::Residual, corrupting parsed JSON output and hiding mutations in diff_receipts.

  • Invariant: Strict receipt parsing must preserve recognized discharge variants faithfully (consistent with by_wrapper_proof and by_linked_theorem at lines 1763 and 1774) so parsed JSON and diff_receipts accurately reflect claimed discharges.
  • Evidence: In trusted/cargo-anneal/src/core/foreign_entry.rs:1739-1745, matching "by_c_typing" | "by_build_assert" | "by_ffi_check" pushes a Phase-1 violation but returns Ok(CallerClauseDischarge::Residual) rather than CallerClauseDischarge::ByCTyping / ByBuildAssert / ByFfiCheck (defined on lines 67-69). Consequently, cargo anneal inspect --passive --format json serializes the tampered clause as "discharge": "residual", and diff_receipts (trusted/cargo-anneal/src/core/inspect/diff.rs:1819,1959,2019,2057) compares cl.discharge as Residual vs Residual, emitting zero changes and has_regressions == false (whereas tampering to by_wrapper_proof is preserved on line 1763 and reported as a Tier A regression).

Non-blocking advisories (P3, not Gate 2 findings)

These notes do not block merge and do not require another Gate 2 round.

  • G2-R1-A01 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:181): extract_captured_foreign_info_from_capture_json deserializes configuration into Option<serde_json::Value> via serde_json::from_slice, silently accepting duplicate keys inside configuration.
  • G2-R1-A02 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:1118): ffi_exports.json and retained capture.json are parsed with plain serde_json::from_slice rather than the duplicate-key-rejecting StrictJsonDom parser that target_base PR 602 introduced for untrusted verify.rs JSON inputs.
  • G2-R1-A03 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:1559): parse_foreign_entry_contracts_strict permits non-contiguous/duplicate parameter indices, duplicate parameter names across indices, empty warnings arrays, and unknown warning codes.
  • G2-R1-A04 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:1675): Bare inspect (without --verify-artifacts) does not require a warning for every extra-validity parameter clause, nor a safety_pre clause on unsafe exports; only --verify-artifacts re-derivation catches a receipt that drops them.
  • G2-R1-A05 [P3] (trusted/cargo-anneal/src/verify.rs:5293): Every non-stdlib receipt now carries configuration.allow_foreign_exports=true even for Rust-only crates, so inspect --diff across a tool upgrade reports a configuration change (Tier A under require_unchanged_specs); the commit body could state this receipt-wide effect explicitly.
  • G2-R1-A06 [P3] (global): AssuranceBadge::Ok doc comment says 'zero-warning' while classify_success_badge only checks spec_warnings.is_empty(), leaving [OK] active when foreign_entry_contracts emits [foreign-entry: extra_validity_parameter] warning rows (AssuranceBadge::Warn specifically formats anti-vacuity spec_warnings); warning and caveat rows still render unconditionally including under --quiet.

Executed Sandbox Probes

  • seat3 repo_hygiene_and_root_manifest: outcome=pass
  • seat3 taxonomy_lockstep_live_and_cli_json: outcome=pass
  • seat3 test_verify_zerocopy_unittest: outcome=pass
  • seat3 test_check_taxonomy_lockstep_unittest: outcome=pass
  • seat3 rustc_capture_to_foreign_entry_parity_and_core_purity: outcome=pass
  • seat3 rustc_2024_ffi_abi_layout_sanity: outcome=pass
  • seat3 docs_relative_links_and_ci_check_todo: outcome=pass
  • seat3 github_workflow_security_checklist: outcome=inapplicable
  • seat3 workspace_cargo_and_lean_builds: outcome=skipped_light_workload

@joshlf

joshlf commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

🤖 Exact-HEAD verification receipt for PR 2 (HEAD=a5e9f4210321365f93a36729bd45843c29bdeb25, TREE=5f45678b13a5d159812cd9449fab6217291e4a8a, BASE=3dd88838b1dc1dc8794ba9c1075e55003a7bc0b4), implementing cargo-anneal Receipt v3 ForeignEntryContract, inspect, and verify.rs wiring on top of #460 .

PR State: Strictly Draft (--draft, autoMergeRequest=null), updated with fixes for all 3 Gate-2 Round 1 P2 findings (--delta-from 2fb9d54b3c1b59caad2f11230947a5c2f2519fff) and ready for Gate-2 Round 2 (--tcb human review surface listed below).

Gate-2 Round 1 Fixes Incorporated (Delta over 2fb9d54b3c1b)

  • Memoized ty_requires_structural_extra_validity on acyclic record DAGs (foreign_entry.rs): Added cycle-safe memoization ((requires_extra, hit_cycle) + per-manifest memo: BTreeMap<String, bool>) mirroring ValidityReasonCollector, eliminating exponential O(2^N) traversal on diamond record DAGs. Added a 40-level diamond DAG unit test covering both baseline-initialized validation and fail-closed rejection when a bool leaf is downgraded.
  • Enforced Linux-only extern "system" boundary (foreign_entry.rs, schema.rs): Added is_linux_target_triple (<arch>-<vendor>-linux[-<env>], excluding Android) and enforced it fail-closed across validate_ffi_exports_manifest, build_foreign_entry_contracts, and parse_foreign_entry_contracts_strict (wired from configuration.target in schema.rs), with regression tests for non-Linux targets (x86_64-pc-windows-msvc, aarch64-apple-darwin, Android).
  • Preserved forbidden Phase-1 string discharges in parse_discharge_strict (foreign_entry.rs, diff.rs): Returned CallerClauseDischarge::ByCTyping / ByBuildAssert / ByFfiCheck faithfully while still recording Phase-1 invariant violations, ensuring passive JSON output and diff_receipts accurately detect tampered discharge claims as Tier A regressions. Added unit tests in foreign_entry.rs and diff.rs.

Human review surface (--tcb)

  • ci/test_check_taxonomy_lockstep.py
  • ci/test_verify_zerocopy.py
  • ci/verify_zerocopy.py
  • docs/trust-model.md
  • trusted/cargo-anneal/src/core/foreign_entry.rs
  • trusted/cargo-anneal/src/core/inspect/diff.rs
  • trusted/cargo-anneal/src/core/inspect/render.rs
  • trusted/cargo-anneal/src/core/inspect/schema.rs
  • trusted/cargo-anneal/src/core/mod.rs
  • trusted/cargo-anneal/src/inspect.rs
  • trusted/cargo-anneal/src/output.rs
  • trusted/cargo-anneal/src/verify.rs

Verification ([real measurement])

  • Exact HEAD=a5e9f4210321365f93a36729bd45843c29bdeb25:
    • cargo test --locked --offline -p cargo-anneal --lib -- foreign_entry inspect:: — 65 passed, 0 failed (1.79s; 382 unrelated tests filtered out)
    • cargo test --locked --offline -p cargo-anneal-tests --no-default-features --test cli --test inspect — 129/129 cli passed (12.02s), 46/46 inspect passed (16.79s)
    • cargo clippy --locked --offline --no-deps -p cargo-anneal --no-default-features --lib --bins -- -A clippy::type_complexity -D warnings — pass (10.84s)
    • cargo clippy --locked --offline --no-deps -p cargo-anneal-tests --no-default-features --test cli --test inspect -- -A clippy::type_complexity -D warnings — pass (5.69s)
    • RUSTFLAGS="-D warnings" cargo check --locked --offline -p cargo-anneal --no-default-features --lib --target wasm32-unknown-unknown — pass (13.63s)
    • python3 -B ci/check_pr_hygiene.py --base 3dd88838b1dc1dc8794ba9c1075e55003a7bc0b4 --head HEAD --receipt-file ... — 0 findings
  • Identical non-test production code (58537a77dddf; only #[cfg(test)] in foreign_entry.rs changed in a5e9f4210321):
    • cargo test --locked --offline -p cargo-anneal-tests --test suite -- ffi_export_entry (with anneal-rustc-capture built on pinned nightly-2026-05-31 and Lean 4.36.0) — 3 passed, 0 failed (173.78s; 79 unrelated tests filtered out)
  • Identical Python/CI/docs tree (2fb9d54b3c1b; zero Python/docs/taxonomy edits in delta):
    • PYTHONPATH=ci python3 -B -m unittest ci/test_verify_zerocopy.py ci/test_perf_tracking.py — 64 tests OK
    • python3 -B -m unittest ci/test_check_taxonomy_lockstep.py — 4 tests OK
    • ./ci/check_todo.sh, check_contract_lockstep.py, check_taxonomy_lockstep.py, run_fast_checks.py (3/3) — all pass
  • Not yet exercised on a5e9f4210321: full GitHub Actions ci-core matrix (runs upon push).

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf
joshlf force-pushed the joshlf/ffi-export-entry-spine-p2 branch from 2fb9d54 to a5e9f42 Compare December 5, 2026 01:38

@joshlf joshlf left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Authored by an AI agent acting on joshlf's behalf.

Gate 2 Independent Cross-Family Review — FINDINGS (tier2a_core_tcb, Round 2)

  • Identity: multi:5f07ae36854a910fac2010e39768d5d14131eddb:a5e9f4210321365f93a36729bd45843c29bdeb25 (base=5f07ae36854a, head=a5e9f4210321, tree=5f45678b13a5)
  • Separation: author_family=agent vs. reviewer_family=multi
  • Coverage: 23 inspected, 0 inapplicable, 0 blocked (of 23 changed file(s))
  • Review mode: delta_escalated relative to the prior Gate 2 review at head 2fb9d54b3c1b59caad2f11230947a5c2f2519fff (escalated to the full panel: Q1 delta guard forces the full panel)
Seat Family Role Status Verdict Findings Latency
seat1 claude-frontier-thinking tcb_and_api_critic completed clean 0 2359s
seat2 gemini-frontier-thinking tcb_and_spec_critic completed findings 1 1175s
seat3 gemini-executable-falsifier sandboxed_probe_runner completed findings 3 907s

Deduplicated Findings

ID Sev Consensus Verification Location Summary
G2-R2-01 P2 2 (seat2, seat3) static_verified trusted/cargo-anneal/src/core/foreign_entry.rs:181 extract_captured_foreign_info_from_capture_json deserializes configuration into serde_json::Value, silently accepting duplicate allow_foreign_exports keys inside retained capture.json.
G2-R2-02 P2 2 (seat2, seat3) probe_confirmed trusted/cargo-anneal/src/core/inspect/diff.rs:1971 baseline_altered in diff_foreign_entry_contracts does not inspect discharge/statement tampering on a parameter that simultaneously retires from ExtraValidity to BaselineInitialized.
G2-R2-03 P2 2 (seat2, seat3) static_verified trusted/cargo-anneal/src/core/inspect/render.rs:1199 render_markdown omits ffi_exports_manifest_sha256 and foreign_entry_contracts disclosures that render_human and render_ledger display.
G2-R2-04 P2 1 (seat2) static_verified trusted/cargo-anneal/src/inspect.rs:1043 verify_retained_artifacts probes capture/ffi_exports.json with SafeFs::probe_symlink_metadata (bare lstat), following intermediate symlinks on dir/capture outside --artifacts-dir.

G2-R2-01 [P2] (trusted/cargo-anneal/src/core/foreign_entry.rs:181, Pass 2 §3 (trusted/cargo-anneal), static_verified): extract_captured_foreign_info_from_capture_json deserializes configuration into serde_json::Value, silently accepting duplicate allow_foreign_exports keys inside retained capture.json.

  • Invariant: Strict JSON parsing defense-in-depth on untrusted retained artifacts.
  • Evidence: While trusted/cargo-anneal/src/inspect.rs parses sibling retained manifests (result.json lines 829-830, capture/capture_shards.json line 1072, spec-closure line 1364, request.json line 1458) through StrictJsonDom::parse_with_max_bytes, inspect.rs:933 calls extract_captured_foreign_info_from_capture_json (trusted/cargo-anneal/src/core/foreign_entry.rs:129-215) which uses serde_json::from_slice::<CaptureJsonRoot> with configuration: Option<Value> and no #[serde(deny_unknown_fields)], silently applying last-key-wins to duplicate keys inside configuration (including allow_foreign_exports) and omitting depth-64 bounds; parse_ffi_exports_manifest (trusted/cargo-anneal/src/core/foreign_entry.rs:1168, called from inspect.rs:987 and verify.rs:5592) similarly calls serde_json::from_slice directly without StrictJsonDom::parse.

G2-R2-02 [P2] (trusted/cargo-anneal/src/core/inspect/diff.rs:1971, Pass 2 §3 (trusted/cargo-anneal), probe_confirmed): baseline_altered in diff_foreign_entry_contracts does not inspect discharge/statement tampering on a parameter that simultaneously retires from ExtraValidity to BaselineInitialized.

  • Invariant: Defense-in-depth regression detection in diff_receipts independent of invariant_violations.
  • Evidence: In trusted/cargo-anneal/src/core/inspect/diff.rs:1928-1991, collect_entry_validity places entry_validity.param.<idx>.<name> clauses into b_ev_extra (and not b_ev_base) whenever warnings contains extra_validity_parameter for <name>, and into h_ev_base once the warning is retired in head. Line 1971-1972 computes let baseline_altered = h_ev_base.iter().any(|(k, v)| b_ev_base.get(k).is_some_and(|bv| bv != v));, which returns false for any key missing from b_ev_base. Confirmed in an isolated bwrap rustc probe of lines 1899-1991: under an unchanged rust_identity and a fresh symbol (so step 1 exports is TierB), retiring warnings while setting entry_validity.param.0.x.statement to a vacuous string (valid receipt with 0 invariant_violations under discharge: "residual") or setting discharge: "by_c_typing" yields ("TierB", false) and has_regressions == false.

G2-R2-03 [P2] (trusted/cargo-anneal/src/core/inspect/render.rs:1199, Pass 2 §3 (trusted/cargo-anneal), static_verified): render_markdown omits ffi_exports_manifest_sha256 and foreign_entry_contracts disclosures that render_human and render_ledger display.

  • Invariant: Cross-format disclosure parity in cargo anneal inspect.
  • Evidence: PR adds ffi_exports digest, Foreign-Entry Contracts baseline caveat, and Foreign-Entry Warnings to render_human (trusted/cargo-anneal/src/core/inspect/render.rs:821-823,867-891) and render_ledger (1118-1124,1177-1192), plus unit test renders_ffi_exports_digest_and_warnings_in_text_and_ledger (line 2003), while render_markdown (lines 1251-1420) and assurance_qualification_tags (lines 440-474) emit neither table rows nor warning callouts for ffi_exports_manifest_sha256 or foreign_entry_contracts (including unsafe safety_pre clauses and extra_validity_parameter warnings).

G2-R2-04 [P2] (trusted/cargo-anneal/src/inspect.rs:1043, Pass 2 §3 (trusted/cargo-anneal), static_verified): verify_retained_artifacts probes capture/ffi_exports.json with SafeFs::probe_symlink_metadata (bare lstat), following intermediate symlinks on dir/capture outside --artifacts-dir.

  • Invariant: Pass 2 §3 (trusted/cargo-anneal) retained-artifact containment: every multi-component path access under an untrusted --artifacts-dir must traverse every intermediate directory with O_DIRECTORY | O_NOFOLLOW (matching read_artifact_under_dir at inspect.rs:652-740) to prevent symlink escape and TOCTOU swaps.
  • Evidence: At trusted/cargo-anneal/src/inspect.rs:1042-1054, when s.ffi_exports_manifest_sha256 is None, verify_retained_artifacts constructs let ffi_path = dir.join("capture/ffi_exports.json") and calls SafeFs::probe_symlink_metadata(&ffi_path, "inspect"). SafeFs::probe_symlink_metadata (trusted/cargo-anneal/src/sys_util.rs:140-151) calls bare fs::symlink_metadata (lstat), which only avoids following a symlink on the final component (ffi_exports.json) and unconditionally follows a symlink on the intermediate capture component. Trigger 1 (static symlink escape): if an untrusted artifacts directory has symlink dir/capture -> /arbitrary/host/dir, read_artifact_under_dir(dir, "capture/capture.json", ...) at inspect.rs:922 fails via O_NOFOLLOW and pushes to failures, but execution continues to line 1043 and probes /arbitrary/host/dir/ffi_exports.json, leaking host file existence or permission errors (EACCES) into check.failures. Trigger 2 (TOCTOU): swapping dir/capture to a symlink pointing to an empty directory between line 922 and line 1043 causes probe_symlink_metadata to return Ok(None) and miss an unexpected capture/ffi_exports.json. Replace with a probe_artifact_under_dir helper using openat(..., O_DIRECTORY | O_NOFOLLOW) + fstatat(..., AT_SYMLINK_NOFOLLOW) on Unix (and validate_artifact_dir_chain prefix validation on non-Unix).

Non-blocking advisories (P3, not Gate 2 findings)

These notes do not block merge and do not require another Gate 2 round.

  • G2-R2-A01 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:873): validate_ffi_exports_manifest omits export-level ABI, symbol, uniqueness, and parameter checks that only run later in build_foreign_entry_contracts.
  • G2-R2-A02 [P3] (docs/trust-model.md:724): No Human review surface block could be confirmed: the PR body has none and the PR comments could not be read.
  • G2-R2-A03 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:823): The record-layout walks recurse once per named record with no depth cap, so a crafted long chain could overflow the stack during inspect --verify-artifacts.
  • G2-R2-A04 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:1745): parse_foreign_entry_contracts_strict accepts arbitrary non-blank warnings[*].code values and non-contiguous/duplicate-name entry_validity.param.. clauses despite diff.rs filtering strictly on extra_validity_parameter.
  • G2-R2-A05 [P3] (trusted/cargo-anneal/src/core/inspect/diff.rs:1847): else if b_safety_evidence != h_safety_evidence skips reporting a safety_pre evidence-hash change when another export retires safety_pre in the same diff.
  • G2-R2-A06 [P3] (trusted/cargo-anneal/src/core/inspect/render.rs:867): Human inspect --quiet hides foreign-entry contracts and extra-validity warnings, although the commit message calls the warnings non-suppressible.
  • G2-R2-A07 [P3] (trusted/cargo-anneal/src/core/inspect/schema.rs:2036): No test covers the rule that ffi_exports_manifest_sha256 and foreign_entry_contracts must appear together, or the schema-side stdlib_crate vs allow_foreign_exports exclusion.
  • G2-R2-A08 [P3] (trusted/cargo-anneal/src/output.rs:1016): The success badge only checks spec_warnings, so the card can show an OK badge next to a foreign-entry warning row.
  • G2-R2-A09 [P3] (trusted/cargo-anneal/src/verify.rs:6829): Rebase needed onto target_base near specification_manifest_sha256, and expanded check_taxonomy_lockstep staging makes test_all_fail_closed_taxonomy_and_ref_branches exceed 30s single-probe budgets.

Executed Sandbox Probes

  • seat3 Mandatory Workflow Permissions / Auth / Secret-Containment Checklist (8 items): outcome=N/A — zero .github/workflows/*.yml files were added or modified in the 23-file PR diff, and no workflow triggers, permissions, secrets, checkouts, shell interpolations, caches, or guards were altered.
  • seat3 Pass 1 deterministic static hygiene walk (os.walkover read-only candidate) + diffTODO/bidi/80-col doc check inside bwrap``: outcome=passed (exit 0): 0 symlinks, 0 hardlinks, 0 gitlinks, 0 checked-in build caches, 0 case/NFC collisions, 0 bidi/control chars, 0 TODO/FIXME/XXX in diff or commit metadata, valid 2026 Fuchsia headers on all 3 added .rs` files, all prose lines in modified regions of `docs/alpha.md` (lines 742-763) and `docs/trust-model.md` (lines 724-763) <= 80 chars.`
  • seat3 sha256sum --check --strict trusted/root-manifest.sha256` inside `bwrap: outcome=passed (exit 0): Cargo.toml, Cargo.lock, flake.nix, flake.lock all OK.
  • seat3 python3 -I -B -m unittest discover -s ci -p 'test_verify_zerocopy.py' -v` inside `bwrap: outcome=passed (exit 0): 32 tests ran in 4.625s, all OK (including foreign_opt_in_ok and negative foreign-export receipt tests).
  • seat3 python3 -I -B ci/check_taxonomy_lockstep.py --json` + 3 standalone `TaxonomyLockstepTests` + bounded framework/symbol/symlink mutation checks inside `bwrap: outcome=passed (exit 0): CLI JSON ok: true (enums_found: 18, total_constructs: 101, source_refs_checked: 215in 3.27s); 3 non-loop unit tests OK in 25.749s;test_all_fail_closed_taxonomy_and_ref_branches timed out at 30s (exit 124) due to 31 sequential ~3.3s lockstep invocations.
  • seat3 ci/check_skills_and_docs.py`, `ci/check_fast_docs_path_sync.py`, `ci/check_contract_lockstep.py`, `ci/check_fast_manifest_hygiene.py` inside `bwrap: outcome=passed (all exit 0); ci/check_todo.sh exited 127 (rgabsent in stripped sandbox/usr/bin, covered by Python diff/metadata check).
  • seat3 Cross-file contract parity (trusted/rustc-capture/src/ffi_exports.rsvstrusted/cargo-anneal/src/core/foreign_entry.rs) + is_linux_target_triplevsrustc --print target-list (--print target-spec-json) across all 322 pinned compiler targets inside bwrap``: outcome=passed (exit 0): 322/322 targets matched spec.os == "linux"` (0 mismatches); `FfiPassMode`, `FfiType`, `FfiReprFlags`, `FfiFieldLayout`, `FfiEnumVariant`, `FfiEnumTagEncoding`, `FfiEnumLayout`, `CanonicalSig`, and `ValidityReasonCollector` matched field-for-field.`
  • seat3 Standalone rustc --edition 2024executable falsification probe ofdiff.rs collect_entry_validity (lines 1899-1991) on b_ev_extra -> h_ev_baseinsidebwrap``: outcome=defect_confirmed (Finding 1, exit 0): both gutted entry_validity.param.0.x.statement` (valid `residual` receipt) and `ByCTyping` discharge produced `("TierB", false)` (`baseline_altered == false`) instead of `TierA`.`
  • seat3 target_base` (`5f07ae36`) overlap & hex-case compatibility check across all 7 shared files inside `bwrap: outcome=passed (exit 0): 6/7 files and all 38/39 diff hunks match target_basecontext verbatim with lowercase SHA-256 fixtures; 1 hunk inverify.rs:6829sits 2 lines below#602's specification_manifest_sha256 change.

Comment thread trusted/cargo-anneal/src/inspect.rs Resolved
@joshlf

joshlf commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

🤖 Exact-HEAD verification receipt for PR 2 (HEAD=3d85a25b097a751c56f44d97f6236eb1e183e26c, TREE=42f10b234362f03de9396c70e4c02a4c5990cf72, BASE=3dd88838b1dc1dc8794ba9c1075e55003a7bc0b4), implementing cargo-anneal Receipt v3 ForeignEntryContract, inspect, and verify.rs wiring on top of #460 .

PR State: Strictly Draft (--draft, autoMergeRequest=null), updated with fixes for all 4 Gate-2 Round 2 P2 findings (--delta-from a5e9f4210321365f93a36729bd45843c29bdeb25) and ready for Gate-2 Round 3 (--tcb human review surface listed below).

Gate-2 Round 2 Fixes Incorporated (Delta over a5e9f4210321)

  • Strict DOM parsing + depth cap (foreign_entry.rs): Routed both extract_captured_foreign_info_from_capture_json and parse_ffi_exports_manifest through StrictJsonDom::parse_with_max_bytes (128 MiB ceiling, MAX_JSON_DEPTH = 64, duplicate-key rejection at every nesting level including configuration.allow_foreign_exports), and added MAX_LAYOUT_WALK_DEPTH = 64 to collect_referenced_layouts and ty_requires_structural_extra_validity. Added duplicate-key rejection unit tests for both parsers.
  • Hardened ExtraValidity -> BaselineInitialized diff check (diff.rs, foreign_entry.rs): Extracted shared canonical_baseline_param_statement and updated baseline_altered in diff_foreign_entry_contracts to require exact canonical Residual payload when a parameter transitions from ExtraValidity to BaselineInitialized, catching statement tampering or discharge mutation (by_c_typing) as Tier A even under a fresh link symbol. Also ensured safety_pre evidence_hash regressions under --require-unchanged-specs are not masked when another export retires safety_pre. Added regression unit tests in diff.rs.
  • Markdown, qualification tags, and --quiet rendering parity (render.rs): Added FFI Exports Digest and Foreign-Entry Contracts table rows, ### Foreign-Entry Contracts section with the MaybeUninit<T> baseline non-omission caveat and safety_pre annotations, and > [!WARNING] foreign-entry warning callouts to render_markdown; added foreign_entry=residual_obligations / foreign_entry=extra_validity_warnings / foreign_entry=safety_pre tags to assurance_qualification_tags; kept foreign-entry contracts and warnings non-suppressible under --quiet in render_human. Extended renders_ffi_exports_digest_and_warnings_in_text_and_ledger to cover Markdown, qualification tags, safety_pre, and --quiet.
  • Symlink-safe artifact probing (inspect.rs): Replaced bare SafeFs::probe_symlink_metadata on dir/capture/ffi_exports.json with probe_artifact_under_dir using O_DIRECTORY | O_NOFOLLOW openat + fstatat(..., AT_SYMLINK_NOFOLLOW) on Unix (and component-by-component symlink-rejecting prefix walk on non-Unix). Added probe_artifact_under_dir_rejects_intermediate_symlink_escape unit test.

Human review surface (--tcb)

  • ci/test_check_taxonomy_lockstep.py
  • ci/test_verify_zerocopy.py
  • ci/verify_zerocopy.py
  • docs/trust-model.md
  • trusted/cargo-anneal/src/core/foreign_entry.rs
  • trusted/cargo-anneal/src/core/inspect/diff.rs
  • trusted/cargo-anneal/src/core/inspect/render.rs
  • trusted/cargo-anneal/src/core/inspect/schema.rs
  • trusted/cargo-anneal/src/core/mod.rs
  • trusted/cargo-anneal/src/inspect.rs
  • trusted/cargo-anneal/src/output.rs
  • trusted/cargo-anneal/src/verify.rs

Verification ([real measurement] on exact HEAD=3d85a25b097a751c56f44d97f6236eb1e183e26c)

  • cargo test --locked --offline -p cargo-anneal --lib -- foreign_entry inspect:: — 66 passed, 0 failed (1.77s; includes probe_artifact_under_dir_rejects_intermediate_symlink_escape, 382 unrelated tests filtered out)
  • cargo test --locked --offline -p cargo-anneal-tests --no-default-features --test cli --test inspect — 129/129 cli passed (12.02s), 46/46 inspect passed (16.53s)
  • cargo test --locked --offline -p cargo-anneal-tests --test suite -- ffi_export_entry (with anneal-rustc-capture built on pinned nightly-2026-05-31 and Lean 4.36.0) — 3 passed, 0 failed (172.42s; 79 unrelated tests filtered out)
  • cargo clippy --locked --offline --no-deps -p cargo-anneal --no-default-features --lib --bins -- -A clippy::type_complexity -D warnings — pass (9.91s)
  • cargo clippy --locked --offline --no-deps -p cargo-anneal-tests --no-default-features --test cli --test inspect -- -A clippy::type_complexity -D warnings — pass (5.10s)
  • RUSTFLAGS="-D warnings" cargo check --locked --offline -p cargo-anneal --no-default-features --lib --target wasm32-unknown-unknown — pass (13.59s)
  • python3 -B ci/check_pr_hygiene.py --base 3dd88838b1dc1dc8794ba9c1075e55003a7bc0b4 --head HEAD --receipt-file ... — 0 findings
  • Identical Python/CI/docs tree (2fb9d54b3c1b; zero Python/docs/taxonomy edits in delta; full GitHub Actions ci-core passed 38/38 on a5e9f4210321): 64/64 verify_zerocopy/perf_tracking, 4/4 taxonomy_lockstep, check_todo, check_contract_lockstep, check_taxonomy_lockstep, run_fast_checks (3/3).
  • Not yet exercised on 3d85a25b097a: full GitHub Actions ci-core matrix (runs upon push).

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf
joshlf force-pushed the joshlf/ffi-export-entry-spine-p2 branch from a5e9f42 to 3d85a25 Compare December 5, 2026 02:57
@joshlf

joshlf commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

🤖 Exact-HEAD verification receipt for PR 2 (HEAD=60619228942e1da10f73b88d29b1120e381032b8, TREE=e64900ee9f845e98464743b80a47322fed4338bd, BASE=3dd88838b1dc1dc8794ba9c1075e55003a7bc0b4), implementing cargo-anneal Receipt v3 ForeignEntryContract, inspect, and verify.rs wiring on top of #460 .

PR State: Strictly Draft (--draft, autoMergeRequest=null), updated with fixes for all 4 Gate-2 Round 2 P2 findings plus the clippy::type_complexity struct refactor (EntryValiditySnapshot in diff.rs) on --delta-from a5e9f4210321365f93a36729bd45843c29bdeb25 (--tcb human review surface listed below).

Gate-2 Round 2 + Clippy Fixes Incorporated (Delta over a5e9f4210321)

  • Strict DOM parsing + depth cap (foreign_entry.rs): Routed extract_captured_foreign_info_from_capture_json and parse_ffi_exports_manifest through StrictJsonDom::parse_with_max_bytes (128 MiB, MAX_JSON_DEPTH = 64, duplicate-key rejection including configuration.allow_foreign_exports), added MAX_LAYOUT_WALK_DEPTH = 64, and added duplicate-key unit tests.
  • Hardened ExtraValidity -> BaselineInitialized diff check (diff.rs, foreign_entry.rs): Shared canonical_baseline_param_statement, checked exact canonical Residual payload when retiring ExtraValidity -> BaselineInitialized (catching statement or discharge tampering as Tier A even under a fresh link symbol), factored collect_entry_validity return type into EntryValiditySnapshot (clearing strict -D clippy::type_complexity), and ensured safety_pre evidence_hash regressions under --require-unchanged-specs are not masked by concurrent retirements.
  • Markdown, qualification tags, and --quiet parity (render.rs): Added FFI Exports Digest and Foreign-Entry Contracts rows, ### Foreign-Entry Contracts caveat/export bullets, and > [!WARNING] warning callouts to render_markdown; added foreign_entry=* tags to assurance_qualification_tags; kept foreign-entry contracts and warnings non-suppressible under --quiet in render_human.
  • Symlink-safe artifact probing (inspect.rs): Replaced bare SafeFs::probe_symlink_metadata on dir/capture/ffi_exports.json with probe_artifact_under_dir (O_DIRECTORY | O_NOFOLLOW openat + fstatat(AT_SYMLINK_NOFOLLOW) on Unix, prefix walk on non-Unix) + intermediate-symlink regression unit test.

Human review surface (--tcb)

  • ci/test_check_taxonomy_lockstep.py
  • ci/test_verify_zerocopy.py
  • ci/verify_zerocopy.py
  • docs/trust-model.md
  • trusted/cargo-anneal/src/core/foreign_entry.rs
  • trusted/cargo-anneal/src/core/inspect/diff.rs
  • trusted/cargo-anneal/src/core/inspect/render.rs
  • trusted/cargo-anneal/src/core/inspect/schema.rs
  • trusted/cargo-anneal/src/core/mod.rs
  • trusted/cargo-anneal/src/inspect.rs
  • trusted/cargo-anneal/src/output.rs
  • trusted/cargo-anneal/src/verify.rs

Verification ([real measurement])

  • Exact HEAD=60619228942e1da10f73b88d29b1120e381032b8:
    • cargo test --locked --offline -p cargo-anneal --lib -- foreign_entry inspect:: — 66 passed, 0 failed (1.76s; 382 unrelated tests filtered out)
    • cargo test --locked --offline -p cargo-anneal-tests --no-default-features --test cli --test inspect — 129/129 cli passed (12.17s), 46/46 inspect passed (17.06s)
    • RUSTFLAGS="-D warnings" cargo clippy --locked --offline --no-deps -p cargo-anneal --lib --bins -- -D warnings (strict, no -A clippy::type_complexity) — pass (15.22s)
    • cargo clippy --locked --offline --no-deps -p cargo-anneal --no-default-features --lib --bins -- -D warnings — pass (11.25s)
    • cargo clippy --locked --offline --no-deps -p cargo-anneal-tests --no-default-features --test cli --test inspect -- -A clippy::type_complexity -D warnings — pass (9.63s)
    • RUSTFLAGS="-D warnings" cargo check --locked --offline -p cargo-anneal --no-default-features --lib --target wasm32-unknown-unknown — pass (13.42s)
    • python3 -B ci/check_pr_hygiene.py --base 3dd88838b1dc1dc8794ba9c1075e55003a7bc0b4 --head HEAD --receipt-file ... — 0 findings
  • Identical runtime behavior (3d85a25b097a; only local return struct refactor in diff.rs changed):
    • cargo test --locked --offline -p cargo-anneal-tests --test suite -- ffi_export_entry (pinned nightly-2026-05-31, Lean 4.36.0) — 3 passed, 0 failed (172.42s)
  • Not yet exercised on 60619228942e: full GitHub Actions ci-core matrix (runs upon push).

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf
joshlf force-pushed the joshlf/ffi-export-entry-spine-p2 branch from 3d85a25 to 6061922 Compare December 5, 2026 03:18

@joshlf joshlf left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Authored by an AI agent acting on joshlf's behalf.

Gate 2 Independent Cross-Family Review — FINDINGS (tier2a_core_tcb, Round 3)

  • Identity: multi:53ae52f441a59d264cf2aba51cd19041fbacd44f:60619228942e1da10f73b88d29b1120e381032b8 (base=53ae52f441a5, head=60619228942e, tree=e64900ee9f84)
  • Separation: author_family=agent vs. reviewer_family=multi
  • Coverage: 23 inspected, 0 inapplicable, 0 blocked (of 23 changed file(s))
  • Review mode: delta_escalated relative to the prior Gate 2 review at head a5e9f4210321365f93a36729bd45843c29bdeb25 (escalated to the full panel: Q1 delta guard forces the full panel)
Seat Family Role Status Verdict Findings Latency
seat1 claude-frontier-thinking tcb_and_api_critic completed clean 0 515s
seat2 gemini-frontier-thinking tcb_and_spec_critic completed clean 0 1151s
seat3 gemini-executable-falsifier sandboxed_probe_runner completed findings 1 1242s

Deduplicated Findings

ID Sev Consensus Verification Location Summary
G2-R3-01 P2 1 (seat3) probe_confirmed trusted/cargo-anneal/src/core/foreign_entry.rs:200 StrictJsonDom::MAX_JSON_DEPTH (64) prematurely rejects valid capture.json and ffi_exports.json files within MAX_FFI_TYPE_DEPTH (64) and parse_capture_receipt's 128-level limit.

G2-R3-01 [P2] (trusted/cargo-anneal/src/core/foreign_entry.rs:200, Pass 2 §3 (trusted/cargo-anneal), probe_confirmed): StrictJsonDom::MAX_JSON_DEPTH (64) prematurely rejects valid capture.json and ffi_exports.json files within MAX_FFI_TYPE_DEPTH (64) and parse_capture_receipt's 128-level limit.

  • Invariant: cargo-anneal artifact parsers must accept every valid capture/ffi_exports JSON emitted within anneal-rustc-capture's structural depth limits, and inspect --verify-artifacts must not reject pure-Rust captures accepted by verify.
  • Evidence: StrictJsonDom::parse_with_max_bytes enforces MAX_JSON_DEPTH = 64 across all nested JSON objects/arrays (trusted/cargo-anneal/src/core/inspect/strict_json.rs:31,91-98,154-178). In ffi_exports.json (trusted/rustc-capture/src/ffi_exports.rs:58-226,1067,1151-1165), exports[0].params[0].ty starts at JSON depth 6 while MAX_FFI_TYPE_DEPTH = 64 allows 59 nested arrays (depth 65 > 64) or 30 nested 1-tuples (2 containers each, depth 66 > 64), both confirmed to compile cleanly with rustc --edition=2024 --crate-type=lib (exit 0, no #![recursion_limit]). Additionally, trusted/cargo-anneal/src/verify.rs:2385-2403 (parse_capture_receipt) uses serde_json::from_slice (default recursion limit 128), whereas trusted/cargo-anneal/src/inspect.rs:1061 now calls extract_captured_foreign_info_from_capture_json (trusted/cargo-anneal/src/core/foreign_entry.rs:196-203) with MAX_JSON_DEPTH = 64, rejecting valid zero-FFI capture/capture.json files (depth >= 65 at program.bodies[i].local_tys[j], trusted/rustc-capture/src/ir.rs:888-965) during inspect --verify-artifacts. Fix by raising the artifact JSON parser depth bound cleanly above 128 + outer envelope (or using a dedicated higher-depth strict parser constant for capture/FFI artifacts).

Non-blocking advisories (P3, not Gate 2 findings)

These notes do not block merge and do not require another Gate 2 round.

  • G2-R3-A01 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:1097): validate_ffi_exports_manifest defers several per-export structural checks (abi.unwind, abi.c_variadic, unsupported abi.kind, empty/duplicate symbol or rust_identity, contiguous param.index/unique param.name) until build_foreign_entry_contracts after Lean elaboration.
  • G2-R3-A02 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:1330): ffi_exports.json parameter types are cross-checked against capture.json bodies only by count, not by type.
  • G2-R3-A03 [P3] (trusted/cargo-anneal/src/inspect.rs:1093): verify_retained_artifacts reads capture/ffi_exports.json under receipt_artifact_cap (which honors --max-receipt-bytes) but parse_ffi_exports_manifest enforces a fixed 128 MiB cap (MAX_FOREIGN_ARTIFACT_JSON_BYTES) without forwarding max_receipt_bytes.
  • G2-R3-A04 [P3] (trusted/cargo-anneal/src/verify.rs:5293): The supplied PR metadata contains no Human review surface block; the Review Receipt was not provided for this review.
  • G2-R3-A05 [P3] (trusted/cargo-anneal/src/verify.rs:5376): verify.rs always passes --allow-foreign-exports on non-stdlib runs but still accepts a capture whose configuration omits allow_foreign_exports.
  • G2-R3-A06 [P3] (trusted/cargo-anneal/src/verify.rs:7042): --fast-check returns before build_foreign_entry_contracts runs, so the ffi_exports/capture cross-check is skipped in dev mode.

Executed Sandbox Probes

  • seat3 Static repo-wide hygiene scan (symlinks, submodules, build caches, case/NFC collisions, bidi/control Unicode, TODOs) inside bwrap --unshare-all: outcome=passed
  • seat3 Pinned root manifest checksum check (sha256sum --check --strict trusted/root-manifest.sha256) inside bwrap --unshare-all: outcome=passed
  • seat3 Taxonomy lockstep CLI check (ci/check_taxonomy_lockstep.py) inside bwrap --unshare-all: outcome=passed
  • seat3 Zerocopy receipt validator unit tests (ci/test_verify_zerocopy.py) inside bwrap --unshare-all: outcome=passed
  • seat3 Taxonomy lockstep unit and mutation test suite (ci/test_check_taxonomy_lockstep.py) inside bwrap --unshare-all: outcome=passed
  • seat3 Built-in rustc target triple parity probe vs foreign_entry.rs::is_linux_target_triple inside bwrap --unshare-all: outcome=passed
  • seat3 Adversarial deep-type rustc compilation and StrictJsonDom JSON container depth probe inside bwrap --unshare-all: outcome=failed_reproduced_defect
  • seat3 Fuchsia copyright headers, added TODO/FIXME markers in diff & commit 606192289, and Markdown relative links/anchors check inside bwrap --unshare-all: outcome=passed

@joshlf

joshlf commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

🤖 Exact-HEAD verification receipt for PR 2 (HEAD=1a7d0551d6b016448ad44a142d238aa28e5b8587, TREE=18c6fff167a7c85752943dbe81f3629f00f585cc, BASE=3dd88838b1dc1dc8794ba9c1075e55003a7bc0b4), implementing cargo-anneal Receipt v3 ForeignEntryContract, inspect, and verify.rs wiring on top of #460 .

PR State: Strictly Draft (--draft, autoMergeRequest=null), updated with the fix for Gate-2 Round 3's single P2 finding (G2-R3-01) on --delta-from 60619228942e1da10f73b88d29b1120e381032b8 (--tcb human review surface listed below).

Gate-2 Round 3 Fix Incorporated (Delta over 60619228942e)

  • Explicit heap-stack strict JSON parser with configurable depth (strict_json.rs, foreign_entry.rs, inspect.rs): Added StrictJsonDom::parse_with_limits(bytes, max_bytes, max_depth) backed by an explicit heap-allocated frame stack (parse_strict_iterative), preserving duplicate-key rejection at every nesting level, UTF-8 validation, RFC 8259 string/number validation, and trailing-token rejection while bypassing serde_json's 128-frame recursion limit. Set MAX_FOREIGN_ARTIFACT_JSON_DEPTH = 256 for capture.json and ffi_exports.json (cleanly above both parse_capture_receipt's 128-level limit + outer envelope and MAX_FFI_TYPE_DEPTH = 64 nested 1-tuples at depth 134), and added *_with_max_bytes wrappers so inspect.rs forwards (MAX_ARTIFACT_FILE_BYTES).max(max_receipt_bytes). Added regression tests covering 63 nested 1-tuples (depth 132), 63 nested arrays (depth 69), 120-level pure-Rust capture.json, depth-280 parsing, depth-256 rejection, and duplicate-key rejection above depth 128.

Human review surface (--tcb)

  • ci/test_check_taxonomy_lockstep.py
  • ci/test_verify_zerocopy.py
  • ci/verify_zerocopy.py
  • docs/trust-model.md
  • trusted/cargo-anneal/src/core/foreign_entry.rs
  • trusted/cargo-anneal/src/core/inspect/diff.rs
  • trusted/cargo-anneal/src/core/inspect/render.rs
  • trusted/cargo-anneal/src/core/inspect/schema.rs
  • trusted/cargo-anneal/src/core/inspect/strict_json.rs
  • trusted/cargo-anneal/src/core/mod.rs
  • trusted/cargo-anneal/src/inspect.rs
  • trusted/cargo-anneal/src/output.rs
  • trusted/cargo-anneal/src/verify.rs

Verification ([real measurement] on exact HEAD=1a7d0551d6b016448ad44a142d238aa28e5b8587)

  • cargo test --locked --offline -p cargo-anneal --lib -- foreign_entry inspect:: — 68 passed, 0 failed (1.77s; 382 unrelated tests filtered out)
  • cargo test --locked --offline -p cargo-anneal-tests --no-default-features --test cli --test inspect — 129/129 cli passed (12.13s), 46/46 inspect passed (16.58s)
  • cargo test --locked --offline -p cargo-anneal-tests --test suite -- ffi_export_entry (with anneal-rustc-capture built on pinned nightly-2026-05-31 and Lean 4.36.0) — 3 passed, 0 failed (178.98s; 79 unrelated tests filtered out)
  • RUSTFLAGS="-D warnings" cargo clippy --locked --offline --no-deps -p cargo-anneal --lib --bins -- -D warnings (strict, no -A clippy::type_complexity) — pass (15.31s)
  • cargo clippy --locked --offline --no-deps -p cargo-anneal --no-default-features --lib --bins -- -D warnings — pass (11.02s)
  • cargo clippy --locked --offline --no-deps -p cargo-anneal-tests --no-default-features --test cli --test inspect -- -A clippy::type_complexity -D warnings — pass (9.83s)
  • RUSTFLAGS="-D warnings" cargo check --locked --offline -p cargo-anneal --no-default-features --lib --target wasm32-unknown-unknown — pass (17.48s)
  • python3 -B ci/check_pr_hygiene.py --base 3dd88838b1dc1dc8794ba9c1075e55003a7bc0b4 --head HEAD --receipt-file ... — 0 findings
  • Not yet exercised on 1a7d0551d6b0: full GitHub Actions ci-core matrix (runs upon push; 38/38 execute shards passed on 60619228942e).

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf
joshlf force-pushed the joshlf/ffi-export-entry-spine-p2 branch from 6061922 to 1a7d055 Compare December 5, 2026 05:02

@joshlf joshlf left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Authored by an AI agent acting on joshlf's behalf.

Gate 2 Independent Cross-Family Review — CLEAN (tier2a_core_tcb, Round 4)

  • Identity: multi:2ce3cf9e185c561929ceb06817f7485904f1be61:1a7d0551d6b016448ad44a142d238aa28e5b8587 (base=2ce3cf9e185c, head=1a7d0551d6b0, tree=18c6fff167a7)
  • Separation: author_family=agent vs. reviewer_family=multi
  • Coverage: 24 inspected, 0 inapplicable, 0 blocked (of 24 changed file(s))
  • Review mode: delta_escalated relative to the prior Gate 2 review at head 60619228942e1da10f73b88d29b1120e381032b8 (escalated to the full panel: Q1 delta guard forces the full panel)
Seat Family Role Status Verdict Findings Latency
seat1 claude-frontier-thinking tcb_and_api_critic completed clean 0 533s
seat2 gemini-frontier-thinking tcb_and_spec_critic completed clean 0 1234s
seat3 gemini-executable-falsifier sandboxed_probe_runner completed clean 0 884s

No unresolved P0-P2 findings raised across completed seats.

Non-blocking advisories (P3, not Gate 2 findings)

These notes do not block merge and do not require another Gate 2 round.

  • G2-R4-A01 [P3] (docs/trust-model.md:724): The section is still titled 'Opt-in foreign-ABI export capture' although cargo anneal verify now passes the flag on every run without --stdlib-crate, so every new receipt carries configuration.allow_foreign_exports: true and a new capture digest.
  • G2-R4-A02 [P3] (tools/anneal-corpus-scan/canonical_taxonomy_v1.json:105): item_extern_c_export_non_unwinding cites Trusted/Framework/Instances.lean#bodyMatchesMirSignature as its Lean semantics ref, but that check runs only on the MirEnvelope path this PR explicitly refuses for foreign exports.
  • G2-R4-A03 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:658): is_valid_raw_bits_hex accepts uppercase hex digits and inspect.rs compares ffi_exports_manifest_sha256 case-insensitively.
  • G2-R4-A04 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:948): validate_ffi_exports_manifest defers several per-export ABI/identity/parameter checks to build_foreign_entry_contracts.
  • G2-R4-A05 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:1836): parse_foreign_entry_contracts_strict only requires warnings[].code to be non-empty (!code.trim().is_empty()), whereas build_foreign_entry_contracts only emits "extra_validity_parameter" and diff_foreign_entry_contracts filters w.code == "extra_validity_parameter" when canonicalizing entry_validity.baseline_byte_initialization. Defense-in-depth note only: any mismatched or unrecognized warning code still triggers TierA under foreign_entry_contracts.warnings in diff.rs and fails inspect --verify-artifacts contract recomputation.
  • G2-R4-A06 [P3] (trusted/cargo-anneal/src/verify.rs:5293): No Review Receipt / Human review surface block was in the staged artifacts, so its completeness (listing trusted/cargo-anneal, ci/, docs/trust-model.md and the default-on capture flag) could not be checked.

Executed Sandbox Probes

  • seat3 pass1_fs_unicode_hygiene: outcome=passed
  • seat3 sha256sum_root_manifest: outcome=passed
  • seat3 workflow_permissions_checklist: outcome=inapplicable
  • seat3 taxonomy_lockstep_check: outcome=passed
  • seat3 ci_test_verify_zerocopy: outcome=passed
  • seat3 ci_test_check_taxonomy_lockstep_targeted: outcome=passed
  • seat3 ci_test_check_taxonomy_lockstep_exhaustive: outcome=timeout
  • seat3 docs_links_and_nextest_config: outcome=passed
  • seat3 rustc_e2e_ffi_snippets: outcome=passed
  • seat3 rustc_standalone_logic_edge_cases: outcome=passed
  • seat3 heavy_cargo_and_lean_suites: outcome=not_run_under_workload_light

@joshlf
joshlf marked this pull request as ready for review December 5, 2026 16:17
@joshlf
joshlf requested a review from jswrenn as a code owner December 5, 2026 16:17

@joshlf joshlf left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ci-core approve 1a7d055

@joshlf

joshlf commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

Authored by an AI agent acting on joshlf's behalf. Posted /ci-core approve for 1a7d0551d6b016448ad44a142d238aa28e5b8587 under joshlf's Gate-5 authorization, after this head passed its independent review.

@joshlf
joshlf added this pull request to the merge queue Dec 5, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Dec 5, 2026
@joshlf
joshlf force-pushed the joshlf/ffi-export-entry-spine-p2 branch from 1a7d055 to c166577 Compare December 5, 2026 18:04
@joshlf

joshlf commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

🤖 Exact-HEAD verification receipt for PR 2 (HEAD=c1665774722ca38621d77d1a84b421eab01f35ce, TREE=7d6dcc83835fae8b75a30a41587d4ba9052edde1, BASE=edc64e88e487212d55401167323ed26e5a87d94e), rebased onto main after #618 .

Rebase & Post-#618 Fix (Delta over 1a7d0551d6b0)

  • Non-TCB E2E proof update (tests/cargo-anneal/tests/suite/ffi_export_entry_e2e.rs:525): Updated ValidEntryArgsV2 destructuring in copy_u32_wellFormed (let ⟨hCM, hArgs, hRefs, hSpans, _⟩ := hValid) to match the fifth conjunct (ownedTreeOkV2) added in [anneal] Name ADTs once, entry owned-heap tree, Vec-to-slice, movedDiscr #618 so hSpans has type spansPairwiseDisjoint ... = true as expected by Anneal.MirWp.initStateV2_ok_of.
  • Zero TCB delta: git range-diff 3dd88838b..1a7d0551d6b0 edc64e88e487..c1665774722c confirms all trusted/ patch hunks are byte-identical to 1a7d0551d6b0 (only the single non-TCB line in ffi_export_entry_e2e.rs changed).

Human review surface (--tcb)

  • ci/test_check_taxonomy_lockstep.py
  • ci/test_verify_zerocopy.py
  • ci/verify_zerocopy.py
  • docs/trust-model.md
  • trusted/cargo-anneal/src/core/foreign_entry.rs
  • trusted/cargo-anneal/src/core/inspect/diff.rs
  • trusted/cargo-anneal/src/core/inspect/render.rs
  • trusted/cargo-anneal/src/core/inspect/schema.rs
  • trusted/cargo-anneal/src/core/inspect/strict_json.rs
  • trusted/cargo-anneal/src/core/mod.rs
  • trusted/cargo-anneal/src/inspect.rs
  • trusted/cargo-anneal/src/output.rs
  • trusted/cargo-anneal/src/verify.rs

Verification ([real measurement] on exact HEAD=c1665774722ca38621d77d1a84b421eab01f35ce)

  • cargo test --locked --offline -p cargo-anneal-tests --test suite -- ffi_export_entry (with anneal-rustc-capture built on pinned nightly-2026-05-31 and anneal-audit) — 3 passed, 0 failed (227.64s; 79 unrelated tests filtered out)
  • cargo test --locked --offline -p cargo-anneal-tests --no-default-features --test cli --test inspect — 131/131 cli passed (13.16s), 46/46 inspect passed (18.29s)
  • cargo test --locked --offline -p cargo-anneal --lib -- foreign_entry inspect:: — 68 passed, 0 failed (1.74s; 385 unrelated tests filtered out)
  • cargo clippy --locked --offline --no-deps -p cargo-anneal --lib --bins -- -D warnings — pass
  • cargo clippy --locked --offline --no-deps -p cargo-anneal-tests --no-default-features --test cli --test inspect -- -A clippy::type_complexity -D warnings — pass
  • ./ci/check_todo.sh, python3 -B ci/check_taxonomy_lockstep.py, python3 -B -m unittest ci/test_check_taxonomy_lockstep.py ci/test_verify_zerocopy.py (36 tests), and python3 -B ci/check_pr_hygiene.py --base edc64e88e487212d55401167323ed26e5a87d94e --head HEAD --receipt-file ... — pass (0 findings)
  • Not yet exercised on c1665774722c: full GitHub Actions ci-core matrix (runs upon push).

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf
joshlf force-pushed the joshlf/ffi-export-entry-spine-p2 branch from c166577 to f457fac Compare December 5, 2026 18:16
@joshlf

joshlf commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

🤖 Exact-HEAD verification receipt for PR 2 (HEAD=f457facfd3adcd30874af9ea7d79c7981baa4d77, TREE=defc63cf09bfabdf29e0fb86e12a5589891b66d8, BASE=6c2abcfa4aa5625b82433fa53da32762feadc4c0), rebased onto main after #618 and #671 .

Rebase & Mechanical Updates (Delta over 1a7d0551d6b0)

  • Non-TCB E2E proof update (tests/cargo-anneal/tests/suite/ffi_export_entry_e2e.rs:525): Updated ValidEntryArgsV2 destructuring in copy_u32_wellFormed (let ⟨hCM, hArgs, hRefs, hSpans, _⟩ := hValid) to match the fifth conjunct (ownedTreeOkV2) added in [anneal] Name ADTs once, entry owned-heap tree, Vec-to-slice, movedDiscr #618 .
  • Mechanical taxonomy path update (tools/anneal-corpus-scan/canonical_taxonomy_v1.json): Updated the two item_extern_* rustc_capture_ref entries from trusted/rustc-capture/src/extract.rs to trusted/rustc-capture/src/extract/mod.rs following the submodule split in [rustc-capture] Split ir.rs, extract.rs, and capture.rs into submodules #671 .
  • Zero TCB delta: git range-diff against 1a7d0551d6b0 confirms all trusted/ patch hunks are byte-identical (only the two non-TCB updates above changed).

Human review surface (--tcb)

  • ci/test_check_taxonomy_lockstep.py
  • ci/test_verify_zerocopy.py
  • ci/verify_zerocopy.py
  • docs/trust-model.md
  • trusted/cargo-anneal/src/core/foreign_entry.rs
  • trusted/cargo-anneal/src/core/inspect/diff.rs
  • trusted/cargo-anneal/src/core/inspect/render.rs
  • trusted/cargo-anneal/src/core/inspect/schema.rs
  • trusted/cargo-anneal/src/core/inspect/strict_json.rs
  • trusted/cargo-anneal/src/core/mod.rs
  • trusted/cargo-anneal/src/inspect.rs
  • trusted/cargo-anneal/src/output.rs
  • trusted/cargo-anneal/src/verify.rs

Verification ([real measurement] on exact HEAD=f457facfd3adcd30874af9ea7d79c7981baa4d77)

  • cargo test --locked --offline -p cargo-anneal-tests --test suite -- ffi_export_entry (with anneal-rustc-capture built on pinned nightly-2026-05-31 and anneal-audit) — 3 passed, 0 failed (225.18s; 79 unrelated tests filtered out)
  • cargo test --locked --offline -p cargo-anneal-tests --no-default-features --test cli --test inspect — 131/131 cli passed (12.16s), 46/46 inspect passed (16.50s)
  • cargo test --locked --offline -p cargo-anneal --lib -- foreign_entry inspect:: — 68 passed, 0 failed (1.77s; 385 unrelated tests filtered out)
  • ./ci/check_todo.sh, python3 -B ci/check_taxonomy_lockstep.py (18 enums, 335 variants, 101 constructs, 238 source refs), python3 -B -m unittest ci/test_check_taxonomy_lockstep.py ci/test_verify_zerocopy.py (36 tests), and python3 -B ci/check_pr_hygiene.py --base 6c2abcfa4aa5625b82433fa53da32762feadc4c0 --head HEAD --receipt-file ... — pass (0 findings)
  • Not yet exercised on f457facfd3ad: full GitHub Actions ci-core matrix (runs upon push).

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf joshlf left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Authored by an AI agent acting on joshlf's behalf.

Gate 2 Independent Cross-Family Review — FINDINGS (tier2a_core_tcb, Round 5)

  • Identity: one:bc9a7ea96ee91f6b03bdc8c0bd50e481d6c58268:defc63cf09bfabdf29e0fb86e12a5589891b66d8:9f28b1646ec583db31bf781789f6fe0a7f6167ec64a8d020a7ce876de725b9b4 (base=6c2abcfa4aa5, head=f457facfd3ad, tree=defc63cf09bf)
  • Separation: author_family=agent vs. reviewer_family=multi
  • Coverage: 24 inspected, 0 inapplicable, 0 blocked (of 24 changed file(s))
  • Review mode: delta_escalated relative to the prior Gate 2 review at head 1a7d0551d6b016448ad44a142d238aa28e5b8587 (escalated to the full panel: Q1 delta guard forces the full panel)
Seat Family Role Status Verdict Findings Latency
seat1 claude-frontier-thinking tcb_and_api_critic completed clean 0 627s
seat2 gemini-frontier-thinking tcb_and_spec_critic completed clean 0 903s
seat3 gemini-executable-falsifier sandboxed_probe_runner completed findings 1 1016s

Deduplicated Findings

ID Sev Consensus Verification Location Summary
G2-R5-01 P2 1 (seat3) probe_confirmed trusted/cargo-anneal/src/core/foreign_entry.rs:923 Cyclic FfiRecordLayout DAGs bypass memoization in ty_requires_structural_extra_validity before signature_sha256 verification, causing O(2^N) CPU DoS.

G2-R5-01 [P2] (trusted/cargo-anneal/src/core/foreign_entry.rs:923, Pass 2 §3 (trusted/cargo-anneal), probe_confirmed): Cyclic FfiRecordLayout DAGs bypass memoization in ty_requires_structural_extra_validity before signature_sha256 verification, causing O(2^N) CPU DoS.

  • Invariant: Untrusted ffi_exports.json manifest validation must run in bounded polynomial time within the declared size, depth, and diamond-DAG limits and reject physically impossible by-value Rust record cycles fail-closed.
  • Evidence: collect_referenced_layouts (trusted/cargo-anneal/src/core/foreign_entry.rs:769-770) short-circuits on already-seen records and permits cycles, while validate_ffi_exports_manifest calls ty_requires_structural_extra_validity (line 1148) unconditionally on every export parameter before compute_export_signature_sha256 (line 1205). Whenever a record DAG contains a cycle edge back toward an ancestor without hitting an extra-validity leaf, hit_cycle propagates true up the DAG and line 923 (if requires || !hit_cycle) skips inserting into memo, forcing exponential re-traversal of every diamond node. Inside bwrap, rustc confirmed recursive by-value structs ([S; 0] and mutual tuples) fail compilation with error[E0072], and a compiled probe mirroring lines 769-927 completed an acyclic 41-record diamond in 82 visits (0.031 ms) vs 16,777,215 visits (2,787.821 ms) with one cycle back-edge at N=23.

Non-blocking advisories (P3, not Gate 2 findings)

These notes do not block merge and do not require another Gate 2 round.

  • G2-R5-A01 [P3] (docs/trust-model.md:724): The section heading still says 'Opt-in' although cargo anneal verify now enables --allow-foreign-exports by default, and the section does not describe the receipt foreign_entry_contracts envelope (residual-only discharge, required ambient clauses, --verify-artifacts re-derivation).
  • G2-R5-A02 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:1120): Move per-export ABI kind/unwind/c_variadic validation into validate_ffi_exports_manifest so parse_ffi_exports_manifest fails fast before Lean elaboration.
  • G2-R5-A03 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:1836): Restrict Phase 1 foreign-entry warning codes to extra_validity_parameter and reject explicit empty warnings: [] in parse_foreign_entry_contracts_strict.
  • G2-R5-A04 [P3] (trusted/cargo-anneal/src/core/inspect/diff.rs:1903): canonical_baseline_stmt re-implements the baseline clause text emitted by build_foreign_entry_contracts (foreign_entry.rs:1446) instead of sharing one helper.
  • G2-R5-A05 [P3] (trusted/cargo-anneal/src/output.rs:1025): Success verdict cards emit green [OK] even when foreign_entry_contracts carries D3 extra_validity_parameter warnings or safety_pre residual obligations, whereas inspect renders yellow [QUALIFIED].

Executed Sandbox Probes

  • seat3 repo_hygiene_and_diff_scan: outcome=passed
  • seat3 root_manifest_sha256: outcome=passed
  • seat3 taxonomy_lockstep_and_refs: outcome=passed
  • seat3 ci_test_verify_zerocopy: outcome=passed
  • seat3 ci_test_check_taxonomy_lockstep: outcome=passed
  • seat3 rustc_target_triples_vs_is_linux_target_triple: outcome=passed
  • seat3 cyclic_record_dag_dos_and_rustc_e0072: outcome=finding_confirmed
  • seat3 strict_json_iterative_edge_cases: outcome=passed
  • seat3 workflow_permissions_auth_secret_checklist: outcome=na

@joshlf

joshlf commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

🤖 Exact-HEAD verification receipt for PR 2 (HEAD=90377931875a2764cae1795c03d44514442e0d13, TREE=bcff50256826c6a764fbeb7b8dcf45e9c92af7ea, BASE=6c2abcfa4aa5625b82433fa53da32762feadc4c0).

Gate-2 Round 5 Fix (1-File TCB Delta over f457facfd3ad / Gate-5 1a7d0551d6b0)

  • Minimal TCB delta (trusted/cargo-anneal/src/core/foreign_entry.rs only): Relative to Gate-5 1a7d0551d6b0, the sole trusted/ change is this single-file fix in trusted/cargo-anneal/src/core/foreign_entry.rs (alongside the two prior non-TCB rebase updates in tests/cargo-anneal/tests/suite/ffi_export_entry_e2e.rs and tools/anneal-corpus-scan/canonical_taxonomy_v1.json from f457facfd3ad).
  • Fail-closed cyclic by-value layout rejection (G2-R5-01):
    • Added iterative 3-color DFS validate_acyclic_by_value_layouts in validate_ffi_exports_manifest (running upfront in O(V + E) time before the export loop, ty_requires_structural_extra_validity, and signature_sha256 verification) to reject cyclic by-value Record/Enum graphs (including through Array, Slice, Tuple, Option, and unions — all rejected by rustc with E0072), while permitting valid indirection-mediated recursive types (Ptr, Ref, NonNull, Box, Vec, FnPtr, e.g. struct Node { next: *mut Node }).
    • Hardened ty_requires_structural_extra_validity to return Result<bool, String>, fail closed immediately on any active-record cycle back-edge (cleaning up visiting_records on error), and memoize every completed Record unconditionally so diamond DAG traversal remains strictly O(V + E) linear time.
    • Added validate_ffi_exports_manifest_rejects_by_value_layout_cycles_in_linear_time covering simple self-cycles, mutual record cycles, union cycles, Option<Self> cycles, mutual Record <-> Enum cycles, N=32 cyclic diamond DAGs (root, interior, and leaf back-edges, both via validate_ffi_exports_manifest and directly via ty_requires_structural_extra_validity), and valid indirection-mediated self-referential structs (struct Node { next: *mut Node, opt_next: Option<NonNull<Node>>, val: u32 }), alongside existing 40-level acyclic diamond tests.

Human review surface (--tcb)

  • ci/test_check_taxonomy_lockstep.py
  • ci/test_verify_zerocopy.py
  • ci/verify_zerocopy.py
  • docs/trust-model.md
  • trusted/cargo-anneal/src/core/foreign_entry.rs
  • trusted/cargo-anneal/src/core/inspect/diff.rs
  • trusted/cargo-anneal/src/core/inspect/render.rs
  • trusted/cargo-anneal/src/core/inspect/schema.rs
  • trusted/cargo-anneal/src/core/inspect/strict_json.rs
  • trusted/cargo-anneal/src/core/mod.rs
  • trusted/cargo-anneal/src/inspect.rs
  • trusted/cargo-anneal/src/output.rs
  • trusted/cargo-anneal/src/verify.rs

Verification ([real measurement] on exact HEAD=90377931875a2764cae1795c03d44514442e0d13)

  • cargo test --locked --offline -p cargo-anneal --lib -- foreign_entry inspect:: — 69 passed, 0 failed (1.83s; 385 unrelated tests filtered out)
  • cargo test --locked --offline -p cargo-anneal --lib — 454 passed, 0 failed (344.23s)
  • cargo test --locked --offline -p cargo-anneal-tests --no-default-features --test cli --test inspect — 131/131 cli passed (12.26s), 46/46 inspect passed (16.54s)
  • cargo test --locked --offline -p cargo-anneal-tests --test suite -- ffi_export_entry (with anneal-rustc-capture built on pinned nightly-2026-05-31 and anneal-audit) — 3 passed, 0 failed (260.66s; 79 unrelated tests filtered out)
  • RUSTFLAGS="-D warnings" cargo clippy --locked --offline --no-deps -p cargo-anneal --lib --bins -- -D warnings — pass (15.84s)
  • cargo clippy --locked --offline --no-deps -p cargo-anneal --no-default-features --lib --bins -- -D warnings — pass (13.12s)
  • cargo clippy --locked --offline --no-deps -p cargo-anneal-tests --no-default-features --test cli --test inspect -- -A clippy::type_complexity -D warnings — pass (9.42s)
  • ./ci/check_todo.sh, python3 -B ci/check_contract_lockstep.py (1 contract(s) verified), python3 -B ci/check_taxonomy_lockstep.py (18 enums, 335 variants, 101 constructs, 238 source refs), python3 -B -m unittest ci/test_check_taxonomy_lockstep.py ci/test_verify_zerocopy.py (36 tests), and python3 -B ci/check_pr_hygiene.py --base 6c2abcfa4aa5625b82433fa53da32762feadc4c0 --head HEAD --receipt-file ... — pass (0 findings)
  • Not yet exercised on 90377931875a: wasm32-unknown-unknown target check (target sysroot absent on remote runner) and full GitHub Actions ci-core matrix (runs upon push).

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf
joshlf force-pushed the joshlf/ffi-export-entry-spine-p2 branch from f457fac to 9037793 Compare December 5, 2026 18:59
@joshlf

joshlf commented Dec 5, 2026 •

Copy link
Copy Markdown
Member Author

Anneal Merge Coordination Status: CB_PAUSED (CB_AWAITING_TRIAGE)

  • Next action: Automatic Gate 2 re-review is paused pending maintainer round-budget triage. Open review threads above still apply.

Authored by an AI agent acting on joshlf's behalf.

@joshlf joshlf left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Authored by an AI agent acting on joshlf's behalf.

Gate 2 Independent Cross-Family Review — FINDINGS (tier2a_core_tcb, Round 6)

  • Identity: multi:dbb2ae53ac1d429095f0df348d4aa341843cf682:90377931875a2764cae1795c03d44514442e0d13 (base=dbb2ae53ac1d, head=90377931875a, tree=bcff50256826)
  • Separation: author_family=agent vs. reviewer_family=multi
  • Coverage: 24 inspected, 0 inapplicable, 0 blocked (of 24 changed file(s))
  • Review mode: delta_escalated relative to the prior Gate 2 review at head f457facfd3adcd30874af9ea7d79c7981baa4d77 (escalated to the full panel: Q1 delta guard forces the full panel)
Seat Family Role Status Verdict Findings Latency
seat1 claude-frontier-thinking tcb_and_api_critic completed clean 0 684s
seat2 gemini-frontier-thinking tcb_and_spec_critic completed findings 1 1256s
seat3 gemini-executable-falsifier sandboxed_probe_runner completed clean 0 1097s

Deduplicated Findings

ID Sev Consensus Verification Location Summary
G2-R6-01 P2 1 (seat2) static_verified trusted/cargo-anneal/src/core/foreign_entry.rs:1076 ty_requires_structural_extra_validity caches depth-truncated Ok(true) fallback results in the shared extra_validity_memo, causing false rejection of valid rustc-capture manifests and poisoning subsequent shallow parameter/export checks.

G2-R6-01 [P2] (trusted/cargo-anneal/src/core/foreign_entry.rs:1076, Pass 2 §3 (trusted/cargo-anneal), static_verified): ty_requires_structural_extra_validity caches depth-truncated Ok(true) fallback results in the shared extra_validity_memo, causing false rejection of valid rustc-capture manifests and poisoning subsequent shallow parameter/export checks.

  • Invariant: validate_ffi_exports_manifest structural validity validation must agree with rustc-capture (LayoutCollector::lower_ty + ValidityReasonCollector) and must not cache depth-dependent truncation outcomes in a depth-independent rust_name -> bool memo map.
  • Evidence: In trusted/rustc-capture/src/ffi_exports.rs:1151-1165 and :1388-1397, LayoutCollector::lower_ty caches lowered records in record_tys (returning Ok(()) on re-encounter), and ValidityReasonCollector (lines 1773-1985) has no depth cutoff. In trusted/cargo-anneal/src/core/foreign_entry.rs:1000-1008 and :1038-1077, ty_requires_structural_extra_validity returns Ok(false) on FfiType::Ptr without populating extra_validity_memo, returns Ok(true) whenever depth > MAX_LAYOUT_WALK_DEPTH (64), and unconditionally writes memo.insert(rust_name.clone(), requires) at line 1076 into the manifest-wide extra_validity_memo (line 1272). Trigger: define a 35-level #[repr(C)] baseline-initialized struct chain S0 { x: u32 }, ..., S34 { f: S33 } and #[repr(C)] struct Wrap { a: [[...[S34; 1]...; 1]; 1], b: bool } (31 nested arrays) in pub extern "C" fn f(p0: *const S34, p1: Wrap, p2: S34) -> u32. rustc-capture lowers p0 at depth 1..37 (< 64) caching S0..S34, hits the cache for S34 inside p1 at depth 33, and emits BaselineInitialized for p0 and p2 and ExtraValidity for p1. In foreign_entry.rs, collect_referenced_layouts succeeds, p0 skips S34 in ty_requires_structural_extra_validity, p1 walks Wrap + 31 arrays + S34..S2 and hits S1 at depth 65 > 64 -> Ok(true), poisoning extra_validity_memo for S2..S34 with true (p1 still passes line 1325 because it is ExtraValidity). Then shallow depth-0 p2: S34 (or any later export g(x: S34)) reads the poisoned true from extra_validity_memo at line 1039 and fails at lines 1317-1322. (Similarly, p1: [[...[S34; 1]...; 1]; 1] marked BaselineInitialized is directly rejected.) Because validate_acyclic_by_value_layouts (line 1268) and StrictJsonDom depth 256 (line 1412) already guarantee acyclic O(V + E) termination, depth truncation should not poison memo (and is unnecessary once acyclicity is verified).

Non-blocking advisories (P3, not Gate 2 findings)

These notes do not block merge and do not require another Gate 2 round.

  • G2-R6-A01 [P3] (docs/trust-model.md:727): The supplied PR metadata has no Human review surface block (the Review Receipt comment was not in the bundle), so its completeness could not be checked; it must exist before ready-for-review and list the trusted/cargo-anneal TCB changes, the ci/ changes, the docs/trust-model.md default-admission policy flip, and the new receipt fields.
  • G2-R6-A02 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:67): The agent-facing cargo-anneal skill doc (trusted/cargo-anneal/skills/cargo-anneal/SKILL.md, 'Diagnose failures and read Receipt v3 honestly') is not updated to mention ffi_exports_manifest_sha256, foreign_entry_contracts, or reporting residual foreign-entry obligations and extra-validity warnings.
  • G2-R6-A03 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:1989): parse_foreign_entry_contracts_strict permits arbitrary non-empty warnings[*].code values, explicit empty warnings arrays, and ambient.panic_link_consistency statements not matching configuration.panic during offline receipt inspection.
  • G2-R6-A04 [P3] (trusted/cargo-anneal/src/inspect.rs:1050): verify_artifacts reads capture/capture.json with MAX_ARTIFACT_FILE_BYTES instead of receipt_artifact_cap even though line 1064 forwards max(MAX_ARTIFACT_FILE_BYTES, max_receipt_bytes) to the JSON parser.

Executed Sandbox Probes

  • seat3 Static hygiene scan of candidate tree (2923 tracked paths) and all 24 changed files + commit message: 0 symlinks (120000: outcome=passed
  • seat3 sha256sum --check --strict trusted/root-manifest.sha256 inside bwrap --unshare-all --clearenv exited 0 (Cargo.toml, Carg: outcome=passed
  • seat3 python3 -I -B -m unittest discover -s ci -p 'test_verify_zerocopy.py' -v inside bwrap exited 0 (32/32 tests passed in 2.: outcome=passed
  • seat3 All 4 tests in ci/test_check_taxonomy_lockstep.py passed inside bwrap (split to stay under 30s timeout: 3 fast tests in : outcome=passed
  • seat3 python3 -I -B probe in bwrap verified canonical_taxonomy_v1.json counts (101 constructs matching total_constructs, statu: outcome=passed
  • seat3 Standalone rustc binary compiled and executed in bwrap verified parse_strict_iterative, parse_json_string_token, and par: outcome=passed
  • seat3 Isolated bwrap unittest runs exited 0 on test_workflow_yaml (14), test_check_pr_hygiene_size_budget (17), test_check_con: outcome=passed
  • seat3 Verified all local relative links in candidate docs/alpha.md and docs/trust-model.md resolve to existing repository targ: outcome=passed
  • seat3 Workflow checklist item 1 (top-level and per-job permissions least-privilege): 0 .github/workflows/*.yml files modified : outcome=passed
  • seat3 Workflow checklist item 2 (triggers): 0 .github/workflows/*.yml files modified; bwrap scan confirmed 0 occurrences of pu: outcome=passed
  • seat3 Workflow checklist item 3 (secrets / GITHUB_TOKEN / GITHUB_ENV / GITHUB_OUTPUT scoping): 0 workflow files modified; grep: outcome=passed
  • seat3 Workflow checklist item 4 (release/publish protected environment): release.yml unmodified; bwrap audit confirmed environ: outcome=passed
  • seat3 Workflow checklist item 5 (persist-credentials: false and full SHA pinning): 0 workflow files modified; anneal-fast-chec: outcome=passed
  • seat3 Workflow checklist item 6 (${{ ... }} script injection in run:): 0 workflow files modified; no modified files introduce : outcome=passed
  • seat3 Workflow checklist item 7 (cache and artifact trust boundaries): 0 workflow or ci/checks.toml files modified; grep acros: outcome=passed
  • seat3 Workflow checklist item 8 (no guard relaxation): 0 .github/workflows/*.yml or ci/checks.toml guards altered; ci/verify_z: outcome=passed

Wire `cargo-anneal` to opt into and enforce Phase 1 non-variadic,
non-unwinding `extern "C"` and Linux `extern "system"` export
verification on top of the Ring-0 `Body.abi` metadata and
`ffi_exports.json` manifest capture infrastructure:

- Foreign-entry manifest parsing and `ForeignEntryContract` builder
  (`trusted/cargo-anneal/src/core/foreign_entry.rs`,
  `trusted/cargo-anneal/src/core/mod.rs`): Strictly parse and validate
  `capture/ffi_exports.json` (`#[serde(deny_unknown_fields)]`, schema
  version, target, 64-bit pointer width, `ambient_obligations`, record
  and enum layout tables including `Vec`, `FnPtr.c_variadic`, payload
  enums, `FfiEnumTagEncoding`, and `"uninhabited"`/`"untagged"`/`"none"`
  discriminants, structural extra-validity classification, and exact
  per-export `signature_sha256` recomputation), cross-check captured
  foreign-ABI bodies (`abi != .rust`) 1:1 against `capture.json`, and
  emit deterministic `ForeignEntryContract` records with explicit
  per-parameter `entry_validity` clauses, `safety_pre` (for `unsafe`
  exports only), fixed `ambient.*` clauses, non-suppressible `D3`
  extra-validity warnings (`extra_validity_parameter`), and an explicit
  baseline byte-initialization validity caveat (`MaybeUninit<T>`
  contrast) so non-flagged scalar/pointer parameters are never implied
  to be validity-free.
- `verify.rs` wiring (`trusted/cargo-anneal/src/verify.rs`): Pass
  `--allow-foreign-exports` to `anneal-rustc-capture` on non-stdlib
  runs, authenticate `configuration.allow_foreign_exports` in
  `capture.json` fail-closed whenever foreign-ABI bodies or
  `ffi_exports.json` appear, refuse foreign exports on `MirEnvelope`
  (`#[spec]`) requests, hash `ffi_exports.json` into
  `ffi_exports_manifest_sha256`, record
  `FOREIGN_ENTRY_RECEIPT_ASSUMPTION` in `assumptions`, and attach
  `foreign_entry_contracts` to Receipt v3.
- Receipt v3 `inspect` & human output
  (`trusted/cargo-anneal/src/core/inspect/{schema,render,diff}.rs`,
  `trusted/cargo-anneal/src/inspect.rs`,
  `trusted/cargo-anneal/src/output.rs`): Enforce strict envelope
  validation (symmetric `allow_foreign_exports`, `assumptions`,
  `ffi_exports_manifest_sha256`, `foreign_entry_contracts`, `Phase 1`
  `residual`-only discharge), verify `capture/ffi_exports.json` SHA-256
  and re-derived contracts in `--verify-artifacts`, render human/ledger/
  card disclosures and warnings, and classify foreign-entry changes and
  regressions in three-tier `diff_receipts`.
- End-to-end tests, docs, and taxonomy lockstep
  (`tests/cargo-anneal/tests/suite/ffi_export_entry_e2e.rs`,
  `tests/cargo-anneal/tests/cli/sharding_and_limits/`,
  `tests/cargo-anneal/tests/cli/foreign_entry_guards.rs`,
  `tests/testkit/src/assertions.rs`, `.config/nextest.toml`,
  `docs/alpha.md`, `docs/trust-model.md`,
  `tools/anneal-corpus-scan/canonical_taxonomy_v1.json`,
  `ci/test_check_taxonomy_lockstep.py`, `ci/verify_zerocopy.py`,
  `ci/test_verify_zerocopy.py`): Add E2E scalar `extern "C"`
  verification under `panic=unwind` + `overflow_checks: true`, tamper
  and missing-flag controls, extra-validity warning + `safety_pre` test,
  and safe-export precondition refusal control, and promote
  `item_extern_c_export_non_unwinding` to `SUPPORTED_END_TO_END`.

Agent-authored-by: AI agent acting on Josh Liebow-Feeser's behalf
@joshlf
joshlf force-pushed the joshlf/ffi-export-entry-spine-p2 branch from 9037793 to ed4f573 Compare December 5, 2026 19:55
@joshlf

joshlf commented Dec 5, 2026

Copy link
Copy Markdown
Member Author

🤖 Exact-HEAD verification receipt for PR 2 (HEAD=ed4f5735d233e53d5c54e76523352d09a42c0ded, TREE=0097c5b1d186ade1c691489b441c10d58fb299a7, BASE=6c2abcfa4aa5625b82433fa53da32762feadc4c0).

Gate-2 Round 6 Fix (1-File TCB Delta over 90377931875a / f457facfd3ad / Gate-5 1a7d0551d6b0)

  • Minimal TCB delta (trusted/cargo-anneal/src/core/foreign_entry.rs only): Relative to Gate-5 1a7d0551d6b0 (and prior 90377931875a), the sole trusted/ change remains in trusted/cargo-anneal/src/core/foreign_entry.rs (alongside the two prior non-TCB rebase updates in tests/cargo-anneal/tests/suite/ffi_export_entry_e2e.rs and tools/anneal-corpus-scan/canonical_taxonomy_v1.json from f457facfd3ad).
  • Iterative post-order structural validity check (G2-R6-01):
    • Replaced the recursive depth > MAX_LAYOUT_WALK_DEPTH (64) fallback in ty_requires_structural_extra_validity with an iterative explicit-stack post-order traversal (iterative Array/Slice unwrapping in O(1) stack space, explicit Record/Tuple frames, local visiting_records cycle detection, and post-order memo caching).
    • Because validate_acyclic_by_value_layouts upfront rejects cyclic by-value graphs and StrictJsonDom bounds JSON container nesting depth (256), every visited record is evaluated exact-once in strictly linear O(V + E) time with zero call-stack overflow risk, no depth-dependent Ok(true) truncation, and no poisoning of manifest-wide extra_validity_memo across shallow parameters/exports—agreeing with rustc-capture's ValidityReasonCollector.
    • Added ty_requires_structural_extra_validity_avoids_depth_truncation_memo_poisoning covering the 35-level #[repr(C)] struct chain S0..S34 + Wrap (31 nested arrays of S34 and b: bool) with p0: *const S34, p1: Wrap (ExtraValidity), p2: S34 (BaselineInitialized), a subsequent shallow export g(x: S34) (BaselineInitialized), a deep 31-nested-array parameter [[...[S34; 1]...; 1]; 1] (BaselineInitialized), and a fail-closed negative control with a leaf bool at combined depth > 64.

Human review surface (--tcb)

  • ci/test_check_taxonomy_lockstep.py (taxonomy lockstep tests for promoted item_extern_c_export_non_unwinding)
  • ci/test_verify_zerocopy.py (zerocopy verifier tests for allow_foreign_exports and foreign-entry contract refusal)
  • ci/verify_zerocopy.py (accepts configuration.allow_foreign_exports, rejects foreign-entry contracts on zerocopy)
  • docs/trust-model.md (default-admission policy update for Phase 1 foreign-ABI exports and new Receipt v3 fields)
  • trusted/cargo-anneal/src/core/foreign_entry.rs (manifest parser/validator, iterative structural extra-validity check, ForeignEntryContract builder)
  • trusted/cargo-anneal/src/core/inspect/diff.rs (three-tier receipt diffing for foreign-entry contracts and warnings)
  • trusted/cargo-anneal/src/core/inspect/render.rs (human/ledger/card rendering of foreign-entry disclosures and warnings)
  • trusted/cargo-anneal/src/core/inspect/schema.rs (Receipt v3 schema validation for ffi_exports_manifest_sha256 and foreign_entry_contracts)
  • trusted/cargo-anneal/src/core/inspect/strict_json.rs (iterative duplicate-key-rejecting strict JSON DOM parser)
  • trusted/cargo-anneal/src/core/mod.rs (module wiring for foreign_entry)
  • trusted/cargo-anneal/src/inspect.rs (--verify-artifacts SHA-256 and contract re-derivation for capture/ffi_exports.json)
  • trusted/cargo-anneal/src/output.rs (success card rendering for foreign-entry contracts and extra-validity warnings)
  • trusted/cargo-anneal/src/verify.rs (--allow-foreign-exports opt-in, capture.json authentication, MirEnvelope refusal, and Receipt v3 emission)

Verification ([real measurement] on exact HEAD=ed4f5735d233e53d5c54e76523352d09a42c0ded)

  • cargo test --locked --offline -p cargo-anneal --lib -- foreign_entry inspect:: — 70 passed, 0 failed (1.76s; 385 unrelated tests filtered out)
  • cargo test --locked --offline -p cargo-anneal --lib — 455 passed, 0 failed (352.73s)
  • cargo test --locked --offline -p cargo-anneal-tests --no-default-features --test cli --test inspect — 131/131 cli passed (12.29s), 46/46 inspect passed (17.92s)
  • cargo test --locked --offline -p cargo-anneal-tests --test suite -- ffi_export_entry (with anneal-rustc-capture built on pinned nightly-2026-05-31 and anneal-audit) — 3 passed, 0 failed (274.77s; 79 unrelated tests filtered out)
  • RUSTFLAGS="-D warnings" cargo clippy --locked --offline --no-deps -p cargo-anneal --lib --bins -- -D warnings — pass (14.32s)
  • cargo clippy --locked --offline --no-deps -p cargo-anneal --no-default-features --lib --bins -- -D warnings — pass (10.48s)
  • cargo clippy --locked --offline --no-deps -p cargo-anneal-tests --no-default-features --test cli --test inspect -- -A clippy::type_complexity -D warnings — pass (9.62s)
  • ./ci/check_todo.sh, python3 -B ci/check_contract_lockstep.py (1 contract(s) verified), python3 -B ci/check_taxonomy_lockstep.py (18 enums, 335 variants, 101 constructs, 238 source refs), python3 -B -m unittest ci/test_check_taxonomy_lockstep.py ci/test_verify_zerocopy.py (36 tests, 24.74s), and python3 -B ci/check_pr_hygiene.py --base 6c2abcfa4aa5625b82433fa53da32762feadc4c0 --head HEAD --receipt-file ... — pass (0 findings)
  • Not yet exercised on ed4f5735d233: wasm32-unknown-unknown target check (target sysroot absent on remote runner) and full GitHub Actions ci-core matrix (runs upon push).

Authored by an AI agent acting on Josh Liebow-Feeser's behalf.

@joshlf joshlf left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Authored by an AI agent acting on joshlf's behalf.

Gate 2 Independent Cross-Family Review — CLEAN (tier2a_core_tcb, Round 7)

  • Identity: multi:1a60949aad8080f5d083aabd2edeacfe0d39078d:ed4f5735d233e53d5c54e76523352d09a42c0ded (base=1a60949aad80, head=ed4f5735d233, tree=0097c5b1d186)
  • Separation: author_family=agent vs. reviewer_family=multi
  • Coverage: 24 inspected, 0 inapplicable, 0 blocked (of 24 changed file(s))
  • Review mode: delta_escalated relative to the prior Gate 2 review at head 90377931875a2764cae1795c03d44514442e0d13 (escalated to the full panel: Q1 delta guard forces the full panel)
Seat Family Role Status Verdict Findings Latency
seat1 claude-frontier-thinking tcb_and_api_critic completed clean 0 713s
seat2 gemini-frontier-thinking tcb_and_spec_critic completed clean 0 904s
seat3 gemini-executable-falsifier sandboxed_probe_runner completed clean 0 2284s

No unresolved P0-P2 findings raised across completed seats.

Non-blocking advisories (P3, not Gate 2 findings)

These notes do not block merge and do not require another Gate 2 round.

  • G2-R7-A01 [P3] (docs/trust-model.md:724): The trust-model section on foreign-ABI export capture does not describe the new Receipt v3 trust semantics (foreign_entry_contracts clauses are all residual, i.e. the verified guarantee holds only if callers meet the entry_validity, safety_pre and ambient obligations).
  • G2-R7-A02 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:42): Doc comment claims structural validity classification 'never disagrees' with rustc-capture's ValidityReasonCollector, but the structural walk ignores layout scalar valid ranges (e.g. NonZero records) and can return false where capture reports extra validity.
  • G2-R7-A03 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:682): collect_referenced_layouts permits depth 64 (65 frames) whereas rustc-capture LayoutCollector stops at depth >= 64.
  • G2-R7-A04 [P3] (trusted/cargo-anneal/src/core/foreign_entry.rs:827): is_linux_target_triple matches target.os == linux across all 322 built-in rustc targets, but synthetic 4-component *-linux-androideabi or 3-component custom -linux- triples would misclassify.
  • G2-R7-A05 [P3] (trusted/cargo-anneal/src/core/inspect/diff.rs:1835): Retiring safety_pre with --require-unchanged-specs emits a Tier A note mentioning specification_manifest_sha256 even when specification_manifest_sha256 itself did not change.
  • G2-R7-A06 [P3] (trusted/cargo-anneal/src/core/inspect/diff.rs:2056): When baseline_altered triggers on a baseline-only entry_validity clause with unchanged IDs and no extra-validity entries, fmt_ev emits identical base and head ID strings instead of showing the altered baseline payload.
  • G2-R7-A07 [P3] (trusted/cargo-anneal/src/verify.rs:5379): PR title and body say cargo-anneal 'opts into' foreign exports, but the flag is passed on every non-stdlib run with no user-facing opt-in or opt-out; the description could state this default expansion explicitly.

Executed Sandbox Probes

  • seat1 bwrap-sandboxed python3 -B -m unittest discover -s ci -p test_verify_zerocopy.py on candidate copy: outcome=Ran 32 tests OK
  • seat1 python3 -B check_taxonomy_lockstep.check_lockstep on candidate tree (base-identical script, untrusted JSON input): outcome=ok=True, enums_found=18, total_constructs=101, unmapped=[], stale=[]
  • seat3 hygiene_sha256_manifest: outcome=passed
  • seat3 hygiene_static_repo_and_docs: outcome=passed
  • seat3 ci_check_taxonomy_lockstep: outcome=passed
  • seat3 ci_test_check_taxonomy_lockstep: outcome=passed
  • seat3 ci_test_verify_zerocopy: outcome=passed
  • seat3 rustc_target_os_linux_parity_322_targets: outcome=passed
  • seat3 bwrap_rustc_probe_strict_json_and_foreign_entry: outcome=passed
  • seat3 workflow_checklist_item_1_permissions: outcome=not_applicable
  • seat3 workflow_checklist_item_2_triggers: outcome=not_applicable
  • seat3 workflow_checklist_item_3_secrets: outcome=not_applicable
  • seat3 workflow_checklist_item_4_protected_environments: outcome=not_applicable
  • seat3 workflow_checklist_item_5_checkout_and_pinned_shas: outcome=not_applicable
  • seat3 workflow_checklist_item_6_shell_injection: outcome=not_applicable
  • seat3 workflow_checklist_item_7_cache_artifact_trust: outcome=not_applicable
  • seat3 workflow_checklist_item_8_guard_relaxations: outcome=not_applicable

@joshlf joshlf left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ci-core approve ed4f573

@joshlf

joshlf commented Dec 6, 2026

Copy link
Copy Markdown
Member Author

Authored by an AI agent acting on joshlf's behalf. Posted /ci-core approve for ed4f5735d233e53d5c54e76523352d09a42c0ded under joshlf's standing authorization, after this head passed its independent review.

@joshlf
joshlf added this pull request to the merge queue Dec 6, 2026
Merged via the queue into main with commit d076e06 Dec 6, 2026
79 of 80 checks passed
@joshlf
joshlf deleted the joshlf/ffi-export-entry-spine-p2 branch December 6, 2026 01:20
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.

1 participant