# Weft semantics and verification The source semantics and proof obligations are implemented in C. The compiler emitter and binary validator are separate modules. [Source semantics](native/proof.c) · [WASM validator](native/validate.c) Verification uses quantifier-free, 32-bit bit-vector formulas. Free variables range over all legal values, including states that examples or tests might never exercise. ## Components A field of type `uN` has domain `{0, …, 2ᴺ−1}`. A state σ is a tuple of fields in declaration order. An initializer either supplies a constant or accepts a typed value from the owner. The expression evaluator interprets bitwise operations pointwise, comparisons as unsigned, and Boolean values as 0 or 1. Expressions are pure and total. A view V(σ) is the tuple of declared view values followed by the truth value of each action guard. For a fixed action a, payload v and random mask r, evaluation produces a new state and an ordered tuple of recipient messages: ```text step(a, σ, v, r) = (σ′, messages) ``` When the guard is false, σ′ equals σ and every message is absent. Otherwise each assigned field takes the value of its right-hand side in (σ, v). Other fields retain their values. Sending places the evaluated expression in the named recipient's slot. Splitting a w-bit value x sends r to the first recipient and x XOR r to the second, with r uniform over w bits. All other slots are absent. A recipient can distinguish absence from every payload, including zero. ## Behavioral obligations Let I be the conjunction of declared claims. For every allowed external initializer h, verification requires I(init(h)). For every typed state satisfying I, each action preserves I for all legal inputs and masks. This proves invariance for arbitrarily many steps by induction. Each enabled action must also satisfy its declared postconditions. A channel policy requires that every nonempty message to that channel originates in the named action with the declared precondition true. These are safety properties. An assertion about a view or enabled control expands to the same source definition that determines the runtime view. Progress, user satisfaction, screen layout and delivery are separate properties. ## Information flow and observers By default each observer can see all public state fields and the contents or absence of messages addressed to it. The owner has access to its own state, views and complete outbox. Event identities, order and public inputs are treated as known. Compare two runs with the same public event schedule and public inputs. Private payloads may differ. For each observer, the verifier proves equal distributions of complete observation histories for any finite number of steps. The proof uses a one-step *unwinding* argument. Start two executions in equivalent states. For every allowed pair of inputs, the verifier constructs a bijection between the fresh coins in the two runs. Under paired coins, their observable messages agree and their next states remain equivalent. A bijection preserves the uniform distribution. Induction couples the entire history, including the occurrence or absence of each observed message. For the first share recipient, the coupling uses the same mask in both runs. For the second, it uses r′ = r XOR x XOR x′, so x XOR r equals x′ XOR r′. Z3 checks that the mapping preserves the mask domain, is its own inverse, and makes the observations agree. Reconstruction is a separate check requiring left XOR right to equal x whenever the split executes. A field-specific `protect` rule compares the **joint** observations of its listed recipients. Its state relation fixes every field other than the protected field. Only the specified input action may vary its payload. The verifier checks that this relation holds initially and is preserved at every step. This conservative rule can reject a secure program that copies a secret into a second private field. The default per-observer relation instead allows all private fields to differ. In the ballot, the two recipients together may recover the vote, while their joint transcript is independent of confidence when the vote and other inputs are held fixed. These are statements about information conveyed by the modeled program. Prior knowledge, correlations in user choices, the user's choice of *which* action to take, external scripts, network timing, resource consumption, failures and host-side channels are outside the observation model. The proof requires fresh independent uniform masks for repeated splits. The adapters obtain masks from the operating system or browser cryptographic random source. An operator controlling both recipients can read both shares. ## Translation validation For each artifact, the validator first runs standard Wasmtime module validation. It independently decodes the actual type, function, export, and code sections. The accepted profile includes i32 constants, parameter reads, unsigned comparisons, equality, bitwise operations, select and end. Each function may declare one zero-initialized i32 scratch local, with reads and writes accounted for in symbolic execution. This allows the compiler to evaluate a shared guard once. The validator admits flat stack programs with the declared exports. It rejects imports, memory, globals, calls, branches, tables, a start function, extra sections, hidden functions and additional locals. This makes every accepted function total and free of hidden state or effects. The validator symbolically executes each decoded body according to its Wasm stack semantics. Each typed input is a fresh bit-vector of its declared width, zero-extended to i32. This covers every legal input exactly once and keeps irrelevant high bits out of the search. The validator checks each function signature and the following equalities. ```text ∀ typed host initializers h. wasm.init(h) = source.init(h) ∀ typed states σ. wasm.view(σ) = V(σ) ∀ typed σ, v, r. wasm.step_a(σ, v, r) = step(a, σ, v, r) ``` Comparison includes every state field, view binding, enabled flag and recipient slot. A mismatch is a satisfiable formula with a concrete witness. Since the ABI returns the complete next state, function refinement composes by induction across dispatches. This is a per-artifact translation-validation result. A universal once-for-all correctness theorem about the compiler implementation would be a separate deliverable. [WebAssembly Core instruction semantics](https://webassembly.github.io/spec/core/exec/instructions.html) ## Host ABI v1 All exports use i32 parameters and results. A single result is a scalar and multiple results follow the standard Wasm multi-value convention. Hosts must supply inputs within the widths in the verified interface. | Export | Parameters | Results | | --- | --- | --- | | `init` | External field values in declaration order | All fields in declaration order | | `view` | All fields | View values, then one enabled flag per action | | `step_NAME` | All fields, optional event payload, optional fresh mask | Next fields, then one output per peer in declaration order | An absent output is the i32 bit pattern 0xffffffff, surfaced as −1 by the included hosts. All valid payloads are unsigned and fit in eight bits. State is carried by the host between calls. Initialization inputs, state and the full outbox are available to the owning host. A server-owned component and its external initializer belong at the server. Each recipient receives only the output in its assigned slot. The browser demo uses separate processes as inboxes. Its delivery status concerns HTTP acknowledgments, while the proved sealed state means that shares have been prepared. ## Trusted boundary The parser/type checker, source semantic encoding, obligation generator, Wasm decoder and symbolic instruction definitions, and Z3 form the verification base. The compiler backend can be faulty and still cannot pass a checked build if its output disagrees semantically on a legal input. Interface labels and ABI order come from the same parsed source. Each receipt binds the source, interface and binary by digest. Replaying exported SMT-LIB checks the generated mathematics. Auditing whether those formulas capture the intended language still requires inspecting the encodings. Running the artifact additionally trusts the Wasm engine, owner placement, input validation, entropy, rendering and transport adapters, and host environment. The browser host uses a fixed JavaScript DOM and Web Crypto adapter. The headless host uses Wasmtime. The C host validates the binary and ABI before caching its functions and using the raw i32 call interface. Its source and memory safety are part of the trusted base. The language and per-artifact certificates concern component behavior. Timing, including any compiler optimization that affects it, is outside the confidentiality model.