Skip to content

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.

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 public Reply.audit strings
  • 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:

Terminal window
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:

Terminal window
tts sim --seeds=1..100 verified_escrow.ts
tts sim: PASS (100 seeds, 2500 turns, 398 misfits rejected, 0 violations)
  • 2,500 simulation turns executed deterministically across 100 seeds
  • 398 invalid/out-of-bounds transitions (misfits) rejected cleanly without violating invariant(state) (0 violations)

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:

  1. Spawn escrow1
    • Request: {"id":1,"op":"spawn","kind":"verified_escrow","name":"escrow1"}
    • Response: {"id":1,"ok":true}
  2. Deposit 50 with 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]"}}
  3. 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"}}
  4. Release 40 to settled
    • 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"}}
  5. Attempt over-refund of 50 (only 20 locked)
    • 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"}}
  6. 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"}}

On any machine with z3 installed (apt install z3 / brew install z3), run:

Terminal window
tts prove --cert=/tmp/escrow.cert.json --sarif=/tmp/escrow.sarif verified_escrow.ts

This 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.