Architecture & Security·3 min read·docs/formal-verification.md

Formal Verification (TLA+ / TLC)

6 exhaustive TLA+ formal specifications verified with TLC 2.19 across 1.93M states (Four-Eyes, Zero Auto-Enforce, PQ Fleet, Reverse RPC, Audit Chain).

Interactive Guide LabTLA+ / TLC 2.19 · 6 specs · 1.93M states verified
Visual Isometric WalkthroughInfrastructure & SRE Teams

Interactive Isometric Architecture Simulators

Post-Quantum Zero-Trust Onboarding & Outbound Reverse Live RPC

See how 1 to 10,000+ Linux servers join a hub with zero inbound ports and instant revocation.

Post-Quantum Fleet & Auth guide →
RING 3 · AI / PROCUntrusted user spaceRING 0 · eBPFTetragon v1.8.0PQ ZERO-TRUSTML-DSA-65 + HPKEHUB · CEL & MCPGraphs & 23 toolsHUMAN SEALSHA-256 audit chainSHA3-256 TOKEN ←
Step 1 of 5 · Token Mintinternal/adapter/httpapi/fleet_admin.go

Admin mints scoped enrollment token (stored as SHA3-256)

From /nodes -> Add node, an admin mints a single-use or unlimited (max_uses=0) cluster token. Only its SHA3-256 digest is persisted in SQLite migration 0027.

Developer invariant · Even full read access to the hub database cannot recover raw enrollment tokens, and active node_id collisions are rejected with 409 Conflict.
POST /api/v1/nodes/tokens response
{
  "metadata": { "cluster": "prod-eu", "max_uses": 0, "ttl": "168h" },
  "install_command":
    "curl -fsSL 'https://hub:7070/api/v1/fleet/install.sh?token=...' | sudo sh"
}

Ometsuke's security guarantees — zero automatic enforcement, two-person (Four-Eyes) cryptographic approval immutability, Post-Quantum single-use enrollment and key rotation, cross-node Reverse RPC isolation, and tamper-evident audit chains — are formally specified in TLA+ and exhaustively checked across every reachable concurrent interleaving using the TLC explicit-state model checker (tla2tools.jar v1.7.4 / TLC 2.19).

Unit tests check individual execution paths; TLC exhaustively explores all concurrent worker schedules, out-of-order and duplicated network messages, clock ticks, and active attacker replays, producing a minimal counterexample trace whenever any safety invariant or temporal liveness property can fail.

#Verified Specification Matrix (TLC 2.19)

SpecificationImplementation CoveredGenerated / Distinct StatesDepthSafety Invariants & Temporal Properties
specs/tla/FourEyesSeal.tlainternal/domain/seal/foureyes.go, internal/adapter/sqlite/seals.go34,922 / 8,44610NoSelfApproval, EnforceRequiresCryptoDualSeal, NoApprovalReplay, NoExpiredSeal, TerminalImmutability, AuditMonotonicity, liveness EventuallyResolved
specs/tla/ZeroAutoEnforce.tlainternal/app/fleet/rollout.go, internal/domain/decision/1,367,937 / 161,90411ZeroAutoEnforceInvariant under adversarial AI/MCP agents & reordering networks, DesiredEnforceRequiresHumanSeal, MonotonicPolicyRevision
specs/tla/PQFleetEnrollment.tlainternal/adapter/sqlite/fleet_pq.go, internal/app/fleet/299,130 / 53,36315SingleUseTokenEnforcement, NoAttackerHijack under leaked-token replay, RevokedNodeExcluded, NonceReplayIntegrity
specs/tla/AuditHashChain.tlainternal/domain/audit/, internal/adapter/httpapi/compliance_gitops.go84,767 / 33,90711UntamperedChainAlwaysValid, TamperAlwaysDetected, WORMNeverCertifiesTamperedChain
specs/tla/ReverseRPCBroker.tlainternal/app/fleet/broker.go, internal/adapter/fleethttp/rpc.go5,005 / 1,09810NoCrossNodeDelivery, SingleReplyPerCall, RevokedNodeNeverActive, CallResultImmutable, liveness EveryCallEventuallyTerminates
specs/tla/PQKeyRotation.tlainternal/adapter/sqlite/fleet_pq.go, internal/app/fleet/145,041 / 21,90419OnlyActiveKeyAccepted, RevokedHasNoActiveKey, RotatedCompromisedKeyRejected, RevocationPermanent, MonotonicRotation

Total exhaustively verified: 1,936,802 states generated, 280,622 distinct states, 0 invariant or temporal violations.

flowchart LR
  S["TLA+ Spec (6 Modules)"] --> TLC["TLC 2.19 Exhaustive BFS"]
  TLC -->|"1.93M states checked"| OK["0 Safety & Liveness Violations"]
  TLC -->|"Fault-injection / missing guard"| CE["Minimal Counterexample Trace"]
  CE --> FIX["Atomic SQLite CAS & Broker Binding"]
  FIX --> RACE["Go -race Regression Suite"]

#Real Bugs Caught by TLC Counterexamples

Formal modeling directly uncovered three real security and concurrency defects before production exposure, each confirmed via a minimal TLC counterexample trace and closed in Go with matching -race tests:

  1. Four-Eyes Seal TOCTOU overwrite (TerminalImmutability):
    • Counterexample: Worker 1 (bob, cosign) and Worker 2 (carol, reject) concurrently read the same pending_second_seal approval. Worker 1 sealed it; Worker 2 then executed UPDATE four_eyes_seals SET ... WHERE id = ? without guarding status, overwriting an already-sealed cryptographic approval.
    • Fix: Atomic SQLite Compare-And-Swap (WHERE id = ? AND status = 'pending_second_seal') in internal/adapter/sqlite/seals.go, returning errs.ErrConflict (HTTP 409) and verified by TestFourEyesApprovalAtomicCASPreventsConcurrentOverwrite.
  2. Cross-Node Reverse RPC Reply Spoofing (NoCrossNodeDelivery):
    • Counterexample: Hub dispatches RPC c1 to node-a. A compromised peer node-b learns c1 and submits a valid PQ-signed reply. Because Broker.DeliverReply originally routed solely by RequestID without checking pending.nodeID == reply.NodeID, node-b's forged payload was delivered to the caller awaiting node-a.
    • Fix: internal/app/fleet/broker.go now binds pendingCall{nodeID, ch} and strictly rejects replies whose authenticated NodeID does not match the target node (TestBrokerRejectsCrossNodeReplySpoofing).
  3. Single-Use PQ Enrollment Token Conditional Guard (SingleUseTokenEnforcement):
    • Fix: ConsumeEnrollmentAndStoreCred in internal/adapter/sqlite/fleet_pq.go enforces the atomic conditional update WHERE id = ? AND (max_uses = 0 OR uses_count < max_uses) AND revoked_at IS NULL AND expires_at > ? with RowsAffected() == 1 as database-level defense-in-depth.

#Reproducing Formal Verification Locally

Run all 6 specifications with one command from the repository root:

sh
./specs/tla/verify.sh

The script downloads the official tlaplus/tlaplus v1.7.4/tla2tools.jar into /tmp/tla, verifies its SHA-256 digest (936a262061c914694dfd669a543be24573c45d5aa0ff20a8b96b23d01e050e88), and runs TLC using either a local Java 21+ runtime or Docker eclipse-temurin:21-jre-alpine.

See Enterprise Governance, Fleet & Auth, and Security Policy for the runtime controls verified by these specifications.