Calybris Core
Deterministic proof-carrying decision core for systems that must explain and replay why an action was allowed, substituted, or rejected.
Not an LLM framework. Not an exchange or strategy engine. A domain-neutral primitive:
candidate + policy constraints → decision + digests + optional WAL + budget proof
#![forbid(unsafe_code)] · unit/proptest/Loom/Miri coverage · Apache-2.0
Two Reference Use Cases
| Use case | What Calybris does |
|---|---|
| LLM routing | Select / substitute / reject models under budget, risk, quality, latency |
| Pre-trade guard | Admit / reject candidate orders under exposure, risk, and latency limits |
Calybris is not an exchange, market data feed, colocation stack, or alpha engine. It is a deterministic pre-trade decision kernel — integer-only constraints, replay verification, and fixed-point conservation proofs.
Quick Start
use BudgetEngine;
use ;
use *;
use ;
let models = vec!;
let snapshot = try_new?;
let input = KernelInput ;
let decision = snapshot.prescribe;
assert_eq!;
assert!;
let budget = new;
budget.ensure_tenant;
let proof: ConservationProof = prove_conservation?;
assert_eq!;
Kernel-only (no WAL):
Architecture
kernel— Integer-only decision kernel (~115ns/decision).prescribe_with_traceexposes per-constraint rejection counts.verify— Policy + input + decision digests, full replay,DigestDecodeErroron public API.finance— Ledger digest,FinancialCertificate,ConservationProof,prove_conservation,certify_snapshot.wal— Tamper-evident hash chain,append_audited, fail-closedreplay_audited_wal.budget— CAS reserve/commit/release. Conservation holds after completed ops:remaining + reserved + committed_lifetime == initial. Loom + Miri in CI.
Audit Pipeline
prescribe → audit_bundle → append_audited → replay_audited_wal (fail-closed)
↓
calypol1 / calyinp1 / calydcn1 digests
Financial layer & policy
Fixed-point i64 microcents (1 cent = 1,000,000). No f64.
committed_microcents— lifetime cumulative spend (monotonic; never decreases)reserved_microcents— active holds awaiting commit/releasetop_up_tenant— add funds without resetting lifetime spendrestore_from_snapshot— exclusive-recovery restore from frozenBudgetSnapshotverify_conservation— audit/reconciliation path (full snapshot)PolicySnapshot::utility_for_model— per-model utility (not prescribe winner/runner-up)
budget.ensure_tenant;
budget.top_up_tenant;
let proof = prove_conservation?;
let cert = certify_ledger;
assert!;
| Policy API | Use |
|---|---|
PolicySnapshot::try_new |
Production — validates catalog + BPS (MAX_BPS, etc.) |
PolicySnapshot::new_unchecked |
Tests / fuzz only — never serve without explicit validate() |
PolicySnapshot::new |
Deprecated alias for new_unchecked |
Examples
Tests & CI
cargo fmt --check
cargo clippy --all-targets -- -D warnings
cargo test --all-features
cargo test --no-default-features
RUSTFLAGS='--cfg loom' LOOM_MAX_PREEMPTIONS=3 cargo test --test budget_loom
cargo +nightly miri test --lib --all-features # see docs/MIRI.md for CI filters
cargo doc --no-deps
Tested on Rust 1.85.0 (MSRV) and stable. Miri runs on nightly in CI (UB detection); Loom covers budget concurrency interleavings.
Integration contract
Calybris verifies decisions and conservation proofs — it does not auto-invoke verify_decision in your hot path. You must call it at audit boundaries:
prescribe → verify_decision → (optional WAL / prove_conservation)
Recommended hooks: before append_audited, at reconciliation, before exporting a FinancialCertificate. Skipping verification is a deployment risk, not a library default. See docs/AUDIT_GUIDE.md.
External audit
Invariant docs, adversarial tests, Loom, Miri, and supply-chain checks are in place for third-party review. A paid external audit is still your responsibility — see docs/AUDIT_GUIDE.md §7.
What This Crate Is Not
- Exchange gateway, market data, or order lifecycle
- Thompson Sampling / adaptive routing
- HTTP API server
See emirhuseyin.tech/engine for the full proprietary stack.
License
Apache-2.0. See LICENSE.