WeftManual

Tutorial

Your first component

Build an approval button that can be pressed once. You’ll see the state change, prove the control follows that state, and get a counterexample when you deliberately break the implementation.

Write the latch

Save the following component as latch.weft. The downloadable version adds a page and styles to this same model. You can run that version in your browser before installing anything.

component "Approval latch" on browser
state approved: u1 = 0 public
view status "Approved" = approved

action approve "Approve" when not approved
  set approved = 1
  ensures locked = approved and not enabled(approve)
end

claim available = enabled(approve) == not shown(status)
Try the approval buttonDownload the complete latch.weft

The declaration on browser chooses the owner. The u1 field holds either 0 or 1. A view reads that field, and the guard permits approve while it is zero. The step writes 1. Its postcondition checks that the next state has approval set and a disabled control.

The claim connects two separately named parts of the interface. At every reachable state, the action is available exactly when the status view is zero.

Build, check, and run it

Extract the compiler download. Place latch.weft next to the bin directory and run these commands from that directory. The macOS download includes a native arm64 executable. The tools chapter covers building from source.

bin/weft build latch.weft
bin/weft check latch.weft
bin/weft run latch.weft approve approve
Initial view: [ 0, 1 ]
{"event":"approve","view":[1,0],"outbox":{}}
{"event":"approve","view":[1,0],"outbox":{}}

Read the first entry as the status view and the second as the enabled bit for approve. The second dispatch leaves both unchanged. A host can attempt a disabled action directly and the module still preserves the state.

Get the compiler

Break a postcondition

In a copy of the file, change the assignment inside approve from set approved = 1 to set approved = 0. Build the copy. The error names the transition and the promise it broke.

bin/weft build broken.weft
postcondition / approve / locked: counterexample
s.state.approved -> #b0

Read the witness as an enabled step beginning at approved = 0. The faulty assignment leaves it at 0, so approve stays enabled. The invariant about the display can still hold even though the transition fails its postcondition. Restore the assignment and build again.

Open the artifacts

The compiler puts this module in build/latch/. Open verification.json to see which obligations passed and which source, interface, and Wasm bytes the receipt identifies. For the version with a page, serve the output directory over HTTP with a static host that serves .wasm as application/wasm. The published copy includes the same assets.

Inspect the runnable example’s receipt