WeftManual

Design

Language design

A Weft component is a finite state machine owned by one principal. Given the same state, action, input, and random mask, its next state and recipient outputs are fixed. That design gives the verifier something precise to compare with the emitted WebAssembly.

Draw the ownership boundary

Start by naming who holds the complete state. In the ballot, the browser owns the vote. In the vault, a server owns the key and the browser is an observer. The owner sees its fields, views, action inputs, and complete outbox. Each observer has its own slot in that outbox.

component "Vault status" on vault
observer browser
state key: u8 = external private
state online: u1 = 1 public

The component header records an intended placement. Deployment gives it effect. Run the vault at its owner and supply the real key there. Copying a Wasm file with a literal secret into a frontend bundle would distribute the literal with the program. An external initializer lets the value enter at the owning host.

A public field is part of every observer’s modeled knowledge. A private field can appear in an owner’s view. Choose the owner before deciding whose knowledge a claim should constrain.

Follow one transition

owner supplies initializers → init → state
state → view → displayed values and enabled flags
state + event + optional payload and mask → step → next state + outbox

The host carries the state between calls. The Wasm module has no persistent memory of its own. A view computes values from the current state without effects. Each guard is also a pure expression over the current state, so the host can ask which actions are enabled before a user clicks.

An enabled step evaluates all assignments and messages against the same pre-state. Fields without an assignment carry forward. A disabled step returns the original state and an absent message in every slot. Its effect is defined even if a host invokes it directly.

action swap "Swap" when true
  set left = right
  set right = left
end

For fields initially holding 1 and 2, one swap returns 2 and 1. Order within the action cannot turn both fields into 2.

Why bounded values and explicit effects?

Every field and payload occupies one to eight bits. There is no recursion, unbounded heap, or user-defined loop in a component. A verifier can encode a complete step as bit-vector equations. Multiple dispatches can still run indefinitely because invariants compose across steps.

A message has a named recipient, and a split has an explicit random input at the ABI. Network access, DOM access, and randomness acquisition occur at the host. This keeps the set of values and effects to be checked small enough to inspect.

Use a host to handle transport or durable storage. If its decisions affect a guarantee, introduce a corresponding modeled input or state transition and state the host assumption. A sealed ballot records that shares were prepared. An acknowledgment would require its own input and transition.

What runs when

At build time
The native C11 frontend parses and type-checks the program, emits Wasm, builds source obligations, and runs a separate decoder and symbolic evaluator on those emitted bytes. Z3 checks for counterexamples.
At admission
The check command re-reads a saved build, reconstructs the interface and obligations, and checks the source against the bytes on disk. A receipt identifies the exact source, interface, and module.
At runtime
The browser adapter or native Wasmtime host instantiates the module and holds its state. Dispatch calls a precompiled Wasm export. Each click uses the guard and next-state logic already checked at build time.
Inspect the exact ABI and verification boundary