agent_contracts: verifiable inference settlement — model-gated contracts#32
Merged
Merged
Conversation
Add the first contract that uses the ternary VM as a *decision model* rather than an adding machine. Every v0.1.0 contract reaches its decision by reading a trusted flag from the witness (conditional_payment fires on input[56]==1, multisig counts flag bytes, time_locked compares a supplied clock); the VM is used only for carry/borrow arithmetic. risk_gated_transfer instead computes the gate as a neural-network forward pass on the verifier path, so a machine-learning inference becomes a bit-exact, re-executable artifact that both releases money and resolves disputes — no oracle, no human underwriter. This works only because TernaryNetwork::forward is bit-exact on every conformant integer host (ARCHITECTURE.md s0.8): a model's output is a deterministic function of (weights_hash, features), so any participant can re-derive the verdict. Floating-point inference cannot do this. - risk_gated_transfer (agent_contracts/src/inference.rs): transfer gated by credit_risk_model_v1, a 4-layer integer-only ternary MLP computing APPROVE = (income + collateral - debt >= 500) AND (risk_flags <= 10). The AND is a real ReLU(b1+b2-1) non-linearity. program_hash commits to the model's weights_hash, so the model is part of the contract identity. - inference_agent example: happy path (model APPROVEs, loan settles) + dispute path (model DENIEs a high-risk applicant, malicious executor claims it disbursed, judge re-executes the model -> SlashExecutor). - 10 new tests (264 workspace total), incl. a feature-grid sweep proving the network is bit-exact vs a plain-Rust ground truth on both decision boundaries. Strict clippy + rustfmt clean. - docs/use-cases/verifiable-inference-settlement.md: the capability, the build, honest limits, and a portfolio of further model-gated use cases (parametric insurance, verifiable inference markets, oracle-free KYC, deterministic auctions, per-inference model licensing, confidential model-gated payments). INDEX + CHANGELOG updated in the same commit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017mNfJDn9fro84YvM3WnCks
RustSec flagged the entire pqcrypto-* family unmaintained on 2026-06-04 (RUSTSEC-2026-0161/-0162/-0163/-0166) because upstream PQClean is being archived (~July 2026). These crates enter via psl-crypto-agility as the ML-DSA (FIPS 204) and ML-KEM (FIPS 203) bindings. The advisory class is `unmaintained`, NOT `vulnerability`: the wrapped FIPS implementations are NIST-standardized and unchanged, and the advisories state no safe upgrade exists within the pqcrypto-* ecosystem. The forward path is the pure-Rust ml-dsa / ml-kem crates (both determinism-compatible) — a cryptographer-review-gated change tracked under ADR-0006 / gate 19. Ignore in the interim, matching the existing documented-ignore pattern (the family was already partly acknowledged via RUSTSEC-2024-0436 / paste). Updated all three sources that must agree: - deny.toml [advisories].ignore (with rationale) - .github/workflows/security.yml cargo-audit --ignore flags (cargo-audit does not read deny.toml) - docs/LICENSE_REVIEW.md (ignored-advisories table + pqcrypto note) If any advisory is reclassified unmaintained -> vulnerability, the ignore must be removed and the ml-dsa/ml-kem migration prioritized. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017mNfJDn9fro84YvM3WnCks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the first contract that uses the ternary VM as a decision model rather than an adding machine. Every v0.1.0 contract reaches its decision by reading a trusted flag from the witness (conditional_payment fires on input[56]==1, multisig counts flag bytes, time_locked compares a supplied clock); the VM is used only for carry/borrow arithmetic. risk_gated_transfer instead computes the gate as a neural-network forward pass on the verifier path, so a machine-learning inference becomes a bit-exact, re-executable artifact that both releases money and resolves disputes — no oracle, no human underwriter.
This works only because TernaryNetwork::forward is bit-exact on every conformant integer host (ARCHITECTURE.md s0.8): a model's output is a deterministic function of (weights_hash, features), so any participant can re-derive the verdict. Floating-point inference cannot do this.
Claude-Session: https://claude.ai/code/session_017mNfJDn9fro84YvM3WnCks
What & why
CI gates (all must pass)
cargo build --workspace --releasecargo test --workspace --releasecargo fmt --all -- --checkcargo clippy --workspace --exclude psl-rust-runner --all-targets -- -D warningsruff check .(if Python touched)tools/ci/check_legacy_isolation.shRepo invariants
unwrap()/expect()on production paths outside the audited categories (docs/UNWRAP_AUDIT.mdupdated if added)sorrys in load-bearing theoremsdocs/INDEX.mdupdated in this PR if any Markdown doc was added, moved, or removedlegacy/per ADR-0001, trace-hash v1 per ADR-0008) — or the PR explains whyTests