用知识图谱指导大模型生成更安全的芯片状态机代码
SecFSM: Knowledge Graph-Guided Verilog Code Generation for Secure Finite State Machines in Systems-on-Chip
- 用安全知识图谱增强大模型,引导生成可信的Verilog代码
- 在25个测试用例中通过率21/25,显著优于现有方法
- 适合芯片安全设计、自动化代码生成方向的研究者
有限状态机(FSM)在片上系统(SoC)控制逻辑实现中至关重要。传统上由硬件工程师手动编写Verilog代码,过程繁琐耗时。近年来,大型语言模型(LLMs)在代码生成方面进展迅速,被用于自动化生成Verilog代码。然而,LLM生成的代码常存在安全漏洞,这对安全敏感的FSM实现尤为不利。为此,我们提出SecFSM,一种利用面向安全的知识图谱引导LLM生成更安全Verilog代码的新方法。首先构建外部辅助知识图谱FSKG;其次分析用户需求,识别潜在漏洞并生成漏洞列表;接着基于漏洞列表从FSKG中检索安全知识;最后构造包含安全知识的提示词,用于代码生成。为评估方法,我们构建了一个涵盖学术数据集、人工数据、论文及工业案例的专用数据集。大量实验表明,SecFSM优于当前最先进基线,在25个安全测试用例上经DeepSeek-R1评估,通过率达21/25。
原文摘要 · Abstract (English)
Finite State Machines (FSMs) play a critical role in implementing control logic for Systems-on-Chip (SoC). Traditionally, FSMs are implemented by hardware engineers through Verilog coding, which is often tedious and time-consuming. Recently, with the remarkable progress of Large Language Models (LLMs) in code generation, LLMs have been increasingly explored for automating Verilog code generation. However, LLM-generated Verilog code often suffers from security vulnerabilities, which is particularly concerning for security-sensitive FSM implementations. To address this issue, we propose SecFSM, a novel method that leverages a security-oriented knowledge graph to guide LLMs in generating more secure Verilog code. Specifically, we first construct a FSM Security Knowledge Graph (FSKG) as an external aid to LLMs. Subsequently, we analyze users' requirements to identify vulnerabilities and get a list of vulnerabilities in the requirements. Then, we retrieve knowledge from FSKG based on the vulnerabilities list. Finally, we construct security prompts based on the security knowledge for Verilog code generation. To evaluate SecFSM, we build a dedicated dataset collected from academic datasets, artificial datasets, papers, and industrial cases. Extensive experiments demonstrate that SecFSM outperforms state-of-the-art baselines. In particular, on a benchmark of 25 security test cases evaluated by DeepSeek-R1, SecFSM achieves an outstanding pass rate of 21/25.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。