Capabilities and the host boundary
How Lema structures external interaction across Layer -1, Layer 0, and Layer 1's six flat-byte OS capability families while keeping TLS, HTTP, S3, and crash recovery inside proved Lema code.
In Anatomy of a Lema program, we saw that an interactive Lema program is a pure decision tree (Prog) of commands and replies. When that program runs on a real server, how does it open a TCP socket, write a 4 KiB disk sector, read the clock, or sign an HTTPS request without trusting a sprawling C or Rust runtime library?
In conventional application runtimes, the foreign-function boundary sits high up the stack: application code calls out to OpenSSL, rustls, libcurl, or OS filesystem helpers. That convenience carries a steep verification cost. Anything inside the foreign runtime sits outside the theorem prover’s reach, and passing complex pointer graphs across an FFI boundary invites memory bugs.
Following the verified-systems approach pioneered by seL4, CompCert, and Project Everest, Lema pushes the unverified host boundary down to flat byte frames over raw sockets, fixed 4096-byte disk blocks, clocks, random bytes, and sealed secret lookups. Everything above that line (binary codecs, copy-on-write block storage, cryptography, X.509 validation, TLS 1.3, HTTP/1.1, and AWS SigV4 signing) is written and proved inside Lema (The proved storage and HTTPS stack).
Escrow, S3d) checked Http1 framing & SigV4 signing checked Tls13, Noise & bounded X509 checked BlockStore checked LC\x02 byte frames Zero pointers 0x01 tcp 0x02 udp 0x03 block 0x04 random 0x05 clock 0x06 secret Pushing the host boundary down to flat byte frames brings block storage, cryptography, X.509, TLS 1.3, HTTP/1.1, and S3 inside kernel-checked Lema.
Three layers from pure logic to OS system calls
Rather than hardcoding cloud or POSIX calls into the compiler, Lema organizes external interaction into three layers:
-
Layer -1 · Hardware-agnostic core
Prog, Contract, Safe, Handles, Tickets
Pure mathematical interaction trees, protocol contracts, single-owner resource handles, in-flight ticket locks, and concurrency laws checked in the Lean kernel.
-
Layer 0 · Systems descriptor model
Domain, Region, Ring, Clock, Random
The low-level systems concepts for isolated memory domains, bounded byte regions, request/reply submission rings (Ring.call), timestamps, and OS entropy.
-
Layer 1 · Six flat-byte OS capabilities
tcp, udp, block, random, clock, secret (+ exchange & serve)
Self-contained binary request and reply frames executed by the Rust capability host, plus isolated sub-runs that keep raw secret bytes out of app code.
-
Above Layer 1 · Proved Lema libraries
BlockStore, Crypto, TLS 1.3, HTTP/1.1, S3
Crash-safe storage, RFC cryptography, authenticated transport, and applications written in Lema and checked against Layer 1 contracts.
Layer -1: Hardware-agnostic interaction
At the bottom sits the Prog and Contract core (Anatomy of a Lema program and Evolving programs, handles and concurrency). Because Prog C R A is parameterized over any command vocabulary (C, R), nothing in the language kernel assumes POSIX sockets or Von Neumann memory.
Layer 0: Isolated domains and request/reply rings
Layer 0 defines the five systems concepts needed to run isolated workloads on a physical host:
Domain: Isolated execution contexts with capped memory budgets so separate workers do not share mutable pointers.Region: Bounded byte buffers with generation-checked handles andbusylocks while an asynchronous I/O operation is in flight.Ring: Descriptor queues pairing request buffers with reply buffers, including the synchronous one-request/one-reply helperRing.call(ByteArrayrequest frame in,ByteArrayreply frame out).ClockandRandom: Monotonic and UTC timestamps plus cryptographic randomness from the host OS.
Layer 1: The six flat-byte host capability families
Over Ring.call, Lema defines six primitive host capability families that cover standard networking, storage, time, randomness, and credentials:
| Tag | Family | Operations | What crosses the boundary |
|---|---|---|---|
0x01 | tcp | connect, accept, send, recv, close | Bounded byte slices against allowlisted endpoint and listener IDs. |
0x02 | udp | sendTo, recvFrom | Bounded UDP datagrams (up to 65,507 bytes) over configured endpoints. |
0x03 | block | info, readBlock, writeBlock, flush | Fixed 4096-byte sector reads, writes, and fsync barriers on named volumes. |
0x04 | random | bytes | 1 to 4096 bytes per call from the host cryptographic RNG. |
0x05 | clock | utcMs, monoNs | UTC epoch milliseconds (for X.509/SigV4 windows) and monotonic nanoseconds. |
0x06 | secret | get | Role-gated lookup of versioned secret bundles inside verified sub-runs. |
Each family is opted into independently in an application’s execution manifest. A pure calculation tool names zero capability families; a local storage tool names only block and clock and has no link-time or runtime path to tcp, udp, or secret.
Flat binary frames and honest failure states
Pointers and heap graphs never cross the host boundary. Every Layer 1 call encodes a self-contained binary request frame (LC\x02) and receives a self-contained binary reply frame whose codecs are checked in the Lean kernel to round-trip without ambiguity and reject trailing or malformed bytes.
Just as importantly, the host never throws an untyped exception across the boundary. Every reply frame starts with an explicit status (ok, refused, failed, or malformed), and failed replies carry physical certainty flags right in the contract state:
- Uncertain disk writes (
DirtyUncertain): If awriteBlockorflushfails due to a timeout or device error, you cannot assume the sector stayed untouched. Theblockcontract marks that volumedirtyand refuses any further writes until aflushsucceeds orBlockStoreruns crash recovery from its alternating superblocks. - Uncertain network sends (
NotSentvs.Sent): Atcpsend failure reports whether zero bytes left the host (NotSent, safe for automatic retry) or bytes may have reached the peer (Sent), preserving retry safety all the way up through TLS 1.3 and HTTP/1.1.
Keeping raw secrets out of application code (exchange and serve)
How does an application sign an AWS S3 request or terminate TLS 1.3 with a private key without letting general application code read raw secret bytes (and accidentally log or leak them)?
Lema pairs the secret tag with two opaque driver sub-runs and mandatory static bytecode checks:
- Outbound requests (
exchange): Your application asks for asigned(SigV4) orbearerHTTPS exchange. Instead of handing secret bytes to your application, the VM runner executes the provedSecretExchangedriver in an isolated sub-run. The driver completes TLS 1.3, checks the server’s X.509 certificate against the secret bundle’s allowed origin, signs and sends the request, and returns only the HTTP response to your code. - Inbound servers (
serve): An HTTPS server issuesserveandrespond, while the isolatedServeVerifieddriver holds the server’s signing key, terminates TLS 1.3, verifies client signatures, and hands the application only authenticated request data. - Mandatory release gates: Any closure touching
secretmust pass staticConstantTime(no secret-dependent branches or memory indices) andSecretFlowchecks on its compiled VM IR beforelema run --releasewill start it (Checked, tested and assumed).
Next, read The proved storage and HTTPS stack (#8) to see how BlockStore, cryptography, TLS 1.3, HTTP/1.1, and S3 are built and proved on top of these six capabilities.
Lema v0.3.2 · Updated 29 October 2026 · Version and compatibility