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-spec3description: 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).4---56# Formal Spec78## Purpose9Extract properties from a system design, define state variables, write TLA+ specifications, identify invariants, configure the TLC model checker, and document assumptions and limitations.1011## Scope Constraints1213Reads system designs, protocol descriptions, and existing specifications. Produces TLA+ specification files as output. Does not execute model checkers or modify implementation code.1415## Inputs16- System design or protocol description to formalize17- Security properties that should hold (informally stated)18- Concurrency model (number of processes, shared state, communication mechanism)19- Scope constraints (bounded checking parameters)20- Existing informal specification or documentation2122## Input Sanitization2324No user-provided values are used in commands or file paths. All inputs are treated as read-only analysis targets.2526## Procedure2728### Progress Checklist29- [ ] Step 1: Extract properties from design30- [ ] Step 2: Define state variables31- [ ] Step 3: Write TLA+ specification32- [ ] Step 4: Identify invariants33- [ ] Step 5: Configure model checker34- [ ] Step 6: Document assumptions and limitations3536### Step 1: Extract Properties from Design37Translate informal requirements into candidate formal properties:38- **Safety properties**: "Bad thing never happens" — e.g., "No two processes hold the lock simultaneously"39- **Liveness properties**: "Good thing eventually happens" — e.g., "Every request eventually gets a response"40- **Security properties**: "Unauthorized access never occurs" — e.g., "A process at EL0 never reads EL1 memory"41- Classify each property as safety (invariant) or liveness (temporal)42- Identify the state variables each property depends on4344### Step 2: Define State Variables45Define the formal state space:46- Enumerate all state variables (process states, shared variables, message channels)47- Define the type/domain of each variable48- Specify the initial state (Init predicate)49- Identify which variables are shared vs. local to each process50- Define the granularity of state transitions (atomic actions)5152### Step 3: Write TLA+ Specification53Produce a TLA+ module:54- **Module declaration** with EXTENDS (Integers, Sequences, FiniteSets, TLC)55- **Constants** for parameterizable bounds (NUM_PROCESSES, MAX_VALUE, etc.)56- **Variables** with type invariant57- **Init** predicate defining initial state58- **Next** predicate as disjunction of all possible actions59- **Actions** as individual state transitions with enabling conditions and effects60- **Fairness** conditions if liveness properties require them6162### Step 4: Identify Invariants63Define the key invariants to check:64- Type invariant (state variables stay within their domains)65- Safety invariants (extracted from Step 1)66- Security invariants (access control, information flow, integrity)67- Structural invariants (data structure consistency)68- Express each invariant as a TLA+ state predicate6970### Step 5: Configure Model Checker71Set up TLC model checking configuration:72- Define model constants (specific values for CONSTANTS)73- Set state constraint (bound the state space for feasibility)74- Select invariants and temporal properties to check75- Configure symmetry sets to reduce state space76- Estimate state space size and checking time77- Document what the bounded check covers and what it does not7879### Step 6: Document Assumptions and Limitations80Explicitly state:81- Environmental assumptions (fair scheduling, reliable channels, bounded processes)82- Abstraction choices (what was simplified or omitted from the model)83- Bounded verification limits (the check covers N=3 processes, not N=arbitrary)84- What a successful check guarantees and what it does not85- Recommendations for increasing confidence (larger bounds, different abstractions, proof)8687> **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.8889## Output Format9091### Property Table9293| ID | Property | Type | TLA+ Expression | Status |94|----|----------|------|-----------------|--------|95| S1 | Mutual exclusion | Safety | `MutualExclusion == \A p1, p2 \in Procs: ...` | Verified (N<=5) |96| L1 | Starvation freedom | Liveness | `\A p \in Procs: []<>(state[p] = "done")` | Requires fairness |97| ... | ... | ... | ... | ... |9899### TLA+ Specification100```tla101---- MODULE [Name] ----102EXTENDS Integers, Sequences, FiniteSets, TLC103104CONSTANTS NUM_PROCS105106VARIABLES state, shared107108vars == <<state, shared>>109110TypeInvariant == ...111112Init == ...113114Action1(p) == ...115116Next == \E p \in 1..NUM_PROCS: Action1(p) \/ ...117118Spec == Init /\ [][Next]_vars /\ Fairness119120====121```122123### Model Checking Configuration124- Constants: NUM_PROCS = 3125- State constraint: [Bound description]126- Invariants checked: [List]127- Estimated states: [N]128- Estimated time: [T]129130### Assumptions and Limitations131- [Assumption 1]: [Justification]132- [Limitation 1]: [What is not covered]133134## Handoff135136- Hand off to invariant-analysis if additional security claims need enumeration before specification.137- Hand off to the requesting department for implementation of verified properties.138139## Quality Checks140- [ ] All informal security properties formalized as TLA+ predicates141- [ ] State variables fully defined with types and initial values142- [ ] Actions cover all possible state transitions143- [ ] Invariants include both type invariant and security invariants144- [ ] Model checker configured with reasonable bounds145- [ ] State space is feasible to check (or bounds are documented)146- [ ] Assumptions and limitations are explicitly documented147- [ ] Fairness conditions specified if liveness properties are checked148149## Evolution Notes150<!-- Observations appended after each use -->