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. Wire-format trace events
144//! gain a `Recurse` discriminant; `TRACE_REPLAY_FORMAT_VERSION`
145//! bumps to 10.
146//!
147//! # C4 placement
148//!
149//! Container `prism` (Level 2) of the Prism system. The submodules
150//! mirror the Level 2 components named in the wiki's
151//! [Building Block View § Whitebox `prism`][05-prism], with the
152//! ADR-031-introduced standard-library Layer-3 sub-crate re-exports
153//! sitting beside the foundation runtime surface:
154//!
155//! - [`pipeline`] — the principal data path + SDK macro re-exports
156//! - [`seal`] — the sealed Prism-mechanism types
157//! - [`replay`] — trace-replay verification surface
158//! - [`operation`] — operation declaration vocabulary
159//! - [`std_types`] — standard type library (baseline primitives)
160//! - [`vocabulary`] — foundation surface re-exports
161//! - [`crypto`] — standard-library cryptography axes (ADR-031)
162//! - [`numerics`] — standard-library numerics axes (ADR-031)
163//! - [`tensor`] — standard-library tensor-compute axes (ADR-031)
164//! - [`fhe`] — standard-library homomorphic-encryption axes (ADR-031)
165//!
166//! # Behavior
167//!
168//! ```rust
169//! // Given: the substrate dependency `uor-foundation` is in scope
170//! // When: the prism standard-library façade is loaded
171//! // Then: every wiki Level 2 module of `prism` AND every ADR-031
172//! // standard-library sub-crate is reachable through `use prism::*;`
173//! use prism::{operation as _, pipeline as _, replay as _};
174//! use prism::{seal as _, std_types as _, vocabulary as _};
175//! use prism::{crypto as _, fhe as _, numerics as _, tensor as _};
176//! use uor_foundation as _;
177//! assert_eq!(prism::WIKI, "https://github.com/UOR-Foundation/UOR-Framework/wiki");
178//! ```
179//!
180//! [wiki]: https://github.com/UOR-Foundation/UOR-Framework/wiki
181//! [05-prism]: https://github.com/UOR-Foundation/UOR-Framework/wiki/05-Building-Block-View#whitebox-prism
182//! [09-adr-024]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
183//! [09-adr-030]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
184//! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
185
186#![no_std]
187#![cfg_attr(docsrs, feature(doc_cfg))]
188
189pub use uor_foundation;
190
191pub mod operation;
192pub mod pipeline;
193pub mod replay;
194pub mod seal;
195pub mod std_types;
196pub mod vocabulary;
197
198// Wiki ADR-031: the Prism standard library's Layer-3 sub-crates.
199// Re-exported as `prism::<domain>` so application authors reach them
200// through the single `prism` dependency.
201pub mod crypto {
202 //! Cryptography axes per [Wiki ADR-031][09-adr-031]
203 //! (re-export of `uor-prism-crypto`).
204 //!
205 //! Application authors compose `HashAxis`, `CurveAxis`,
206 //! `SignatureAxis`, and `CommitmentAxis` through their model's
207 //! `AxisTuple` per ADR-030. Five canonical `HashAxis` impls are
208 //! provided as the standard-library reference: SHA-256, SHA-512,
209 //! SHA3-256, Keccak-256, and BLAKE3.
210 //!
211 //! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
212 pub use prism_crypto::*;
213}
214
215pub mod numerics {
216 //! Numerics axes per [Wiki ADR-031][09-adr-031]
217 //! (re-export of `uor-prism-numerics`).
218 //!
219 //! Provides `BigIntAxis`, `FixedPointAxis`, `FieldAxis`, and
220 //! `RingAxis`. Reference impls cover 256-bit modular arithmetic,
221 //! Q32.32 fixed-point, secp256k1 prime-field arithmetic, and
222 //! GF(2) over 256-bit operands.
223 //!
224 //! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
225 pub use prism_numerics::*;
226}
227
228pub mod tensor {
229 //! Tensor-compute axes per [Wiki ADR-031][09-adr-031]
230 //! (re-export of `uor-prism-tensor`).
231 //!
232 //! Provides `TensorAxis` and `ActivationAxis` with fixed-shape
233 //! CPU integer-precision reference impls. Variable-rank tensor
234 //! compute composes through verbs over
235 //! `partition_product!`-declared shapes (ADR-033/044).
236 //!
237 //! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
238 pub use prism_tensor::*;
239}
240
241pub mod fhe {
242 //! Homomorphic-encryption axes per [Wiki ADR-031][09-adr-031]
243 //! (re-export of `uor-prism-fhe`).
244 //!
245 //! Provides `FheAxis` with a reference one-time-pad impl. Production
246 //! FHE schemes (TFHE, BGV, CKKS) are operational policy per ADR-031.
247 //!
248 //! [09-adr-031]: https://github.com/UOR-Foundation/UOR-Framework/wiki/09-Architecture-Decisions
249 pub use prism_fhe::*;
250}
251
252/// Canonical URL of the UOR-Framework wiki, the normative source for the
253/// Prism architecture realized by this crate.
254///
255/// Every public item in `prism` carries a backlink to a wiki section that
256/// roots at this URL. Consumers may reference this constant when surfacing
257/// the same origin programmatically — for example, in error messages that
258/// direct users to the architectural section that defines a violated
259/// invariant.
260///
261/// # See also
262///
263/// - [Wiki: Home](https://github.com/UOR-Foundation/UOR-Framework/wiki)
264///
265/// # Constraints
266///
267/// - **CV-02** — code identifiers appear in monospace without paraphrase;
268/// this constant is the single source of truth for the wiki origin
269///
270/// # Behavior
271///
272/// ```rust
273/// // Given: prism is loaded
274/// // When: the wiki URL constant is read
275/// // Then: it points at the UOR-Framework wiki landing page
276/// assert!(prism::WIKI.starts_with("https://"));
277/// assert!(prism::WIKI.ends_with("/UOR-Framework/wiki"));
278/// ```
279pub const WIKI: &str = "https://github.com/UOR-Foundation/UOR-Framework/wiki";
280
281/// Minimum supported Rust version of this crate.
282///
283/// Pinned to track `uor-foundation`'s effective MSRV so the dependency
284/// graph never imposes a tighter requirement on consumers than the
285/// substrate itself. Bumping this constant requires bumping the workspace
286/// `rust-version` and the `rust-toolchain.toml` channel in lockstep.
287///
288/// # See also
289///
290/// - [Wiki: 02 Architecture Constraints](https://github.com/UOR-Foundation/UOR-Framework/wiki/02-Architecture-Constraints)
291///
292/// # Constraints
293///
294/// - **TC-04** — bilateral compile-time enforcement assumes a single,
295/// declared toolchain version on both sides of the contract
296///
297/// # Behavior
298///
299/// ```rust
300/// // Given: the MSRV constant
301/// // When: parsed into its semver components
302/// // Then: it is at least 1.83 and uses the major.minor form
303/// let parts: Vec<&str> = prism::MSRV.split('.').collect();
304/// assert_eq!(parts.len(), 2);
305/// let major: u32 = parts[0].parse().expect("major version is numeric");
306/// let minor: u32 = parts[1].parse().expect("minor version is numeric");
307/// assert!((major, minor) >= (1, 83));
308/// ```
309pub const MSRV: &str = "1.83";