Invariant Analysis
Purpose
Enumerate security claims made by a design, formalize them as invariants, check for hidden assumptions, assess verification feasibility, and propose a specification approach for proving or disproving the claims.
Scope Constraints
Reads system designs, security documentation, and existing formal specifications. Does not modify implementation code or execute verification tools. Does not access production systems for testing.
Inputs
- System design with stated or implied security claims
- Threat model defining attacker capabilities
- Architecture documentation describing components and interactions
- Existing tests or verification results
- Constraints on verification effort (time, tools, expertise)
Input Sanitization
No user-provided values are used in commands or file paths. All inputs are treated as read-only analysis targets.
Procedure
Step 1: Enumerate Security Claims
Extract all security claims from the design, whether explicit or implicit:
- Explicit claims: Stated in documentation ("the system ensures mutual exclusion")
- Implicit claims: Assumed but not stated ("processes always terminate")
- Derived claims: Inferred from the design ("if A holds and B holds, then C should hold")
- For each claim, identify who makes it, what components it depends on, and what could violate it
Step 2: Formalize as Invariants
For each security claim, produce a formal invariant:
- Express the claim as a precise predicate over system state
- Classify as safety invariant (must hold in every reachable state) or temporal property
- Identify the state variables the invariant references
- Determine if the invariant is inductive (preserved by every action) or requires auxiliary lemmas
- Note invariants that cannot be expressed as simple state predicates (information flow, probabilistic)
Step 3: Check for Hidden Assumptions
For each invariant, enumerate the assumptions required for it to hold:
- Environmental: "The network eventually delivers messages" — is this guaranteed?
- Implementation: "The RNG produces uniform random output" — has this been verified?
- Threat model: "The attacker cannot read kernel memory" — what if they can (Meltdown)?
- Timing: "Operations complete within T milliseconds" — is this a hard guarantee?
- Classify assumptions by verifiability: axiom (accepted), verifiable (can be checked), unverified (risk)
Step 4: Assess Verification Feasibility
For each invariant, evaluate whether formal verification is practical:
- State space: How many states does the system have? Is bounded model checking feasible?
- Decidability: Is the property decidable for the system class? (Finite state? Parameterized? Infinite?)
- Tool support: Do existing tools (TLC, Spin, CBMC, Dafny) support this verification?
- Abstraction: Can the system be abstracted to make verification tractable without losing the property?
- Effort: How much effort (person-days) would verification require?
Step 5: Propose Specification Approach
Recommend a verification strategy for the highest-priority invariants:
- Full formal verification: TLA+/TLC for protocol properties, Dafny/Coq for implementation
- Bounded model checking: TLC or CBMC for bounded instances
- Property-based testing: QuickCheck/Hypothesis as a lightweight alternative
- Runtime monitoring: Instrument invariants as runtime assertions for production
- For each approach, state what it guarantees and what it does not
Compaction resilience: If context was lost during a long session, re-read the Inputs section to reconstruct what system is being analyzed, then resume from the earliest incomplete step.
Output Format
Security Claims Inventory
| ID |
Claim |
Type |
Source |
Formalized |
Assumptions |
| I1 |
"No unauthorized memory access" |
Safety |
Design doc 3.2 |
\A p: access[p] => authorized[p] |
MMU enabled, no HW bugs |
| I2 |
"All requests eventually complete" |
Liveness |
Implicit |
\A r: []<>(status[r] = "done") |
Fair scheduling, no deadlock |
| ... |
... |
... |
... |
... |
... |
Hidden Assumption Analysis
| Invariant |
Assumption |
Category |
Verifiable? |
Risk if Violated |
| I1 |
MMU correctly configured |
Implementation |
Yes — audit kernel config |
Critical — full bypass |
| I2 |
No circular wait |
Design |
Yes — deadlock analysis |
High — livelock |
| ... |
... |
... |
... |
... |
Verification Feasibility Matrix
| Invariant |
State Space |
Tool |
Approach |
Effort |
Confidence |
| I1 |
~10^6 (bounded) |
TLC |
Model checking, N<=4 |
3 days |
High (bounded) |
| I2 |
Infinite |
— |
Runtime monitoring |
1 day |
Medium |
| ... |
... |
... |
... |
... |
... |
Recommended Verification Strategy
- [Highest priority invariant]: [Approach] — [Justification]
- [Next priority]: [Approach] — [Justification]
- ...
Handoff
- Hand off to formal-spec if high-priority invariants should be formally specified in TLA+.
- Hand off to the requesting department for implementation of the recommended verification approach.
Quality Checks
Evolution Notes
1---2name: invariant-analysis3department: "prover"4description: "Use when enumerating security claims from a design, formalizing them as invariants, checking for hidden assumptions, and assessing verification feasibility. Covers safety invariants, temporal properties, and verification tool recommendations. Do not use for writing TLA+ specifications directly (use formal-spec) or implementation-level security review."5version: 16triggers:7 - "invariant"8 - "property"9 - "safety"10 - "liveness"11 - "correctness"12 - "proof"13 - "assumption"14 - "verification"15 - "security claim"16 - "guarantee"17---1819# Invariant Analysis2021## Purpose22Enumerate security claims made by a design, formalize them as invariants, check for hidden assumptions, assess verification feasibility, and propose a specification approach for proving or disproving the claims.2324## Scope Constraints2526Reads system designs, security documentation, and existing formal specifications. Does not modify implementation code or execute verification tools. Does not access production systems for testing.2728## Inputs29- System design with stated or implied security claims30- Threat model defining attacker capabilities31- Architecture documentation describing components and interactions32- Existing tests or verification results33- Constraints on verification effort (time, tools, expertise)3435## Input Sanitization3637No user-provided values are used in commands or file paths. All inputs are treated as read-only analysis targets.3839## Procedure4041### Step 1: Enumerate Security Claims42Extract all security claims from the design, whether explicit or implicit:43- **Explicit claims**: Stated in documentation ("the system ensures mutual exclusion")44- **Implicit claims**: Assumed but not stated ("processes always terminate")45- **Derived claims**: Inferred from the design ("if A holds and B holds, then C should hold")46- For each claim, identify who makes it, what components it depends on, and what could violate it4748### Step 2: Formalize as Invariants49For each security claim, produce a formal invariant:50- Express the claim as a precise predicate over system state51- Classify as safety invariant (must hold in every reachable state) or temporal property52- Identify the state variables the invariant references53- Determine if the invariant is inductive (preserved by every action) or requires auxiliary lemmas54- Note invariants that cannot be expressed as simple state predicates (information flow, probabilistic)5556### Step 3: Check for Hidden Assumptions57For each invariant, enumerate the assumptions required for it to hold:58- **Environmental**: "The network eventually delivers messages" — is this guaranteed?59- **Implementation**: "The RNG produces uniform random output" — has this been verified?60- **Threat model**: "The attacker cannot read kernel memory" — what if they can (Meltdown)?61- **Timing**: "Operations complete within T milliseconds" — is this a hard guarantee?62- Classify assumptions by verifiability: axiom (accepted), verifiable (can be checked), unverified (risk)6364### Step 4: Assess Verification Feasibility65For each invariant, evaluate whether formal verification is practical:66- **State space**: How many states does the system have? Is bounded model checking feasible?67- **Decidability**: Is the property decidable for the system class? (Finite state? Parameterized? Infinite?)68- **Tool support**: Do existing tools (TLC, Spin, CBMC, Dafny) support this verification?69- **Abstraction**: Can the system be abstracted to make verification tractable without losing the property?70- **Effort**: How much effort (person-days) would verification require?7172### Step 5: Propose Specification Approach73Recommend a verification strategy for the highest-priority invariants:74- **Full formal verification**: TLA+/TLC for protocol properties, Dafny/Coq for implementation75- **Bounded model checking**: TLC or CBMC for bounded instances76- **Property-based testing**: QuickCheck/Hypothesis as a lightweight alternative77- **Runtime monitoring**: Instrument invariants as runtime assertions for production78- For each approach, state what it guarantees and what it does not7980> **Compaction resilience**: If context was lost during a long session, re-read the Inputs section to reconstruct what system is being analyzed, then resume from the earliest incomplete step.8182## Output Format8384### Security Claims Inventory8586| ID | Claim | Type | Source | Formalized | Assumptions |87|----|-------|------|--------|------------|-------------|88| I1 | "No unauthorized memory access" | Safety | Design doc 3.2 | `\A p: access[p] => authorized[p]` | MMU enabled, no HW bugs |89| I2 | "All requests eventually complete" | Liveness | Implicit | `\A r: []<>(status[r] = "done")` | Fair scheduling, no deadlock |90| ... | ... | ... | ... | ... | ... |9192### Hidden Assumption Analysis9394| Invariant | Assumption | Category | Verifiable? | Risk if Violated |95|-----------|-----------|----------|-------------|------------------|96| I1 | MMU correctly configured | Implementation | Yes — audit kernel config | Critical — full bypass |97| I2 | No circular wait | Design | Yes — deadlock analysis | High — livelock |98| ... | ... | ... | ... | ... |99100### Verification Feasibility Matrix101102| Invariant | State Space | Tool | Approach | Effort | Confidence |103|-----------|------------|------|----------|--------|------------|104| I1 | ~10^6 (bounded) | TLC | Model checking, N<=4 | 3 days | High (bounded) |105| I2 | Infinite | — | Runtime monitoring | 1 day | Medium |106| ... | ... | ... | ... | ... | ... |107108### Recommended Verification Strategy1091. [Highest priority invariant]: [Approach] — [Justification]1102. [Next priority]: [Approach] — [Justification]1113. ...112113## Handoff114115- Hand off to formal-spec if high-priority invariants should be formally specified in TLA+.116- Hand off to the requesting department for implementation of the recommended verification approach.117118## Quality Checks119- [ ] All explicit and implicit security claims enumerated120- [ ] Each claim formalized as a precise predicate121- [ ] Hidden assumptions identified and classified by verifiability122- [ ] Verification feasibility assessed with state space estimates123- [ ] Tool recommendations match the invariant class (safety/liveness/information flow)124- [ ] Verification effort estimated realistically125- [ ] Approach recommendations include both guarantees and limitations126127## Evolution Notes128<!-- Observations appended after each use -->