HardSecBench: Benchmarking the Security Awareness of LLMs for Hardware Code Generation
Qirui Chen, Jingxian Shuai, Shuangwu Chen, Shenghao Ye, Zijian Wen, Xufei Su, Jie Jin, Jiangming Li, Jun Chen, Xiaobin Tan, Jian Yang
TL;DR
HardSecBench tackles the lack of standardized benchmarks for security in LLM-generated hardware code by introducing a scalable, CWE-based benchmark constructed through a four-stage, multi-agent pipeline that separates specification, implementation, and verification. Each task yields a structured specification, a secure reference implementation, and requirement-level harnesses validated with execution evidence, enabling objective security assessment. Empirical results show that models often achieve strong functional correctness while neglecting security protections, with improvements sensitive to prompting and domain-specific fine-tuning. The work provides practical benchmarks and actionable insights to guide safer, more robust LLM-assisted hardware design, and it releases data and code to support further research.
Abstract
Large language models (LLMs) are being increasingly integrated into practical hardware and firmware development pipelines for code generation. Existing studies have primarily focused on evaluating the functional correctness of LLM-generated code, yet paid limited attention to its security issues. However, LLM-generated code that appears functionally sound may embed security flaws which could induce catastrophic damages after deployment. This critical research gap motivates us to design a benchmark for assessing security awareness under realistic specifications. In this work, we introduce HardSecBench, a benchmark with 924 tasks spanning Verilog Register Transfer Level (RTL) and firmware-level C, covering 76 hardware-relevant Common Weakness Enumeration (CWE) entries. Each task includes a structured specification, a secure reference implementation, and executable tests. To automate artifact synthesis, we propose a multi-agent pipeline that decouples synthesis from verification and grounds evaluation in execution evidence, enabling reliable evaluation. Using HardSecBench, we evaluate a range of LLMs on hardware and firmware code generation and find that models often satisfy functional requirements while still leaving security risks. We also find that security results vary with prompting. These findings highlight pressing challenges and offer actionable insights for future advancements in LLM-assisted hardware design. Our data and code will be released soon.
