Real Package, Wrong Controller: Static Auditing of Vendor--Protocol Mismatches in LLM-Generated PLC Code
Organizations: Department of Electrical and Computer Engineering, The University of Tulsa, Tulsa, OK, USA · Department of Computer Science and Engineering, International Islamic University Chittagong, Chittagong, Bangladesh
Abstract
Language models can generate Python that drives industrial protocols on programmable logic controllers, yet existing code-grounding checks ask whether an imported package or symbol exists rather than whether it suits the declared industrial target. We define metadata-conditioned, import-level vendor--protocol incompatibility and build Proteus-OT, a label-free static verifier over a version-pinned graph of documented bindings. Across 883 generated scripts, 180 carry an import-level mismatch against the declared target (20.4%); restricting to single-vendor targets gives 16.3%, and additionally requiring the offending library to reach a protocol communication call gives 14.2%, which we read as conditional on the corpus metadata rather than on verified intent. None of the 28 adjudicable human control files carries one, a sample too small to estimate a prevalence. Within the balanced subset, 96.6% of mismatching scripts import packages and call methods that exist, so an existence baseline does not represent them, and every positive ships with an inspectable witness. We also audit machine-versus-human classification on the same corpus, where character -grams reach macro-F1 1.000 under task, model and vendor-disjoint partitions and survive comment removal, an AST round trip and identifier anonymisation. The trailing newline present in 95.2% of human files and in none of the generated ones separates the classes on its own. Vendor--protocol consistency is a useful static audit target, whereas provenance classification on repository-labelled corpora is not authorship detection.
Figures & tables
| Work | OT domain | Detects | Vendor sem. | Label-free | Leakage ctrl. | Artifact audit |
|---|---|---|---|---|---|---|
| Ben-Moshe et al. [ 6 ] | ○ | ○ | ○ | ○ | ○ | ○ |
| AutoAttacker [ 7 ] | ○ | ○ | ○ | ○ | ○ | ○ |
| Cook et al. [ 1 ] | ● | ○ | ◐ | ○ | ○ | ○ |
| Spracklen et al. [ 9 ] | ○ | ● | ○ | ◐ | ◐ | ○ |
| Fakih et al. [ 12 ] | ● | ○ | ○ | ○ | ○ | ○ |
| Pendlebury et al. [ 19 ] | ○ | ● | ○ | ○ | ● | ◐ |
| Component | Set | Definition (range) |
|---|---|---|
| imaginary_library | G | Eq. ( 5 ), import absent from registry and from {0,1} |
| nonexistent_symbol | G | invented methods on real OT libraries, count |
| placeholder_comment | G | comment matching insert/TODO/your-code {0,1} |
| redundant_import | G | duplicate top-level import {0,1} |
| comment_density | G | comment lines / total lines |
| cross_vendor_mismatch | OT | Eq. ( 4 ) {0,1, } |
| Estimate | Num. | Den. | Rate [95% CI] |
|---|---|---|---|
| Inclusive (all path-derived) | 180 | 883 | 20.4% [17.9, 23.2] |
| Single-vendor target only | 136 | 833 | 16.3% [14.0, 19.0] |
| Use-level confirmed (L3) | 118 | 833 | 14.2% [12.0, 16.7] |
| Human control | 0 | 28 | 0.0% [0.0, 12.1] |
| Feature space | Rand. | Task | Model | Vendor | Repo |
|---|---|---|---|---|---|
| Char -gram TF–IDF | 1.000 | 1.000 | 1.000 | 1.000 | 0.994 |
| CodeBERT (frozen) [ 13 ] | 0.988 | 0.988 | 0.977 | 0.978 | 0.973 |
| Formatting statistics | 0.943 | 0.940 | 0.900 | 0.934 | 0.914 |
| AST node histogram | 0.937 | 0.931 | 0.911 | 0.923 | 0.907 |
| Proteus-OT (MLP) | 0.893 | 0.899 | 0.861 | 0.898 | 0.849 |
| Proteus-OT (LR) | 0.881 | 0.880 | 0.834 | 0.892 | 0.878 |
| Normalisation | Statistic | AUC | |
| raw | 1.0000 | Trailing newline | 0.024 |
| no comments | 1.0000 | Lines per file | 0.228 |
| whitespace | 1.0000 | Docstring | 0.283 |
| AST round trip | 1.0000 | Shebang | 0.432 |
| identifiers | 1.0000 | Non-ASCII | 0.432 |
| Features deleted | Mean line length | 0.538 |
Static Code Analysis
Static code analysis examines source code without running it to find defects, security risks, and maintainability problems.
See all 62 papers