singhanshuman commited on
Commit
684d7ae
Β·
verified Β·
1 Parent(s): 448bbf6

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +186 -6
README.md CHANGED
@@ -1,13 +1,193 @@
1
  ---
2
- title: Ebsysmlsec Py
3
- emoji: πŸ†
4
  colorFrom: blue
5
- colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 6.14.0
8
- python_version: '3.13'
9
  app_file: app.py
10
  pinned: false
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 |