arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2405.00218cs.CRcs.AIcs.LGcs.SE
收藏

用于安全代码生成的约束解码

Constrained Decoding for Secure Code Generation

University of Maryland(马里兰大学);Google DeepMind(谷歌DeepMind)

Yanjun Fu, Ethan Baker, Yu Ding, Yizheng Chen

AI总结:

本文提出CodeGuard+基准和两个新指标,评估代码LLM生成安全且正确代码的能力,并探索约束解码技术,证明其比前缀调优更有效,且优于GPT-4。

摘要:

代码大型语言模型(Code LLMs)已被开发者越来越多地用于提高生产力,但它们经常生成易受攻击的代码。因此,迫切需要确保由代码大型语言模型生成的代码既正确又安全。以往的研究主要集中于生成安全代码,却忽视了安全代码也需要正确这一事实。这种忽视可能导致虚假的安全感。目前,社区缺乏衡量该领域实际进展的方法,我们需要同时解决代码生成的安全性和正确性的解决方案。本文介绍了一个新的基准测试CodeGuard+,以及两个新指标,用以衡量代码大型语言模型生成既安全又正确的代码的能力。使用我们新的评估方法,我们展示了最先进防御技术——前缀调优(prefix tuning)——可能并不像先前认为的那样强大,因为它生成安全代码但牺牲了功能正确性。我们还证明了不同的解码方法显著影响代码大型语言模型的安全性。此外,我们探索了一个新的防御方向:用于安全代码生成的约束解码。我们提出了新的约束解码技术以生成安全代码。我们的结果显示,约束解码在提高代码大型语言模型安全性方面比前缀调优更有效,且无需专门的训练数据集。此外,我们对八个最先进的代码大型语言模型的评估表明,约束解码在提高代码大型语言模型安全性方面表现强劲,我们的技术优于GPT-4。

英文摘要:

Code Large Language Models (Code LLMs) have been increasingly used by developers to boost productivity, but they often generate vulnerable code. Thus, there is an urgent need to ensure that code generated by Code LLMs is correct and secure. Previous research has primarily focused on generating secure code, overlooking the fact that secure code also needs to be correct. This oversight can lead to a false sense of security. Currently, the community lacks a method to measure actual progress in this area, and we need solutions that address both security and correctness of code generation. This paper introduces a new benchmark, CodeGuard+, along with two new metrics, to measure Code LLMs' ability to generate both secure and correct code. Using our new evaluation methods, we show that the state-of-the-art defense technique, prefix tuning, may not be as strong as previously believed, since it generates secure code but sacrifices functional correctness. We also demonstrate that different decoding methods significantly affect the security of Code LLMs. Furthermore, we explore a new defense direction: constrained decoding for secure code generation. We propose new constrained decoding techniques to generate secure code. Our results reveal that constrained decoding is more effective than prefix tuning to improve the security of Code LLMs, without requiring a specialized training dataset. Moreover, our evaluations over eight state-of-the-art Code LLMs show that constrained decoding has strong performance to improve the security of Code LLMs, and our technique outperforms GPT-4.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