TL;DR
Trace2ST is a novel pipeline that uses Large Language Models (LLMs) to recover lost industrial control logic (Structured Text) solely from input/output logs. By combining iterative LLM generation with a validated execution "judge," the system achieves 94% agreement on unseen data and can even detect cyber-attacks on real-world water treatment plants.
What Problem Does This Paper Address?
Programmable Logic Controllers (PLCs) are the "brains" behind power plants, water treatment facilities, and factories. Many of these systems run on code written decades ago. Over time, the original source code is often lost—it might exist only as a compiled binary or be locked in a proprietary tool that no longer exists.
However, these plants usually have a "historian": a database that logs every single input and output (I/O) signal. The authors ask: Can we use these I/O traces to reverse-engineer the original control logic?
This isn't just an academic exercise. Recovering this logic is essential for:
- Migration: Moving old logic to modern hardware.
- Digital Twins: Creating software simulations of a plant for testing.
- Intrusion Detection: If you know exactly how the controller should behave, you can easily spot when a hacker has manipulated an actuator.
Methods
The authors developed a generate–replay–feedback pipeline called Trace2ST. Because raw I/O traces are too massive for an LLM's context window (e.g., 4,000 scans), the process follows these steps:
- Trace Compression: The raw data is summarized into a variable table, samples of state transitions, and "hints" (e.g., "Output X rises 2 seconds after Input Y").
- LLM Generation: Using the summary, an LLM (Claude) writes a candidate program in Structured Text (ST).
- The Judge (Verification): The candidate program is executed by a custom-built ST interpreter. This interpreter was rigorously validated against two independent open-source PLC runtimes (MATIEC and truST) to ensure its "verdict" is trustworthy.
- Iterative Feedback: If the candidate program's output doesn't match the recorded trace, the specific "mismatch windows" are sent back to the LLM for revision. The agent gets up to three attempts to fix the code.
Datasets
The study evaluated the pipeline using three distinct sources:
- Synthetic Controllers: Three programs (tank-level, conveyor, pressure control) used to calibrate the toolchain.
- Blind Benchmark: 47 third-party programs from public sources (like PLCHaT), ranging from simple alarms to complex safety interlocks.
- HAI 23.05 Dataset: Real-world data from an industrial water-treatment testbed featuring Siemens S7-300 PLCs. This dataset includes actual sensor measurements and a recorded actuator-manipulation attack.
Key Insights and Ideas
- Structure vs. Curve Fitting: The authors compared the LLM to classical "automata learning" (which builds state machines from data). While the classical method could fit the training data, it failed miserably on new, unseen inputs (40% accuracy). The LLM, however, was able to infer the underlying structure (like timers and counters), allowing it to generalize to new scenarios (94% accuracy).
- The "Unexercised Branch" Problem: If a trace never shows a "Reset" button being pressed, no learner can guess what that button does. The authors found that by adding "probe traces"—targeted inputs designed to trigger rare behaviors—recovery agreement on adversarial inputs jumped from 0.80 to 0.98.
- LLMs as Security Tools: By recovering the "ground truth" logic from historical data, the system creates a reference model. In the HAI dataset, the recovered program perfectly matched normal operations but diverged sharply during a cyber-attack, effectively exposing the intrusion.
Key Results
- High Fidelity: For the 47 third-party programs, Trace2ST reproduced the recorded traces exactly in 43 out of 47 cases.
- Generalization: On "held-out" traces (data the LLM never saw), the recovered programs maintained a 94% agreement rate.
- Real-World Performance: On the HAI water-treatment data, the recovered control laws reached an $R^2 > 0.99$, matching the physical behavior of the plant almost perfectly.
- Robustness: The authors performed "mutation testing" (changing the logic but keeping variable names) and "neutral identifier" tests (replacing names with generic IDs). They proved the LLM was actually inferring the logic rather than just recalling programs from its training data.
Limitations and Future Work
- Single Model Family: The study relied exclusively on the Claude LLM family. Future work should test if these results hold across other models like GPT-4 or specialized code models.
- Manual Probing: Currently, "probe traces" to exercise hidden branches are designed manually. The authors suggest that future versions could use the LLM's own "notes" on unexplained behavior to automatically generate these probes.
- Vendor Semantics: PLC languages have subtle variations between vendors (e.g., how they handle time units). The recovery process still requires some prior knowledge of the target runtime's specific semantics.
Summary updated