PrismDevRelOpen the app
Tutorials: Turn a Rust project into a Prism model

Learn

Turn a Rust project into a Prism modelBuild your first Prism app

// tutorial · Learn

Turn a Rust project into a Prism model

Run UORust on a sample workspace and check what it writes. Then read a Rust function beside the LexLean it became.

Subject: UORust at commit afd5cea950a8, 331 facet records, source digest f3f743b6834adaff.

What you do with UORust1. Pick a workspace: thermostat: 2 crates, 15 files 2. Project it: 81 files of Prism source 3. Check it: the Lean kernel checks every theorem 4. Read the lift: 141 of 150 functions lifted01Pick a workspacethermostat: 2crates, 15 files02Project it81 files of Prismsource03Check itthe Lean kernelchecks everytheorem04Read the lift141 of 150functions liftedWhat you do with UORust1. Pick a workspace: thermostat: 2 crates, 15 files 2. Project it: 81 files of Prism source 3. Check it: the Lean kernel checks every theorem 4. Read the lift: 141 of 150 functions lifted01Pick a workspacethermostat: 2 crates, 15 files02Project it81 files of Prism source03Check itthe Lean kernel checks everytheorem04Read the lift141 of 150 functions lifted
What you do with UORust. The four things this tutorial does, with the numbers UORust gives at commit afd5cea950a8.
The data in this figure
StepWhat happens
1. Pick a workspacethermostat: 2 crates, 15 files
2. Project it81 files of Prism source
3. Check itthe Lean kernel checks every theorem
4. Read the lift141 of 150 functions lifted

In this tutorial you run UORust on thermostat, the workspace UORust tests itself with. You check what it writes with the locked SDK. Then you read one Rust function beside the LexLean definition UORust lifted it to. Every command is a line UORust's own gate runs: the uorust recipe of its Justfile. Every number is read from UORust at commit afd5cea950a8, so what you see is what you will get.

1. Get the SDK

Everything Prism runs in the PrismPM SDK image a repository's prismpm.lock pins. Follow the Prism quickstart. You need it for step 5. UORust itself needs only a Rust toolchain.

2. Get UORust

Check out the commit this page was generated from, so your output matches it byte for byte:

git clone https://github.com/afflom/uorust
cd uorust
git checkout afd5cea950a8987da02bbf0cc7cca420b71c4b53

3. Look at the workspace

crates/uorust/tests/fixtures/thermostat is a Cargo workspace of 2 crates (thermo-core, thermo-cli). These are all its files:

4. Project it

cargo run -q --locked -p uorust -- project crates/uorust/tests/fixtures/thermostat --out thermostat-prism --name thermostat --last-modified 2026-11-11T00:00:00Z

UORust reads the workspace through cargo metadata, Cargo.lock and its own Rust syntax reader. It routes every fact through its route table. Then it writes 81 files into thermostat-prism/: prismpm.toml, lexlean.toml, one module per facet, the register and scenarios, frontier.toml, and the uorust.manifest that lists them all.

--name and --last-modified fix two inputs that would otherwise come from the directory name and the last commit. So a second run writes the same bytes. The modules hold these records:

FacetRecords
Architecture29
Design views839
Features and journeys10
Security and threat model71
Quality30
Behavior and proofs68

5. Check it

First ask UORust whether a directory holds exactly the projection. This is the line its gate runs, against the projection committed beside the fixture. Point --out at thermostat-prism to check yours:

cargo run -q --locked -p uorust -- check crates/uorust/tests/fixtures/thermostat --out crates/uorust/tests/fixtures/thermostat-prism --name thermostat --last-modified 2026-11-11T00:00:00Z

Then run three checks inside the SDK image. LexLean confirms the modules are canonical and locked. The Lean kernel checks every definition and theorem. PrismPM checks every facet, from design views to the threat model:

cd crates/uorust/tests/fixtures/thermostat-prism && lexlean fmt --check && lexlean lock --check && lexlean verify && prismpm check

Both commands exit 0. UORust's gate holds these registered claims at every commit:

UE-01:

uorust projects the fixture workspace into exactly the committed Prism project, which lexlean fmt, lexlean lock and prismpm check accept

UE-16:

A lifted function never turns unlifted: every function of product code has exactly one row of the lift register, keyed by the κ of its crate path and normalized tokens and typed as lifted, residue (with its cause), foreign (naming the registry crate of its type) or effect (naming the operating-system effect), a lifted row may carry a divergence saying where its definition parts from the Rust function (such as a Unicode table LexLean does not bind) and no other row carries one, and a projection that decides a κ the committed register records as lifted exactly as diverging, or a κ it records as lifted (the fixture's frontier.toml, this workspace's frontier.toml) as anything else is refused; a changed function is a new question, and the unlifted rows are the distance to the requirement that every function lifts, reported as an open claim and never a ceiling

6. Read what was lifted

thermostat-prism/frontier.toml gives every function of the workspace exactly one row. A lifted row names the LexLean definition the function became. The other rows say why a function was not lifted, so nothing is left out unseen:

Every function, by row kindrefusal: 1 functions; residue: 5 functions; effect: 3 functions; lifted: 141 functionsrefusal1residue5effect3lifted141
Every function, by row kind. Each of the 150 functions of the workspace has one row in frontier.toml. Lifted rows are LexLean definitions the kernel checks.
The data in this figure
functions
refusal1
residue5
effect3
lifted141
RowRowsMeaning
refusal1A fact the router proposed and admission would not decide, kept as an open claim.
residue5A pure function outside the lift so far, with the construct that stopped it.
effect3The I/O shell. It reads files, the environment, a process or the network, and is recorded as a capability in the security facet.
lifted141The function became a LexLean definition the kernel checks.

