. This repository accompanies the book chapter on formal verification of modern systems, demonstrating the application of TLA+ across various domains:
- IoT Systems
- Peer-to-Peer Networks
- Blockchain Technology
- Quantum Protocols
The example system models a smart grid infrastructure that integrates:
- Energy metering and anomaly detection at the edge
- P2P network for secure communication
- Blockchain for immutable audit trails
- Quantum teleportation for secure information transfer
The formal verification process follows this workflow:
The system is divided into four main TLA+ modules:
-
EnergyMeter.tla- Edge device anomaly detection
- State management and billing
- Safety properties for meter operation
-
P2PNetwork.tla- Secure peer-to-peer communication
- Message routing and delivery
- Network reliability properties
-
Blockchain.tla- Immutable event recording
- Smart contract execution
- Audit trail maintenance
-
QuantumTeleportation.tla- Secure quantum information transfer
- BB4P protocol implementation
- Quantum state integrity
Each TLA+ module follows this structure:
-------------------------------- MODULE ModuleName --------------------------------
EXTENDS Integers, Sequences, TLC, String, Nat
CONSTANTS YourConstants
VARIABLES YourVariables
Init ==
/\ YourInitialConditions
Next ==
YourNextStateRelation
Spec == Init \/ [][Next]_vars
=============================================================================-
Open TLA+ Toolbox
-
Create or open a specification:
- Go to File → New → Specification
- To verify a module, choose the module file
- Enter the exact module name
- Load the module and let the parser check it
-
Add all modules:
- Right-click on the specification
- Select "Add Module"
- Add:
- EnergyMeter.tla
- P2PNetwork.tla
- Blockchain.tla
- QuantumTeleportation.tla
-
Create models for each module:
- Right-click on each module
- Select "New Model Using Module"
- Name it appropriately (e.g., "EnergyMeter Model")
- Click "OK"
-
Configure each model:
- Click on the model in the left panel
- In the right panel, click "Model Overview"
- Set the following:
- "What is the behavior spec?" → "Spec"
- "What is the model checking task?" → "Check the temporal formula Spec"
- "What temporal properties should be checked?" → Add all properties from the .cfg files
- "What invariants should be checked?" → Add all invariants from the .cfg files
-
Run the verification:
- Click the "Run Model" button (green play icon)
- Wait for TLC to complete the verification
- Check the results in the "Model Checking Results" tab
-
If TLC runs out of memory:
- Increase the heap size in TLA+ Toolbox preferences
- Set a larger value for "Maximum heap size (MB)"
-
If state space is too large:
- Use the "Finite State Space" option in model configuration
- Limit the number of states to check
- Use symmetry reduction if applicable
- "No errors found" means all properties are satisfied
- "State space exhausted" means TLC couldn't explore all states
- "Counterexample found" indicates a property violation
- Check "Model Checking Results" for detailed information
- Use the "Step" feature to manually explore states
- Add "Print" statements in your specification
- Use "Debug" mode to pause at specific states
- Check TLC statistics for performance issues
- Use proper module headers and footers
- Document your constants and variables
- Use meaningful variable names
- Keep specifications modular and reusable
- Add comments for complex operations
- Use type annotations where possible
- Test with small models first
- Use TLC statistics to optimize performance
This repository includes a reusable empirical TLC workflow that can be applied to any subproject with TLA+ modules and .cfg files.
- Multi-scenario TLC execution from one command
- Three repeated runs per scenario by default
- Statistical timing report: mean, sample standard deviation, and 95% confidence interval
- CSV, JSON, console summary, and LaTeX output for paper integration
run_tlc_validation.sh: executes TLC scenarios and writesresults/tlc_results.csvanalyze_tlc_results.py: reads results and prints publication-ready summary tables
Run the default scenario suite:
cd /Users/tianxiang.lu/dev/formal-verification
./run_tlc_validation.sh
./analyze_tlc_results.pyRun with the high-scale stress test (~1M states):
RUN_MILLION_SCALE=1 ./run_tlc_validation.sh
./analyze_tlc_results.pyThe runner is parameterized through environment variables, so it can be reused across subprojects without changing script code.
MODULE_DIR=/path/to/subproject/tla_modules \
MODULE_NAME=YourMainModule \
TLA_JAR_PATH=/path/to/tla2tools.jar \
RESULTS_DIR=/path/to/output/results \
SCENARIOS="S1:Config1.cfg;S2:Config2.cfg;S3:Config3.cfg" \
RUNS_PER_SCENARIO=3 \
./run_tlc_validation.sh
RESULTS_DIR=/path/to/output/results ./analyze_tlc_results.pySet SCENARIOS as a semicolon-separated list of ScenarioName:ConfigFile pairs:
SCENARIOS="Baseline:MainCheck_Strict.cfg;Relaxed:MainCheck_NoUniqueness.cfg"TotalStatesandDistinctStatesquantify explored state spaceMeanWallTime(ms)is mean wall-clock runtime over repeated runsCI95HalfWidth(ms)is the 95% confidence interval half-width for runtimeViolationsFound=Yesindicates property/invariant violations were detected
- Report
mean ± 95% CIinstead of single-run time to improve statistical rigor - Include the largest-state scenario as the scalability stress test
- Keep per-scenario logs from
results/logs/for reproducibility
Run everything:
./run_tlc_validation.sh && ./analyze_tlc_results.pyRun one or more specific scenarios:
SCENARIOS="StrictOnly:MainCheck_Strict.cfg" ./run_tlc_validation.shRun with the million-scale scenario (if MainCheck_MillionScale.cfg exists):
RUN_MILLION_SCALE=1 ./run_tlc_validation.shRun with the breakdown witness scenario (requires refinement witness module):
MODULE_NAME=MainCheckRefinementWitness RUN_BREAKDOWN_WITNESS=1 ./run_tlc_validation.shInspect results:
cat results/tlc_results.csv | column -t -s,
ls -lt results/logs/Analyze a custom CSV location:
./analyze_tlc_results.py /path/to/results/tlc_results.csv| Scenario | Config file | Intent |
|---|---|---|
| Strict | MainCheck_Strict.cfg |
Baseline with full consistency checks |
| No Uniqueness | MainCheck_NoUniqueness.cfg |
Relax uniqueness assumption |
| Medium Scale | MainCheck_MediumScale.cfg |
Measure state-space/runtime growth |
| Minimal Constraints | MainCheck_MinimalConstraints.cfg |
Baseline type-focused validation |
| Million Scale | MainCheck_MillionScale.cfg |
Stress-test scalability (>1,000,000 states) |
java: command not found: install Java and verifyjava -version.ClassNotFoundException: tlc2.TLC: ensureTLA_JAR_PATHpoints totla2tools.jar.- Unexpected failures in one scenario: inspect matching file in
results/logs/. - Runtime too long: reduce config cardinalities or set lower
TLC_STOP_AFTER_SECONDS. - No rows in analysis: ensure
results/tlc_results.csvexists and has scenario data.
Include these with paper submission when possible:
results/tlc_results.csvresults/tlc_results.jsonresults/logs/*tla_modules/MainCheck_*.cfg- Core specs used in validation (
*.tla)
- Type safety across all modules
- Anomaly detection and response
- Secure message delivery
- Immutable audit trails
- Quantum state preservation
tla_modules/- Main TLA+ specification modulestla_modules/tlc_configs/- TLC model configuration filesworkflow/- System architecture diagrams
git clone https://github.com/yourusername/formal-verification.git- Create a new specification in the
specsdirectory - Add model checking configurations in the
modelsdirectory - Document your findings in the
docsdirectory
This software is licensed for NON-COMMERCIAL use only. For commercial use, please contact prof.dr.rer.nat.lu@gmail.com.
For more details, see the LICENSE file.
This repository accompanies the following research contribution:
- Lu, T. (2026). Formal Verification in Modern Technologies: Safety Assurance for P2P, IoT, Blockchain, and Quantum Computing. Technologie und Organisation. Springer Gabler, 2026. Camera-ready
@book{lu2026formal,
author = {Lu, Tianxiang},
title = {Formal Verification in Modern Technologies: Safety Assurance for P2P, IoT, Blockchain, and Quantum Computing},
series = {Technologie und Organisation},
year = {2026},
publisher = {Springer Gabler},
note = {Camera-ready}
}