Skip to content
Edit this page

Formal Verification and Wire Codecs

Wind uses Verus to statically prove critical protocol state machines, routing compiler equivalence, GeoIP/GeoSite lookups, and relay invariants, alongside Vest to generate checked binary wire codecs from declarative schemas.

See Runtime State Machines for how these verified components interact on live connections.

TUIC

Component Source Verified behavior Runtime scope & assumptions
TUIC v5 codec & Vest schema wind-tuic/src/wire/codec.rs
wind-tuic/src/wire/tuic.vest
Every successfully encoded frame parses back to the identical command body consuming exactly the written bytes, covering all 5 commands, 4 address forms, and length-delimited UDP payloads The stream adapter feeds bytes; for Connect, it reads only the address so trailing TCP bytes remain on the stream
Native UDP sender & datagram planner wind-tuic/src/proto/udp_stream.rs
wind-tuic/src/udp/send_plan.rs
plan_datagrams selects single-datagram, fragmentation, or rejection; every fragment fits with its header; IDs run 0..total - 1 with only fragment 0 carrying the destination; ordered slices partition the original payload exactly Sender supplies both header sizes and the sampled datagram limit; if the initial header fills the limit exactly, empty payload succeeds in 1 packet while non-empty is rejected; up to 255 fragments allowed, 256th fails
Reassembly buffer, slots & eviction wind-tuic/src/udp/runtime.rs
wind-tuic/src/udp/slots.rs
wind-tuic/src/udp/eviction.rs
Duplicates overwrite their slot without decrementing the missing count; complete groups join slots in ID order; after expiry or capacity eviction, reusing the key starts empty Lifecycle proof keys on (assoc_id, pkt_id); cleanup removes groups at or past lifetime; capacity eviction removes the least recently updated group (ties broken by traversal order)
Sender-to-receiver round trip wind-tuic/src/udp/lifecycle/roundtrip.rs Receiving all IDs from one successful plan recovers original bytes and destination in any arrival order, including duplicates and continuation fragments arriving before fragment 0 Starts from a fresh group; all arrivals through completion belong to that plan and the group survives until delivery
Server authentication wind-tuic/src/server/authentication.rs Admits at most 3 attempts per connection; applies outcomes in admission order; publishes at most one identity on success; closing prevents late outcomes from publishing wind-tuic/src/server/mod.rs feeds credential outcomes and disconnect events
Client heartbeat & reconnect policy wind-tuic/src/client/session/policy.rs Heartbeat enters Lost if and only if send history holds 3 consecutive failures (any success clears the streak); supervisor reconnects only when lost, reconnect is enabled, and shutdown is unobserved wind-tuic/src/client/session.rs feeds send outcomes, end reasons, and shutdown snapshots for both Quinn and Quiche
Client UDP association IDs wind-tuic/src/client/association/slots.rs From any starting ID, a full scan visits every 16-bit ID exactly once; registration preserves occupied slots; cleanup removes only the owning stream even after ID reuse Association table applies transitions under Moka's single-key atomic compute contract

Routing and GeoData

