Spaces:
Sleeping
Sleeping
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,13 +1,193 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
colorFrom: blue
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
python_version: '3.13'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: EBSysMLSec-Py LLM HAZOP Analyzer
|
| 3 |
+
emoji: π
|
| 4 |
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# EBSysMLSec-Py: Formal Safety-Security Analysis with LLM-Assisted HAZOP
|
| 13 |
+
|
| 14 |
+
A Python reimplementation of the **EBSysMLSec** model transformation pipeline
|
| 15 |
+
(Poorhadi & Troubitsyna, SAFECOMP 2024), applied to a new domain and extended
|
| 16 |
+
with LLM-assisted HAZOP threat analysis.
|
| 17 |
+
|
| 18 |
+
**Domain:** Autonomous Insulin Pump Controller (medical safety-critical system)
|
| 19 |
+
**Original domain:** Railway moving-block signalling (CBTC)
|
| 20 |
+
**Contribution:** Python translator + LLM-assisted HAZOP β neither present in the original ATL/Eclipse toolchain
|
| 21 |
+
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
## What this project does
|
| 25 |
+
|
| 26 |
+
The original EBSysMLSec tool (written in ATL β ATLAS Transformation Language) takes
|
| 27 |
+
a SysML model of a safety-critical system and automatically generates Event-B machines
|
| 28 |
+
and contexts that can be formally verified in the Rodin prover. Security attacks are
|
| 29 |
+
injected as Event-B events; failing proof obligations show which safety invariants are
|
| 30 |
+
violated under attack.
|
| 31 |
+
|
| 32 |
+
This project reproduces that pipeline in Python and extends it:
|
| 33 |
+
|
| 34 |
+
```
|
| 35 |
+
sysml/insulin_pump.xmi
|
| 36 |
+
β
|
| 37 |
+
βΌ
|
| 38 |
+
translator/sysml_to_eventb.py β Python reimplementation of EBSysMLSec ATL rules
|
| 39 |
+
β
|
| 40 |
+
βββΆ eventb/InsulinPump.buc β Event-B context (sets, constants, axioms)
|
| 41 |
+
βββΆ eventb/InsulinPump.bum β Event-B machine (normal operation)
|
| 42 |
+
βββΆ eventb/attacks/Attack_Spoofing.bum β Attack A: sensor spoofing
|
| 43 |
+
βββΆ eventb/attacks/Attack_Injection.bum β Attack B: command injection
|
| 44 |
+
βββΆ eventb/attacks/Attack_Replay.bum β Attack C: replay attack
|
| 45 |
+
β
|
| 46 |
+
βΌ
|
| 47 |
+
hazop/hazop_analyzer.py β LLM-assisted HAZOP via Anthropic API [NEW]
|
| 48 |
+
β
|
| 49 |
+
βΌ
|
| 50 |
+
hazop/threats.json β 18 structured threat scenarios
|
| 51 |
+
β
|
| 52 |
+
βΌ
|
| 53 |
+
verification/proof_results.md β which Rodin POs hold / fail per attack
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
---
|
| 57 |
+
|
| 58 |
+
## System: Autonomous Insulin Pump Controller
|
| 59 |
+
|
| 60 |
+
Six SysML blocks connected by five information flows:
|
| 61 |
+
|
| 62 |
+
```
|
| 63 |
+
PatientProfile ββF2βββΆ DoseCalculator ββF3βββΆ SafetyMonitor ββF4βββΆ PumpActuator
|
| 64 |
+
β²
|
| 65 |
+
GlucoseSensor ββF1βββββββββββββ
|
| 66 |
+
NetworkInterface ββF5βββΆ DoseCalculator β attack surface
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
### Safety invariants (Event-B)
|
| 70 |
+
|
| 71 |
+
| Label | Predicate | Protection |
|
| 72 |
+
|---|---|---|
|
| 73 |
+
| **INV1** | `delivered_dose β€ MAX_SAFE_DOSE` | Overdose prevention |
|
| 74 |
+
| **INV2** | `delivered_dose > 0 β glucose_reading β₯ HYPO_THRESHOLD` | Hypoglycaemia protection |
|
| 75 |
+
| **INV3** | `delivered_dose > 0 β battery_level β₯ MIN_BATTERY_LEVEL` | Power safety |
|
| 76 |
+
| **INV4** | `delivered_dose > 0 β command_approved = TRUE` | Authorisation gate |
|
| 77 |
+
| **INV5** | `dose_request β€ MAX_SAFE_DOSE` | Calculator output bound |
|
| 78 |
+
|
| 79 |
+
### Attack scenarios and violated invariants
|
| 80 |
+
|
| 81 |
+
| Attack | HAZOP guide word | Flow | Violated | Event-B machine |
|
| 82 |
+
|---|---|---|---|---|
|
| 83 |
+
| A: Sensor spoofing | MORE on F1 | GlucoseSensor β DoseCalculator | **INV2** | `Attack_Spoofing.bum` |
|
| 84 |
+
| B: Command injection | AS WELL AS on F5 | NetworkInterface β DoseCalculator | **INV4** | `Attack_Injection.bum` |
|
| 85 |
+
| C: Replay attack | OTHER THAN on F5 | NetworkInterface β DoseCalculator | **INV1** | `Attack_Replay.bum` |
|
| 86 |
+
|
| 87 |
+
---
|
| 88 |
+
|
| 89 |
+
## Running the pipeline
|
| 90 |
+
|
| 91 |
+
```bash
|
| 92 |
+
pip install -r requirements.txt
|
| 93 |
+
|
| 94 |
+
# Full pipeline (Event-B generation + LLM HAZOP)
|
| 95 |
+
export ANTHROPIC_API_KEY=sk-ant-...
|
| 96 |
+
python run_pipeline.py
|
| 97 |
+
|
| 98 |
+
# Event-B generation only (no API key needed)
|
| 99 |
+
python run_pipeline.py --skip-hazop
|
| 100 |
+
|
| 101 |
+
# Gradio demo (uses pre-generated threats by default)
|
| 102 |
+
python app.py
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
---
|
| 106 |
+
|
| 107 |
+
## Verifying in Rodin
|
| 108 |
+
|
| 109 |
+
1. Download [Rodin Platform 3.7](http://www.event-b.org/install.html)
|
| 110 |
+
2. Install the [Camille plugin](https://wiki.event-b.org/index.php/Camille) (textual Event-B import)
|
| 111 |
+
3. Create a new Event-B project in Rodin
|
| 112 |
+
4. Add a new Context: paste content of `eventb/InsulinPump.buc`
|
| 113 |
+
5. Add a new Machine: paste content of `eventb/InsulinPump.bum` β Run Provers β **all POs discharge**
|
| 114 |
+
6. Add attack machines from `eventb/attacks/` β Run Provers β **specific POs fail**
|
| 115 |
+
|
| 116 |
+
Expected results per `verification/proof_results.md`:
|
| 117 |
+
|
| 118 |
+
| Machine | INV1 | INV2 | INV3 | INV4 | INV5 |
|
| 119 |
+
|---|---|---|---|---|---|
|
| 120 |
+
| Normal | β | β | β | β | β |
|
| 121 |
+
| + Spoofing | β | **β** | β | β | β |
|
| 122 |
+
| + Injection | β | β | β | **β** | β |
|
| 123 |
+
| + Replay | **β** | β | β | β | β |
|
| 124 |
+
|
| 125 |
+
β Rodin proof obligation discharged Β· **β** Proof obligation fails = invariant violated under attack
|
| 126 |
+
|
| 127 |
+
---
|
| 128 |
+
|
| 129 |
+
## LLM-Assisted HAZOP: the AI contribution
|
| 130 |
+
|
| 131 |
+
In the original Poorhadi & Troubitsyna papers, the HAZOP analysis is **manual** β a domain expert applies the seven guide words to each flow by hand. This project automates that step using Claude:
|
| 132 |
+
|
| 133 |
+
```python
|
| 134 |
+
from hazop.hazop_analyzer import analyze_system, INSULIN_PUMP_MODEL
|
| 135 |
+
|
| 136 |
+
threats = analyze_system(INSULIN_PUMP_MODEL)
|
| 137 |
+
# β list of 18 structured threat dicts, each linked to an Event-B attack event
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
The LLM receives the system model (blocks, flows, invariants) and applies HAZOP guide words systematically to produce the same structured threat table a human analyst would β but for any system, in seconds.
|
| 141 |
+
|
| 142 |
+
This is a direct demonstration of the PhD position's research question:
|
| 143 |
+
> *"how formally specified safety constraints can be derived using AI"*
|
| 144 |
+
|
| 145 |
+
---
|
| 146 |
+
|
| 147 |
+
## Repository structure
|
| 148 |
+
|
| 149 |
+
```
|
| 150 |
+
insulin-pump-formal/
|
| 151 |
+
βββ sysml/
|
| 152 |
+
β βββ insulin_pump.xmi SysML/XMI model (NCS style)
|
| 153 |
+
βββ translator/
|
| 154 |
+
β βββ sysml_to_eventb.py Python SysML β Event-B translator
|
| 155 |
+
βββ eventb/
|
| 156 |
+
β βββ InsulinPump.buc Event-B context
|
| 157 |
+
β βββ InsulinPump.bum Event-B machine (normal operation)
|
| 158 |
+
β βββ attacks/
|
| 159 |
+
β βββ Attack_Spoofing.bum Attack A: INV2 violated
|
| 160 |
+
β βββ Attack_Injection.bum Attack B: INV4 violated
|
| 161 |
+
β βββ Attack_Replay.bum Attack C: INV1 violated
|
| 162 |
+
βββ hazop/
|
| 163 |
+
β βββ hazop_analyzer.py LLM-assisted HAZOP (Anthropic API)
|
| 164 |
+
β βββ threats.json Pre-generated threat analysis
|
| 165 |
+
βββ verification/
|
| 166 |
+
β βββ proof_results.md Proof obligation results per scenario
|
| 167 |
+
βββ app.py Gradio demo (HF Spaces)
|
| 168 |
+
βββ run_pipeline.py Full pipeline entry point
|
| 169 |
+
βββ requirements.txt
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
---
|
| 173 |
+
|
| 174 |
+
## References
|
| 175 |
+
|
| 176 |
+
1. Poorhadi, E., Troubitsyna, E., DΓ‘n, G. (2022). *Analysing the Impact of Security Attacks on Safety Using SysML and Event-B.* IMBSA 2022. DOI: 10.1007/978-3-031-15842-1_13
|
| 177 |
+
2. Poorhadi, E., Troubitsyna, E. (2023). *Automating an Analysis of Safety-Security Interactions for Railway Systems.* RSSRail 2023. DOI: 10.1007/978-3-031-43366-5_1
|
| 178 |
+
3. Poorhadi, E., Troubitsyna, E. (2024). *Automating an Integrated Model-Driven Approach to Analysing the Impact of Cyberattacks on Safety.* SAFECOMP 2024. DOI: 10.1007/978-3-031-68738-9_5
|
| 179 |
+
4. Troubitsyna, E. (2024). *Formal Analysis of Interactions Between Safety and Security Requirements.* In: The Practice of Formal Methods. DOI: 10.1007/978-3-031-66673-5_8
|
| 180 |
+
5. Abrial, J.R. (2010). *Modeling in Event-B.* Cambridge University Press.
|
| 181 |
+
|
| 182 |
+
---
|
| 183 |
+
|
| 184 |
+
## What makes this original
|
| 185 |
+
|
| 186 |
+
| Aspect | Original EBSysMLSec | This project |
|
| 187 |
+
|---|---|---|
|
| 188 |
+
| Transformation language | ATL (Eclipse/EMF) | Python |
|
| 189 |
+
| Domain | Railway (CBTC moving block) | Medical device (insulin pump) |
|
| 190 |
+
| HAZOP | Manual | LLM-assisted (new contribution) |
|
| 191 |
+
| Attack modelling | Railway-specific attacks | Spoofing, injection, replay |
|
| 192 |
+
| Formal artefacts | Rodin XML format | Textual Event-B (Camille notation) |
|
| 193 |
+
| Distribution | Eclipse plugin | Python + Gradio + HF Spaces |
|