Runtime reference
WebAssembly and hosts
The native compiler emits one small module per component. You can run it in any host that supports the accepted Wasm instructions, i32 values, and multi-value results. The same checked bytes drive the browser and the native Wasmtime host.
What translation validation proves
First Wasmtime validates the module as WebAssembly. A separate decoder reads its type, function, export, and code sections and checks that they fit Weft’s profile. It checks the function count, export names and signatures, and the end of each byte range. It symbolically executes every function body using the meanings of its actual instructions.
init(h) = the source initial state for h
view(s) = all source views and guards at s
step_NAME(s,v,r) = the source next state and every recipient slotThe verifier checks these equalities on every typed input, including states unreachable from the declared initializer. A bit-vector query asks whether any returned field differs. If the answer is unsatisfiable, all legal inputs agree. Because the host carries the complete next state, these per-call checks compose across a sequence of dispatches.
Changing an emitted XOR to OR can leave the binary valid WebAssembly while corrupting share reconstruction. The regression suite exercises that case. The decoder reports Wasm refinement / step_share with a counterexample when the results diverge. A fresh proof is performed for each submitted artifact.
Accepted Wasm profile
- Sections and effects
- Only type, function, export, and code sections in the expected order. Every function has a declared export. Modules with imports, tables, memory, globals, a start section, or additional sections are rejected.
- Straight-line instructions
- i32.const, local.get, local.set for the scratch slot, i32.eqz, i32.eq, i32.ne, i32.lt_u, i32.le_u, i32.gt_u, i32.ge_u, i32.and, i32.or, i32.xor, select, and end.
- Locals and control
- Each function may declare one zero-initialized i32 scratch local. Parameters can be read. The scratch local can be read and written. Branches, calls, loops, and hidden mutable state are outside the accepted profile.
A standard Wasm optimization pass may introduce an instruction or a custom section outside this profile. Run check against the final bytes that will ship. A byte change can also require a new matching receipt.
Call the ABI v1 exports
- init(external₀, …) → fields…
- Pass only the external field values, in field declaration order. The result contains every field in declaration order, including constants.
- view(fields…) → views…, enabled…
- Pass the entire state. Read view values in view declaration order, followed by one 0 or 1 guard result for each action in action declaration order.
- step_NAME(fields…, [payload], [mask]) → fields…, slots…
- Supply the full state, then the payload if the action declares one, then the mask if it uses split. Results are the complete next state followed by one slot per observer in observer declaration order.
All parameters and results use i32. One return value is a scalar in JavaScript. Multiple results use the engine’s multi-value convention. Check that all state, payload, external, and mask values fit the widths in the component contract. The absent-slot bit pattern is 0xffffffff, exposed as −1 in the included hosts. Every value from 0 through 255 can be a real message.
// Exact calls for the tutorial latch, in a JavaScript Wasm host
const { instance } = await WebAssembly.instantiateStreaming(fetch('./app.wasm'), {});
const api = instance.exports;
let approved = api.init(); // 0 (one field)
api.view(approved); // [0, 1] (view, enabled)
approved = api.step_approve(approved); // 1 (no recipient slots)
api.view(approved); // [1, 0]Inspect the latch module’s interfaceRead interface.json
- abi, title, owner
- The ABI version is 1. title is the component label. owner identifies the intended principal.
- peers, external, stateCount
- peers lists recipient names in slot order. external lists just the widths of external initializers in call order. stateCount is the number of fields, used to split step results into state and outbox.
- views
- An array of display labels in view-result order. The compiled page uses numeric binding indices.
- actions
- An ordered array of objects with name, label, inputBits, and randomBits. A zero width means the corresponding argument is omitted. name supplies the suffix for the step_ export.
The manifest omits a complete field-name and width table. A custom host uses the source contract for field widths, obtains its first state from init, and retains subsequent state directly from verified step results.
The host’s part of the contract
Choose an instance location consistent with owner. Source external values there. Route a recipient only its own present slots. Generate fresh independent uniform masks of the specified width. Keep the state and action arguments in their typed domains, and store the returned state before the next dispatch.
The assurance relies on the parser and type checker, the source semantics and obligation generator, the binary decoder and symbolic instruction semantics, and Z3. At execution it also relies on the Wasm engine and the host’s implementation of placement, rendering, entropy, and transport. A receipt identifies a checked build. Replaying the queries tests the generated mathematics. Auditing whether that mathematics captures your intent requires reviewing the source specification too.
Read the formal semantics