Formal Spec
Purpose
Extract properties from a system design, define state variables, write TLA+ specifications, identify invariants, configure the TLC model checker, and document assumptions and limitations.
Scope Constraints
Reads system designs, protocol descriptions, and existing specifications. Produces TLA+ specification files as output. Does not execute model checkers or modify implementation code.
Inputs
- System design or protocol description to formalize
- Security properties that should hold (informally stated)
- Concurrency model (number of processes, shared state, communication mechanism)
- Scope constraints (bounded checking parameters)
- Existing informal specification or documentation
Input Sanitization
No user-provided values are used in commands or file paths. All inputs are treated as read-only analysis targets.
Procedure
Progress Checklist
Step 1: Extract Properties from Design
Translate informal requirements into candidate formal properties:
- Safety properties: "Bad thing never happens" — e.g., "No two processes hold the lock simultaneously"
- Liveness properties: "Good thing eventually happens" — e.g., "Every request eventually gets a response"
- Security properties: "Unauthorized access never occurs" — e.g., "A process at EL0 never reads EL1 memory"
- Classify each property as safety (invariant) or liveness (temporal)
- Identify the state variables each property depends on
Step 2: Define State Variables
Define the formal state space:
- Enumerate all state variables (process states, shared variables, message channels)
- Define the type/domain of each variable
- Specify the initial state (Init predicate)
- Identify which variables are shared vs. local to each process
- Define the granularity of state transitions (atomic actions)
Step 3: Write TLA+ Specification
Produce a TLA+ module:
- Module declaration with EXTENDS (Integers, Sequences, FiniteSets, TLC)
- Constants for parameterizable bounds (NUM_PROCESSES, MAX_VALUE, etc.)
- Variables with type invariant
- Init predicate defining initial state
- Next predicate as disjunction of all possible actions
- Actions as individual state transitions with enabling conditions and effects
- Fairness conditions if liveness properties require them
Step 4: Identify Invariants
Define the key invariants to check:
- Type invariant (state variables stay within their domains)
- Safety invariants (extracted from Step 1)
- Security invariants (access control, information flow, integrity)
- Structural invariants (data structure consistency)
- Express each invariant as a TLA+ state predicate
Step 5: Configure Model Checker
Set up TLC model checking configuration:
- Define model constants (specific values for CONSTANTS)
- Set state constraint (bound the state space for feasibility)
- Select invariants and temporal properties to check
- Configure symmetry sets to reduce state space
- Estimate state space size and checking time
- Document what the bounded check covers and what it does not
Step 6: Document Assumptions and Limitations
Explicitly state:
- Environmental assumptions (fair scheduling, reliable channels, bounded processes)
- Abstraction choices (what was simplified or omitted from the model)
- Bounded verification limits (the check covers N=3 processes, not N=arbitrary)
- What a successful check guarantees and what it does not
- Recommendations for increasing confidence (larger bounds, different abstractions, proof)
Compaction resilience: If context was lost during a long session, re-read the Inputs section to reconstruct what system is being analyzed, check the Progress Checklist for completed steps, then resume from the earliest incomplete step.
Output Format
Property Table
| ID |
Property |
Type |
TLA+ Expression |
Status |
| S1 |
Mutual exclusion |
Safety |
MutualExclusion == \A p1, p2 \in Procs: ... |
Verified (N<=5) |
| L1 |
Starvation freedom |
Liveness |
\A p \in Procs: []<>(state[p] = "done") |
Requires fairness |
| ... |
... |
... |
... |
... |
TLA+ Specification
---- MODULE [Name] ----
EXTENDS Integers, Sequences, FiniteSets, TLC
CONSTANTS NUM_PROCS
VARIABLES state, shared
vars == <<state, shared>>
TypeInvariant == ...
Init == ...
Action1(p) == ...
Next == \E p \in 1..NUM_PROCS: Action1(p) \/ ...
Spec == Init /\ [][Next]_vars /\ Fairness
====
Model Checking Configuration
- Constants: NUM_PROCS = 3
- State constraint: [Bound description]
- Invariants checked: [List]
- Estimated states: [N]
- Estimated time: [T]
Assumptions and Limitations
- [Limitation 1]: [What is not covered]
Handoff
- Hand off to invariant-analysis if additional security claims need enumeration before specification.
- Hand off to the requesting department for implementation of verified properties.
Quality Checks
Evolution Notes
1---2name: formal-spec3department: "prover"4description: "Use when writing formal specifications in TLA+ to verify system properties, defining state variables, configuring TLC model checker, and documenting assumptions and limitations. Covers safety and liveness properties for protocols and concurrent systems. Do not use for security claim enumeration without specification intent (use invariant-analysis)."5version: 16triggers:7 - "formal"8 - "TLA+"9 - "PlusCal"10 - "specification"11 - "model checking"12 - "temporal logic"13 - "state machine"14 - "safety property"15 - "liveness"16 - "refinement"17---1819# Formal Spec2021## Purpose22Extract properties from a system design, define state variables, write TLA+ specifications, identify invariants, configure the TLC model checker, and document assumptions and limitations.2324## Scope Constraints2526Reads system designs, protocol descriptions, and existing specifications. Produces TLA+ specification files as output. Does not execute model checkers or modify implementation code.2728## Inputs29- System design or protocol description to formalize30- Security properties that should hold (informally stated)31- Concurrency model (number of processes, shared state, communication mechanism)32- Scope constraints (bounded checking parameters)33- Existing informal specification or documentation3435## Input Sanitization3637No user-provided values are used in commands or file paths. All inputs are treated as read-only analysis targets.3839## Procedure4041### Progress Checklist42- [ ] Step 1: Extract properties from design43- [ ] Step 2: Define state variables44- [ ] Step 3: Write TLA+ specification45- [ ] Step 4: Identify invariants46- [ ] Step 5: Configure model checker47- [ ] Step 6: Document assumptions and limitations4849### Step 1: Extract Properties from Design50Translate informal requirements into candidate formal properties:51- **Safety properties**: "Bad thing never happens" — e.g., "No two processes hold the lock simultaneously"52- **Liveness properties**: "Good thing eventually happens" — e.g., "Every request eventually gets a response"53- **Security properties**: "Unauthorized access never occurs" — e.g., "A process at EL0 never reads EL1 memory"54- Classify each property as safety (invariant) or liveness (temporal)55- Identify the state variables each property depends on5657### Step 2: Define State Variables58Define the formal state space:59- Enumerate all state variables (process states, shared variables, message channels)60- Define the type/domain of each variable61- Specify the initial state (Init predicate)62- Identify which variables are shared vs. local to each process63- Define the granularity of state transitions (atomic actions)6465### Step 3: Write TLA+ Specification66Produce a TLA+ module:67- **Module declaration** with EXTENDS (Integers, Sequences, FiniteSets, TLC)68- **Constants** for parameterizable bounds (NUM_PROCESSES, MAX_VALUE, etc.)69- **Variables** with type invariant70- **Init** predicate defining initial state71- **Next** predicate as disjunction of all possible actions72- **Actions** as individual state transitions with enabling conditions and effects73- **Fairness** conditions if liveness properties require them7475### Step 4: Identify Invariants76Define the key invariants to check:77- Type invariant (state variables stay within their domains)78- Safety invariants (extracted from Step 1)79- Security invariants (access control, information flow, integrity)80- Structural invariants (data structure consistency)81- Express each invariant as a TLA+ state predicate8283### Step 5: Configure Model Checker84Set up TLC model checking configuration:85- Define model constants (specific values for CONSTANTS)86- Set state constraint (bound the state space for feasibility)87- Select invariants and temporal properties to check88- Configure symmetry sets to reduce state space89- Estimate state space size and checking time90- Document what the bounded check covers and what it does not9192### Step 6: Document Assumptions and Limitations93Explicitly state:94- Environmental assumptions (fair scheduling, reliable channels, bounded processes)95- Abstraction choices (what was simplified or omitted from the model)96- Bounded verification limits (the check covers N=3 processes, not N=arbitrary)97- What a successful check guarantees and what it does not98- Recommendations for increasing confidence (larger bounds, different abstractions, proof)99100> **Compaction resilience**: If context was lost during a long session, re-read the Inputs section to reconstruct what system is being analyzed, check the Progress Checklist for completed steps, then resume from the earliest incomplete step.101102## Output Format103104### Property Table105106| ID | Property | Type | TLA+ Expression | Status |107|----|----------|------|-----------------|--------|108| S1 | Mutual exclusion | Safety | `MutualExclusion == \A p1, p2 \in Procs: ...` | Verified (N<=5) |109| L1 | Starvation freedom | Liveness | `\A p \in Procs: []<>(state[p] = "done")` | Requires fairness |110| ... | ... | ... | ... | ... |111112### TLA+ Specification113```tla114---- MODULE [Name] ----115EXTENDS Integers, Sequences, FiniteSets, TLC116117CONSTANTS NUM_PROCS118119VARIABLES state, shared120121vars == <<state, shared>>122123TypeInvariant == ...124125Init == ...126127Action1(p) == ...128129Next == \E p \in 1..NUM_PROCS: Action1(p) \/ ...130131Spec == Init /\ [][Next]_vars /\ Fairness132133====134```135136### Model Checking Configuration137- Constants: NUM_PROCS = 3138- State constraint: [Bound description]139- Invariants checked: [List]140- Estimated states: [N]141- Estimated time: [T]142143### Assumptions and Limitations144- [Assumption 1]: [Justification]145- [Limitation 1]: [What is not covered]146147## Handoff148149- Hand off to invariant-analysis if additional security claims need enumeration before specification.150- Hand off to the requesting department for implementation of verified properties.151152## Quality Checks153- [ ] All informal security properties formalized as TLA+ predicates154- [ ] State variables fully defined with types and initial values155- [ ] Actions cover all possible state transitions156- [ ] Invariants include both type invariant and security invariants157- [ ] Model checker configured with reasonable bounds158- [ ] State space is feasible to check (or bounds are documented)159- [ ] Assumptions and limitations are explicitly documented160- [ ] Fairness conditions specified if liveness properties are checked161162## Evolution Notes163<!-- Observations appended after each use -->