Component Source Verified behavior Runtime scope & assumptions
TCP consistent-hash selection wind-base/src/load_balance/ring.rs Starts at the first ring position >= hash (first on ties), wraps at end, selects the first healthy owner or falls back to the starting owner after a full turn; on a fixed ring with stable health, failing one proxy only affects targets previously mapped to it Load balancer supplies a non-empty position-sorted ring with valid proxy indices and reads health per visited virtual node
Private-address classifier wind-core/src/utils/private_ip.rs IPv4 matches exactly RFC 1918, link-local, and CGNAT; IPv4-mapped IPv6 mirrors IPv4; other IPv6 matches only unique-local (fc00::/7) and link-local (fe80::/10) Rust supplies address bits; wind-acl uses this for drop_private and checks drop_loopback separately
ACL port verdict maps wind-acl/src/port_map.rs Folding eligible rules with pairwise-disjoint ranges on one port field preserves matched verdicts and fallthrough on miss; failed folds report candidate starts the compiler can safely skip Optimizer consumes the skip count; regression tests separately verify candidate-check counts
ACL named-set folding & match eval wind-acl/src/bucket.rs
wind-acl/src/matches.rs
Grouping eligible domain, IP, and port leaves with identical verdict preserves their disjunction; scalar and set evaluation agree; opaque predicates retain short-circuit order Runtime evaluator supplies connection fields, leaf predicate results, and legacy callback effects
ACL compiler, interpreter & equivalence wind-acl/src/optimize.rs
wind-acl/src/routing.rs
wind-acl/src/route_equivalence.rs
Compiling a ruleset preserves the routing decision (outbound or rejection reason) and final legacy callback state across jumps, tail calls, returns, chain exhaustion, entry policy, and the 64-level chain limit Assumes valid entry, valid set references, and finite map lookups; interpreter also bounds map traversal by table length and rejects invalid indices and cycles
GeoIP CIDR conversion wind-geodata/src/ranges/intervals.rs Closed interval contains exactly the addresses sharing the prefix; prefix 0 covers the full family; prefix >= address width selects only the input address Builder supplies decoded IPv4/IPv6 address and raw prefix length
GeoIP range merging & membership wind-geodata/src/ranges/intervals.rs Merging preserves membership and produces sorted, disjoint, coalesced closed intervals for IPv4 and IPv6; binary search agrees with linear scan (including endpoints) on validated slices Builder merges ranges; query path supplies validated archive slices and decoded endpoints
GeoSite & GeoIP name lookup wind-geodata/src/query/search.rs Binary search finds an index iff the sorted category/country/domain slice contains the name; suffix match matches exact domain or subdomain after an ASCII dot; slice validation distinguishes offset overflow from out-of-bounds ends Archive adapter reads offsets, validates ordering, and supplies Rust string comparisons

Transport

Component Source Verified behavior Runtime scope & assumptions
TCP relay direction wind-core/src/io/direction.rs Acknowledged writes form a prefix of bytes read; short writes retain the exact unwritten suffix; shutdown starts only after EOF and flushing the last buffered byte; counters wrap modulo usize::MAX + 1; Ok reports progress iff bytes moved, EOF first observed, or shutdown finished Underlying stream supplies poll results; bidirectional relay uses progress for wakeups and half-close timer resets
TCP half-close idle timer wind-core/src/io/half_close.rs Zero timeout disables the timer; otherwise first EOF arms it; each check polls readiness once; progress renews the deadline before polling even if previously elapsed, else keeps the existing deadline Bidirectional relay supplies EOF and progress flags; Tokio provides clock and timer readiness
Naive UoT v2 codec & Vest schema wind-naive/src/uot/codec.rs
wind-naive/src/uot/wire.vest
Requests and datagrams use their distinct address tags; decoding an encoded datagram recovers destination, port, and payload while consuming exactly one frame even with arbitrary trailing bytes Stream adapter handles I/O and converts between wire fields and Wind addresses
SOCKS wire format wind-socks/src/socks.vest Vest generates parsers and serializers checked against the binary schema Stream adapter feeds frame bytes, reads NUL-terminated SOCKS4 strings, and converts targets outside proofs
SOCKS5 UDP source admission wind-socks/src/udp/source.rs Preset or first observed client IP is pinned even if the first frame is malformed; IPv4 matches its IPv4-mapped IPv6 form; rejected frames keep the reply endpoint; accepted frames update it or clear it for port 0 UDP relay supplies peer address and parse result; admission requires authorized source, valid parse, FRAG == 0, and payload within limit

Running the Verifier Locally

From the wind repository root, using the Rust toolchain and Verus release pinned in .github/workflows/verus.yml (CI runs once each for x86_64-unknown-linux-gnu and i686-unknown-linux-gnu):

cargo verus verify --locked \
  -p wind-tuic -p wind-geodata -p wind-acl -p wind-naive \
  -p wind-socks -p wind-core -p wind-base \
  --no-default-features --fwd-verus-args-to roots -- --no-cheating

Update VERSU.md, the CI workflow, and this page whenever a verified crate or production invariant changes.