WeftManual

Toolchain reference

Tools and diagnostics

Use the native compiler to build a component, check files already on disk, run event traces, inspect proof obligations, and measure dispatch. The commands below run from the extracted weft directory.

Install or build the toolchain

On Apple Silicon macOS, extract the binary distribution and change into the weft directory. It includes bin/weft, the native dependencies, browser assets, examples, and source. Start with a build to create or refresh the artifacts used by later commands.

bin/weft build examples/ballot.weft
bin/weft check examples/ballot.weft
Download the Apple Silicon distributionDownload the C source distribution

For a source build, install a C11 compiler, make, xxd, json-c, Z3 with C headers, and the Wasmtime C SDK. Linux builds also link libcrypto for SHA-256. Each PREFIX points to a directory containing include/ and lib/. Adjust the example paths to match your installation. The packaged binary targets macOS arm64.

make -j4 Z3_PREFIX=/usr WASMTIME_PREFIX=/opt/wasmtime JSON_PREFIX=/usr
bin/weft build examples/vault.weft
bin/weft run examples/vault.weft rotate=143 status

Command reference

bin/weft COMMAND FILE.weft [-o DIR] [arguments]
build FILE [-o DIR]
Parse, type-check, emit, and verify. The default output is build/<source stem>. The destination receives app.wasm, interface.json, and verification.json, plus the three browser assets for a component with a page.
check FILE [-o DIR]
Read the interface and module on disk, verify them against the source, check generated page assets when applicable, and compare the saved receipt. Use after copying a build or before admitting it to a host.
smt FILE [-o DIR]
Revalidate a saved build and write SMT-LIB queries on standard output. A separate Z3 command-line executable can replay them. Verify the weft command exits successfully before relying on the output.
run FILE [-o DIR] [ACTION[=VALUE] ...]
Recheck and execute the module in Wasmtime. Inputs are decimal and must fit the action width. The command prints the owner’s initial view and an event, view, and outbox row for each dispatch.
serve FILE [-o DIR] [--port N]
Recheck and serve a browser-owned component on loopback. The default port is 8080. Port 0 selects a free port. Run from the project root or set WEFT_ASSETS to the directory containing the browser support files.
bench FILE [-o DIR] [ACTION]
Recheck and run a native dispatch microbenchmark. An omitted action selects the first declared action. After warm-up it reports five samples of one million dispatches each. An action guard may disable later iterations, so choose a workload that measures the transition you intend.

The long spelling --out is equivalent to -o. All commands except build consume existing files from that destination. If you build with -o, pass the same directory to check, smt, run, serve, and bench.

bin/weft build examples/ballot.weft -o build/demo
bin/weft run examples/ballot.weft -o build/demo choose=3 annotate=2 review share
bin/weft serve examples/ballot.weft -o build/demo --port 0

Inspect and replay proofs

Open verification.json. Its format field is 1. The component and method fields identify the component and QF_BV / UNSAT method. The sha256 object identifies the source file, Wasm binary, and exact interface bytes. obligations lists the named successful checks. Individual names tell you which action, property, and recipient each result concerns.

bin/weft build examples/ballot.weft
bin/weft smt examples/ballot.weft > build/ballot/obligations.smt2
z3 build/ballot/obligations.smt2

Each query asks whether a counterexample exists. A successful replay prints unsat for every query. The release ballot has 70 obligations and the vault has 16. Each source change can alter the list. The receipt contains the obligation names and digests. To re-establish the result, run check with the matching toolchain and source.

Inspect the ballot receiptDownload the ballot’s replayable SMT-LIB queries

Interpret a failure

initial / NAME · induction / ACTION / NAME
Inspect the initializer or the named transition. For induction, the solver assumes the conjunction of all the claims in the pre-state. Each claim must still have a valid base case.
postcondition / ACTION / NAME
Examine the action guard and its pre-state writes. In ensures, plain fields refer to the next state. Compare a retained value to old(field).
channel policy / ACTION / PEER
The named step emitted to the peer under a disallowed action or pre-state. An emitted zero still occupies its slot.
noninterference / ACTION / PEER or FIELD from GROUP
Compare the two executions, conventionally marked s and t. Look for changes in public fields, observed payloads, or observed presence. A protect rule also requires equality for every other field.
domain · uniform coins · reconstruction
These obligations check result widths, the domain-preserving inverse of a randomness pairing, and reconstruction of an enabled split. Inspect source widths, recipient order, the split operand, and the trusted encodings when investigating a failure.
Wasm refinement / EXPORT · unsupported Wasm opcode
The saved module disagrees with the source for a legal input, or the checker cannot interpret its profile. Verify that the checked bytes are the intended release artifact.
interface differs from source · page artifact mismatch · verification receipt mismatch
Match the interface, page files, receipt, and source to the same build. Rebuild any intended source change and ship the complete artifact set together.
expected predicate · narrowing assignment · invalid view or guard reference
Use a u1 condition, a sufficiently wide destination, and an expression legal in that context. The syntax chapter lists the permitted references.
unresolved
The solver returned unknown or hit its configured 15-second query timeout. The check exits unsuccessfully. Simplify the relevant rule or encoding and rerun the proof.

A satisfiable query prints a witness. Names such as s.state.vote identify the compared pre-state field. s.event.choose.value is the corresponding payload. Bit-vector model values may be binary or hexadecimal. Interpret the model within the obligation’s assumptions. A disabled-state witness for an unrelated claim is a different problem from a failed enabled postcondition.

Measure the work you care about

Set WEFT_TIMING=1 to see frontend and verification times. make bench also measures in-memory parsing and code generation and native Wasmtime dispatch. make test runs regression cases, including deliberately invalid source and a valid Wasm module with the wrong semantics. The browser test requires Chromium and the ballot build.

WEFT_TIMING=1 bin/weft build examples/ballot.weft
bin/weft bench examples/ballot.weft choose
make test
make browser-test

Measure a browser click separately from a direct Wasm call. Entropy, DOM updates, network requests, and painting are different costs. The supplied benchmark report names the machine, workload, and sampling method.

Read performance measurements and methodology