The first lifted row is thermo_core::band::above. Here is the function, at thermo-core/src/band.rs:57:

thermo-core/src/band.rs:57
pub fn above(readings: &[u32], target: u32) -> u32 {
    match readings {
        [] => 0,
        [first, rest @ ..] => {
            if *first > target {
                above(rest, target).saturating_add(1)
            } else {
                above(rest, target)
            }
        }
    }
}
Behavior::above, in src/Behavior.lex.tex
definition{
  name: above,
  parameters: [readings : (List Nat), target : Nat],
  result: Nat,
  body: (match readings
    | List.nil => 0
    | List.cons firstValue1 rest => (if (target <? firstValue1) then (if (((above rest target) + 1) <? 4294967296) then ((above rest target) + 1) else 4294967295) else (above rest target))),
  recursive_argument: readings
}

The Lean kernel checked that definition in step 5. The projection's theorems and acceptance rows are stated over definitions like it.

7. Now your workspace

Run the same two commands on your own workspace. Without --name and --last-modified, UORust takes the name from the directory and the time from its last commit. --register keeps a lift register. project writes it and check requires it to be current. A function the committed register records as lifted can never come back unlifted. Commit the register beside your workspace:

cargo run -q --locked -p uorust -- project path/to/workspace --out path/to/prism-project --register path/to/workspace/frontier.toml
cargo run -q --locked -p uorust -- check path/to/workspace --out path/to/prism-project --register path/to/workspace/frontier.toml

UORust's gate does the same to its own workspace:

cargo run -q --locked -p uorust -- check . --out target/uorust-self --name uorust --last-modified 2026-11-11T00:00:00Z --register frontier.toml {{mir}}

Every option is in the UORust command reference. To publish the result, start a repository from UOR-Foundation/template. Put the projection in its app/ and push to main. Its Pages workflow verifies, signs and deploys it (Ship).

Next

Next 9 items

The journeys UORust plans for

UORust's own model names a journey for each of its stakeholders, and the application record its holo is built from. This tutorial is the start of the Rust developer's journey:

UORust

Routes::application TextApplication #207 source

UORust 22 entries
profile
prismpm/text-application/3
cargoName
uorust-routes
cargoVersion
0.1.1
cargoDescription
Routes each kind of Rust fact UORust reads from a Cargo workspace to the one Prism record kind it emits, or refuses it.
cargoRepository
https://github.com/afflom/uorust
cargoHomepage
https://afflom.github.io/UORust/
libraryRoots
  • Uorust.Routes.dispatch
acceptanceVectors
(acceptanceVectors)
entryRoot
Uorust.Routes.dispatch
coreContract
hologram:guest/core-wasm@1
requestMaximum
(318 : UInt32)
responseMaximum
(8192 : UInt32)
guestAllocationMaximum
(319 : UInt32)
coreMemoryPages
(ctor Option.some [UInt32] (32 : UInt32))
coreStackBytes
(ctor Option.some [UInt32] (65536 : UInt32))
capabilitiesEmpty
true
fatArchive
true
primaryLayer
(0 : UInt8)
viewLayer
(1 : UInt8)
view
TextView
title
UORust route table
heading
UORust route table
inputLabel
Rust fact kinds, one per line
submitLabel
Route
outputLabel
Route or refusal
inputError
Enter UTF-8 text of at most 512 bytes.
responseError
The answer could not be displayed.
cli
TextCli
command
route
description
UORust reads a Cargo workspace and writes a complete Prism model of it. This page runs UORust's route table, the verified function that decides which Prism record each kind of Rust fact becomes, or refuses the fact.
usageCode
(64 : UInt8)
ioCode
(74 : UInt8)
limitCode
(ctor Option.none [UInt8])
outcomes
  • TextCliOutcome
    name
    routed
    prefix
    route
    exitCode
    (0 : UInt8)
  • TextCliOutcome
    name
    refused
    prefix
    refused
    exitCode
    (1 : UInt8)
  • TextCliOutcome
    name
    error
    prefix
    error
    exitCode
    (2 : UInt8)
sections
  • TextCliSection
    title
    REQUEST
    body
    One kind of Rust fact per line, such as pub-fn, error-enum or unsafe-block. Every line must name the same route.
  • TextCliSection
    title
    ANSWER
    body
    route ID, fact KIND, record PRISM-RECORD, facet FACET the one route every kind names refused unknown-fact, fact KIND no route names the kind refused ambiguous, fact KIND, fact KIND two kinds name different routes error REASON the request is empty, too large, not UTF-8 or has a blank line
examples
  • TextCliExample
    name
    routed
    text
    error-enum
  • TextCliExample
    name
    ambiguous
    text
    error-enum state-enum
workbench
(ctor Option.some [Foundation.View.Text.V3.Model::WorkbenchView] (Guide::view))

Taught by Turn a Rust project into a Prism model, How UORust was modeled, Slides and video script

tutorialLearnMarkdown

Words on this page 9
facet
One view of a model, such as its architecture, its security or its quality. Each facet holds records.
record
One entry in a facet: a component, a threat, a measure or a journey step, with the place in the source it came from.
LexLean
The language Prism models are written in. It reads like LaTeX and compiles to Lean 4.
Lean kernel
The small checker at the heart of the Lean prover. It accepts a proof only if every step follows the rules.
theorem
A statement about the model that the Lean kernel has checked, so it holds for every input, not only the ones tested.
holo
The app Prism builds: one signed, verified file that a browser or a device runs.
SDK
Software development kit. Here, the PrismPM container image that builds, checks and verifies Prism models.
lift
To translate a Rust function into a LexLean definition with its proofs, so the model says what the code does.
stakeholder
A person or group with an interest in the system, as ISO/IEC/IEEE 42010 defines it.