Verified Escrow CLI Walkthrough
This walkthrough executes corpus/verified_escrow.ts (from trusted-ts tag v0.23.0) directly through the compiled tts binary with zero mocked output.
Program Highlights
Section titled “Program Highlights”verified_escrow.ts models an escrow state machine with:
- Nominal taint branding (
type Secret = string & { readonly __label?: "secret" }) +redactMemo(memo: Secret)so secret memos never leak into publicReply.auditstrings - Conservation invariant enforced transactionally across every turn:
export function invariant(state: State): boolean { return ( state.available >= 0 && state.locked >= 0 && state.settled >= 0 && state.txCount >= 0 && state.totalDeposited <= 1000000000 && state.txCount <= 1000000000 && state.available + state.locked + state.settled === state.totalDeposited );}1. Strict Type-Checking (tts check --json)
Section titled “1. Strict Type-Checking (tts check --json)”Running tts check --json verified_escrow.ts validates strict TypeScript subset compliance and outputs machine-readable JSON diagnostics:
tts check --json verified_escrow.ts{"ok":true,"diagnostics":[]}2. Deterministic Simulation (tts sim --seeds=1..100)
Section titled “2. Deterministic Simulation (tts sim --seeds=1..100)”tts sim drives fuzz-generated message sequences and invalid edge cases across 100 deterministic seeds inside the VM:
tts sim --seeds=1..100 verified_escrow.tstts sim: PASS (100 seeds, 2500 turns, 398 misfits rejected, 0 violations)2,500simulation turns executed deterministically across100seeds398invalid/out-of-bounds transitions (misfits) rejected cleanly without violatinginvariant(state)(0 violations)
3. Turn-by-Turn Actor Execution (tts run)
Section titled “3. Turn-by-Turn Actor Execution (tts run)”Streaming line-delimited JSON commands to tts run verified_escrow.ts spawns an isolated actor initialized at start (available: 100, totalDeposited: 100) and executes synchronous request/reply transitions:
- Spawn
escrow1- Request:
{"id":1,"op":"spawn","kind":"verified_escrow","name":"escrow1"} - Response:
{"id":1,"ok":true}
- Request:
- Deposit
50with secret memo ("secret-wire-ref")- Request:
{"id":2,"op":"send","to":"escrow1","msg":{"op":"deposit","amount":50,"memo":"secret-wire-ref"}} - Response:
{"id":2,"reply":{"ok":true,"available":150,"locked":0,"settled":0,"audit":"[redacted]"}}
- Request:
- Lock
60- Request:
{"id":3,"op":"send","to":"escrow1","msg":{"op":"lock","amount":60}} - Response:
{"id":3,"reply":{"ok":true,"available":90,"locked":60,"settled":0,"audit":"locked"}}
- Request:
- Release
40tosettled- Request:
{"id":4,"op":"send","to":"escrow1","msg":{"op":"release","amount":40}} - Response:
{"id":4,"reply":{"ok":true,"available":90,"locked":20,"settled":40,"audit":"released"}}
- Request:
- Attempt over-refund of
50(only20locked)- Request:
{"id":5,"op":"send","to":"escrow1","msg":{"op":"refund","amount":50}} - Response:
{"id":5,"reply":{"ok":false,"available":90,"locked":20,"settled":40,"audit":"rejected"}}
- Request:
- Inspect balances (
90 + 20 + 40 === 150)- Request:
{"id":6,"op":"send","to":"escrow1","msg":{"op":"inspect"}} - Response:
{"id":6,"reply":{"ok":true,"available":90,"locked":20,"settled":40,"audit":"inspect"}}
- Request:
4. Formal Z3 Obligation Proof (tts prove)
Section titled “4. Formal Z3 Obligation Proof (tts prove)”On any machine with z3 installed (apt install z3 / brew install z3), run:
tts prove --cert=/tmp/escrow.cert.json --sarif=/tmp/escrow.sarif verified_escrow.tsThis emits a machine-verifiable SHA-256 certificate (/tmp/escrow.cert.json) and SARIF 2.1.0 report (/tmp/escrow.sarif) alongside zero exit status when all obligations discharge.