prism/lib.rs
1//! `prism` — the Prism **standard library** (wiki ADR-031).
2//!
3//! Per [Wiki ADR-031][09-adr-031], the `prism` crate is the standard
4//! library: a **façade** re-exporting [`uor_foundation`]'s substrate
5//! together with the built-in axes and built-in types the Layer-3
6//! sub-crates of the standard library declare. The wiki's user-facing
7//! promise is _"depend on `uor-prism`, write a `prism_model!`, done"_
8//! — application authors do not need to add `uor-foundation`,
9//! `uor-foundation-sdk`, or the individual `uor-prism-<domain>` crates
10//! to their dependency list. Everything composes through
11//! `use prism::*;` (or finer-grained imports like
12//! `use prism::crypto::Sha256Hasher`).
13//!
14//! Per [ADR-024][09-adr-024], the standard library is **Layer 2** of
15//! the three-layer algebraic closure spine: substrate (`uor-foundation`)
16//! is Layer 1; verbs and axes declared by application crates are
17//! Layer 3.
18//!
19//! # Standard-library Layer-3 sub-crate roster
20//!
21//! Per ADR-031's roster commitment, the standard library publishes
22//! four canonical sub-crates from the Prism repository, each consumed
23//! through the façade re-exports below. Every axis impl is parametric
24//! in its natural axis (byte-width, Q-format split, hasher, dimension)
25//! so application authors instantiate the impl their model needs
26//! without re-rolling the kernel body; canonical type aliases (e.g.,
27//! `Sha256Hasher`, `BigInt256Numeric`, `CpuI8Tensor4x4Matmul`) name
28//! the most common instantiations.
29//!
30//! - **[`crypto`]** — wiki: hashes, curves, signatures, commitments.
31//! `HashAxis` impls: `Sha256Hasher`, `Sha512Hasher`,
32//! `Sha3_256Hasher`, `Keccak256Hasher`, `Blake3Hasher`.
33//! `CommitmentAxis` impl: `MerkleRoot<H, LEAF_BYTES>` (parametric
34//! over `HashAxis`), default alias `MerkleRootCommitment` = SHA-256.
35//! Shapes: `Digest<N>`, `PublicKey<N>`, `Signature<N>`,
36//! `MerkleProofShape<MAX_DEPTH, LEAF_BYTES>`.
37//! - **[`numerics`]** — wiki: integer, fixed-point, prime-field,
38//! GF(2) arithmetic. Parametric: `BigIntModularNumeric<BYTES>`
39//! (8..=512 bits), `FixedPointQNumeric<I, F>` (any Q-format split
40//! ≤ 64 bits total), `Gf2NumericAxisN<BYTES>` (1..=128 bytes).
41//! Concrete: `PrimeFieldNumericSecp256k1`. Shapes: `BigIntShape<N>`,
42//! `FixedPointShape<I, F>`, `FieldElementShape<N>`,
43//! `Gf2RingShape<N>`.
44//! - **[`tensor`]** — wiki: tensor compute + activations. Parametric:
45//! `CpuI8MatmulSquare<DIM>` (1..=16 square `i8`→`i16` matmul),
46//! `CpuI8VectorActivation<N>` (1..=256-length `i8` vector ReLU /
47//! Q1.7 sigmoid). Shapes: `MatrixShape<R, C, ELEM_BYTES>`,
48//! `VectorShape<N, ELEM_BYTES>`.
49//! - **[`fhe`]** — wiki: homomorphic encryption. Parametric reference
50//! impl: `OneTimePadFhe<BLOCK_BYTES>` (1..=256). Shape:
51//! `CiphertextShape<N>`.
52//!
53//! # SDK macros (re-exported)
54//!
55//! Per ADR-031's façade commitment, the SDK macros declared by
56//! `uor-foundation-sdk` are re-exported through [`pipeline`] so a
57//! single `use prism::pipeline::prism_model;` reaches the canonical
58//! application-author surface:
59//!
60//! - `prism_model!` (ADR-020 / ADR-022) — declare a typed route
61//! - `verb!` (ADR-024) — declare a Layer-3 verb (named composition)
62//! - `axis!` (ADR-030) — declare a Layer-3 axis (substrate-extension
63//! vocabulary)
64//! - `resolver!` (ADR-036) — declare a `ResolverTuple` value
65//! - `output_shape!` (ADR-027) — declare a custom Output shape
66//! - `use_verbs!` (ADR-024) — import verbs from another implementation
67//! - `product_shape!`, `coproduct_shape!`, `cartesian_product_shape!`,
68//! `partition_product!`, `partition_coproduct!` (ADR-026 / ADR-033)
69//! — shape constructors
70//!
71//! # See also
72//!
73//! - [Wiki: 01 Introduction and Goals](https://github.com/UOR-Foundation/UOR-Framework/wiki/01-Introduction-and-Goals)
74//! - [Wiki: 04 Solution Strategy](https://github.com/UOR-Foundation/UOR-Framework/wiki/04-Solution-Strategy)
75//! - [Wiki: 05 Building Block View § Whitebox `prism`](https://github.com/UOR-Foundation/UOR-Framework/wiki/05-Building-Block-View#whitebox-prism)
76//! - [Wiki: 06 Runtime View § Scenario 1: Principal Data Path Execution](https://github.com/UOR-Foundation/UOR-Framework/wiki/06-Runtime-View#scenario-1-principal-data-path-execution)
77//! - [Wiki: 09 Architecture Decisions § ADR-024 — Three-layer algebraic closure][09-adr-024]
78//! - [Wiki: 09 Architecture Decisions § ADR-030 — `axis!` SDK macro][09-adr-030]
79//! - [Wiki: 09 Architecture Decisions § ADR-031 — `prism` is the standard library][09-adr-031]
80//! - [Wiki: 10 Quality Requirements § Quality Scenarios](https://github.com/UOR-Foundation/UOR-Framework/wiki/10-Quality-Requirements#quality-scenarios)
81//! - [Wiki: 12 Glossary](https://github.com/UOR-Foundation/UOR-Framework/wiki/12-Glossary)
82//! - [Wiki: Conceptual Model § SD](https://github.com/UOR-Foundation/UOR-Framework/wiki/Conceptual-Model#sd) — OPM (ISO 19450) overall system diagram naming the three actors and Prism as the system-of-interest
83//! - [Wiki: Conceptual Model § SD1 Prism Structure](https://github.com/UOR-Foundation/UOR-Framework/wiki/Conceptual-Model#sd1-prism-structure) — OPM decomposition of Prism into Substrate, Runtime, and Replay Surface
84//!
85//! # Constraints
86//!
87//! This crate is normatively bound by:
88//!
89//! - **TC-01** — zero-cost runtime; no Prism interpreter layer at execution
90//! - **TC-02** — sealing of `Validated`, `Grounded`, `Certified` via the Rust
91//! type system, enforced through `pub(crate)` constructors in the substrate
92//! - **TC-03** — singular principal data path; exactly one constructor for
93//! `Grounded<T>`, reached only through [`pipeline::run`]
94//! - **TC-04** — bilateral compile-time UORassembly enforcement
95//! - **TC-05** — replayability without invoking author deciders or hash
96//! functions; surfaced through [`replay::certify_from_trace`]
97//! - **TC-06** — no application-author infrastructure at runtime
98//! - **ADR-006** — UORassembly is enforced bilaterally at compile time
99//! through the Rust type system; this is the architectural commitment
100//! that makes TC-04 enforceable rather than aspirational
101//!
102//! Substitution axes per ADR-007/030/036: `HostTypes`, `HostBounds`,
103//! `AxisTuple`, `ResolverTuple`, `TypedCommitment`.
104//!
105//! Additionally:
106//!
107//! - **ADR-019** — `uor-foundation`'s vocabulary is the signature
108//! category, `Term` is its initial algebra, [`pipeline::run`] is the
109//! catamorphism.
110//! - **ADR-020** — application authors declare a Prism application by
111//! implementing the sealed [`pipeline::PrismModel`] trait; the
112//! `prism_model!` macro derives `forward`'s body via initiality.
113//! - **ADR-024** — three-layer algebraic closure (substrate, prism,
114//! implementation).
115//! - **ADR-030** — the `axis!` SDK macro is the universal
116//! substrate-extension declaration mechanism.
117//! - **ADR-031** — `prism` IS the standard library: a façade over
118//! `uor-foundation` plus Layer-3 sub-crates published from the
119//! Prism repository.
120//! - **ADR-040** — closed `BoundShape` catalog (7 individuals) with
121//! `type:LexicographicLessEqBound` for byte-sequence-valued
122//! observables; 1:1 correspondence with the foundation-published
123//! `ObservablePredicate` impl surface per ADR-049.
124//! - **ADR-048** — typed-commitment substrate: the `TypedCommitment`
125//! trait with three built-in impls (`EmptyCommitment`,
126//! `SingletonCommitment<P>`, `AndCommitment<A, B>`) and the canonical
127//! `TargetCommitment = SingletonCommitment<LexicographicLessEqThreshold>`
128//! alias. The 5th model-declaration parameter `C` on `PrismModel`.
129//! - **ADR-049** — five foundation-published typed UOR observable
130//! primitives (`Stratum<P>`, `WalshHadamardParity`,
131//! `UltrametricCloseTo<P>`, `AffineParity`,
132//! `LexicographicLessEqThreshold`) realizing the four taxonomy
133//! subclasses of ADR-038's closed observable catalog. Each is
134//! `Copy + Sealed` and consumable as a `SingletonCommitment<P>`
135//! operand per ADR-048.
136//! - **ADR-057** — bounded recursive structural typing via
137//! `ConstraintRef::Recurse { shape_iri, descent_bound }` plus the
138//! foundation shape-IRI registry (`RegisteredShape`,
139//! `ShapeRegistryProvider`, `EmptyShapeRegistry`, `lookup_shape`,
140//! `lookup_shape_in`). Apps emit a registry via the `register_shape!`
141//! SDK macro; `partition_product!` / `partition_coproduct!` operand
142//! grammar admits `recurse[(<bound>)]:T` to declare recursive
143//! references without const-eval cycles. The registry-aware
144//! nerve / Betti substrate primitives shipped in foundation 0.4.15 —
145//! `primitive_simplicial_nerve_betti_in::<T, R>`,
146//! `primitive_cartesian_nerve_betti_in::<S, R>`, and
147//! `expand_constraints_in::<R>` — walk Recurse entries through `R`'s
148//! registry plus foundation's built-in registry, giving the
149//! structurally-correct nerve / Betti reading of recursively-expanded
150//! constraint sets. Wire-format trace events gain a `Recurse`
151//! discriminant; `TRACE_REPLAY_FORMAT_VERSION` bumps to 10.
152//!
153//! # C4 placement
154//!
155//! Container `prism` (Level 2) of the Prism system. The submodules
156//! mirror the Level 2 components named in the wiki's
157//! [Building Block View § Whitebox `prism`][05-prism], with the
158//! ADR-031-introduced standard-library Layer-3 sub-crate re-exports
159//! sitting beside the foundation runtime surface:
160//!
161//! - [`pipeline`] — the principal data path + SDK macro re-exports
162//! - [`seal`] — the sealed Prism-mechanism types
163//! - [`replay`] — trace-replay verification surface
164//! - [`operation`] — operation declaration vocabulary
165//! - [`std_types`] — standard type library (baseline primitives)
166//! - [`vocabulary`] — foundation surface re-exports
167//! - [`crypto`] — standard-library cryptography axes (ADR-031)
168//! - [`numerics`] — standard-library numerics axes (ADR-031)
169//! - [`tensor`] — standard-library tensor-compute axes (ADR-031)
170//! - [`fhe`] — standard-library homomorphic-encryption axes (ADR-031)
171//!
172//! # Behavior
173//!
174//! ```rust
175//! // Given: the substrate dependency `uor-foundation` is in scope
176//! // When: the prism standard-library façade is loaded
177//! // Then: every wiki Level 2 module of `prism` AND every ADR-031
178//! // standard-library sub-crate is reachable through `use prism::*;`
179//! use prism::{operation as _, pipeline as _, replay as _};
180//! use prism::{seal as _, std_types as _, vocabulary as _};
181//! use prism::{crypto as _, fhe as _, numerics as _, tensor as _};
182//! use uor_foundation as _;
183//! assert_eq!(prism::WIKI, "https://github.com/UOR-Foundation/UOR-Framework/wiki");
184//! ```
185//!
186//! [wiki]: https://github.com/UOR-Foundation/UOR-Framework/wiki
187//! [05-prism]: https://github.com/UOR-Foundation/UOR-Framework/wiki/05-Building-Block-View#whitebox-prism
188//! [09-adr-024]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
189//! [09-adr-030]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
190//! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
191
192#![no_std]
193#![cfg_attr(docsrs, feature(doc_cfg))]
194
195pub use uor_foundation;
196
197pub mod operation;
198pub mod pipeline;
199pub mod replay;
200pub mod seal;
201pub mod std_types;
202pub mod vocabulary;
203
204// Wiki ADR-031: the Prism standard library's Layer-3 sub-crates.
205// Re-exported as `prism::<domain>` so application authors reach them
206// through the single `prism` dependency.
207pub mod crypto {
208 //! Cryptography axes per [Wiki ADR-031][09-adr-031]
209 //! (re-export of `uor-prism-crypto`).
210 //!
211 //! Application authors compose `HashAxis`, `CurveAxis`,
212 //! `SignatureAxis`, and `CommitmentAxis` through their model's
213 //! `AxisTuple` per ADR-030. Five canonical `HashAxis` impls are
214 //! provided as the standard-library reference: SHA-256, SHA-512,
215 //! SHA3-256, Keccak-256, and BLAKE3.
216 //!
217 //! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
218 pub use prism_crypto::*;
219}
220
221pub mod numerics {
222 //! Numerics axes per [Wiki ADR-031][09-adr-031]
223 //! (re-export of `uor-prism-numerics`).
224 //!
225 //! Provides `BigIntAxis`, `FixedPointAxis`, `FieldAxis`, and
226 //! `RingAxis`. Reference impls cover 256-bit modular arithmetic,
227 //! Q32.32 fixed-point, secp256k1 prime-field arithmetic, and
228 //! GF(2) over 256-bit operands.
229 //!
230 //! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
231 pub use prism_numerics::*;
232}
233
234pub mod tensor {
235 //! Tensor-compute axes per [Wiki ADR-031][09-adr-031]
236 //! (re-export of `uor-prism-tensor`).
237 //!
238 //! Provides `TensorAxis` and `ActivationAxis` with fixed-shape
239 //! CPU integer-precision reference impls. Variable-rank tensor
240 //! compute composes through verbs over
241 //! `partition_product!`-declared shapes (ADR-033/044).
242 //!
243 //! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
244 pub use prism_tensor::*;
245}
246
247pub mod fhe {
248 //! Homomorphic-encryption axes per [Wiki ADR-031][09-adr-031]
249 //! (re-export of `uor-prism-fhe`).
250 //!
251 //! Provides `FheAxis` with a reference one-time-pad impl. Production
252 //! FHE schemes (TFHE, BGV, CKKS) are operational policy per ADR-031.
253 //!
254 //! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
255 pub use prism_fhe::*;
256}
257
258/// Canonical URL of the UOR-Framework wiki, the normative source for the
259/// Prism architecture realized by this crate.
260///
261/// Every public item in `prism` carries a backlink to a wiki section that
262/// roots at this URL. Consumers may reference this constant when surfacing
263/// the same origin programmatically — for example, in error messages that
264/// direct users to the architectural section that defines a violated
265/// invariant.
266///
267/// # See also
268///
269/// - [Wiki: Home](https://github.com/UOR-Foundation/UOR-Framework/wiki)
270///
271/// # Constraints
272///
273/// - **CV-02** — code identifiers appear in monospace without paraphrase;
274/// this constant is the single source of truth for the wiki origin
275///
276/// # Behavior
277///
278/// ```rust
279/// // Given: prism is loaded
280/// // When: the wiki URL constant is read
281/// // Then: it points at the UOR-Framework wiki landing page
282/// assert!(prism::WIKI.starts_with("https://"));
283/// assert!(prism::WIKI.ends_with("/UOR-Framework/wiki"));
284/// ```
285pub const WIKI: &str = "https://github.com/UOR-Foundation/UOR-Framework/wiki";
286
287/// Minimum supported Rust version of this crate.
288///
289/// Pinned to track `uor-foundation`'s effective MSRV so the dependency
290/// graph never imposes a tighter requirement on consumers than the
291/// substrate itself. Bumping this constant requires bumping the workspace
292/// `rust-version` and the `rust-toolchain.toml` channel in lockstep.
293///
294/// # See also
295///
296/// - [Wiki: 02 Architecture Constraints](https://github.com/UOR-Foundation/UOR-Framework/wiki/02-Architecture-Constraints)
297///
298/// # Constraints
299///
300/// - **TC-04** — bilateral compile-time enforcement assumes a single,
301/// declared toolchain version on both sides of the contract
302///
303/// # Behavior
304///
305/// ```rust
306/// // Given: the MSRV constant
307/// // When: parsed into its semver components
308/// // Then: it is at least 1.83 and uses the major.minor form
309/// let parts: Vec<&str> = prism::MSRV.split('.').collect();
310/// assert_eq!(parts.len(), 2);
311/// let major: u32 = parts[0].parse().expect("major version is numeric");
312/// let minor: u32 = parts[1].parse().expect("minor version is numeric");
313/// assert!((major, minor) >= (1, 83));
314/// ```
315pub const MSRV: &str = "1.83";