Auto-SPT: Automating Semantic Preserving Transformations for Code
作者: Ashish Hooda, Mihai Christodorescu, Chuangang Ren, Aaron Wilson, Kassem Fawaz, Somesh Jha
分类: cs.SE, cs.AI
发布日期: 2025-12-05
💡 一句话要点
Auto-SPT:自动化代码语义保持变换,提升代码克隆检测模型的鲁棒性。
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 代码克隆检测 语义保持变换 大型语言模型 数据增强 鲁棒性 代码混淆 软件安全
📋 核心要点
- 现有的代码克隆检测模型主要在干净、结构化的代码数据集上训练,而现实世界的代码通常会经历各种语义保持变换,导致训练和测试数据之间存在差距。
- Auto-SPT利用大型语言模型自动生成语义保持变换(SPTs),通过多样化的SPTs设计、实现和组合,增强代码的变换能力。
- 实验证明,Auto-SPT生成的SPTs比现有方法更有效,显著降低了现有代码克隆检测器的性能,并能提升模型对真实世界代码变换的鲁棒性。
📝 摘要(中文)
本文提出了一种名为Auto-SPT的新框架,用于自动构建代码合成数据生成器。该框架旨在生成语义保持变换(SPTs),这些变换在改变程序句法结构的同时保持其功能不变。Auto-SPT基于大型语言模型(LLMs),利用LLMs来设计多样化的SPTs,生成这些SPTs的强大实现,并将它们组合成强大的变换。形式分析表明,SPTs的多样性会影响其组合的强度。实验结果表明,Auto-SPT生成的SPTs比现有方法更多样化,并且这些SPTs显著降低了最先进的代码克隆检测器的性能。进一步的实验表明,Auto-SPT可用于增强代码数据集的训练,从而生成对真实世界、对抗性代码变换具有鲁棒性的代码克隆检测模型。
🔬 方法详解
问题定义:代码克隆检测模型在软件工程和安全领域至关重要,但现有模型在面对经过语义保持变换的代码时性能下降。问题在于训练数据与实际应用场景存在差异,缺乏对各种代码变换的鲁棒性。现有方法难以自动生成多样且有效的语义保持变换,从而限制了模型的泛化能力。
核心思路:Auto-SPT的核心思路是利用大型语言模型(LLMs)的强大生成能力,自动生成多样化的语义保持变换(SPTs)。通过精心设计的提示工程和组合策略,使得生成的SPTs既能改变代码的句法结构,又能保持其语义不变,从而增强模型的鲁棒性。
技术框架:Auto-SPT框架主要包含以下几个阶段:1) SPT设计:利用LLM生成各种可能的语义保持变换策略。2) SPT实现:LLM根据设计好的策略生成具体的代码变换实现。3) SPT组合:将多个SPTs组合成更复杂的变换,增加代码变换的多样性。4) 评估与反馈:评估生成的SPTs对代码克隆检测模型的影响,并根据评估结果调整LLM的生成策略。
关键创新:Auto-SPT的关键创新在于利用LLM自动生成多样化的语义保持变换。与传统的手工设计或基于规则的变换方法相比,Auto-SPT能够生成更复杂、更难以预测的变换,从而更有效地提高模型的鲁棒性。此外,Auto-SPT还通过形式分析证明了SPTs多样性对组合强度的影响。
关键设计:Auto-SPT的关键设计包括:1) 精心设计的LLM提示工程,用于引导LLM生成高质量的SPTs。2) 多样性度量方法,用于评估生成的SPTs的多样性,并指导LLM生成更多样化的变换。3) 组合策略,用于将多个SPTs组合成更复杂的变换,增加代码变换的复杂性。具体的参数设置和损失函数等细节在论文中未详细说明,属于未知信息。
📊 实验亮点
实验结果表明,Auto-SPT生成的SPTs比现有方法更多样化,并且这些SPTs显著降低了最先进的代码克隆检测器的性能。具体而言,使用Auto-SPT生成的SPTs进行攻击,代码克隆检测器的性能下降了X%(具体数值未知)。此外,使用Auto-SPT增强训练数据后,代码克隆检测模型对真实世界代码变换的鲁棒性得到了显著提升。
🎯 应用场景
Auto-SPT可应用于软件安全、代码混淆、代码去重等领域。通过生成具有鲁棒性的代码克隆检测模型,可以有效检测恶意代码变种,提升软件安全性。此外,Auto-SPT还可以用于生成对抗样本,评估和提升代码分析工具的安全性。未来,该技术有望应用于自动化代码审计和漏洞挖掘等领域。
📄 摘要(原文)
Machine learning (ML) models for code clone detection determine whether two pieces of code are semantically equivalent, which in turn is a key building block for software-engineering tasks like refactoring and security tasks like vulnerability and malware detection. While these models are predominantly trained on clean, structured code datasets, real-world code often undergoes a variety of semantic-preserving transformations, including refactoring, minification, automated formatting, and compiler optimizations. To address this critical gap between training and test data, we propose Auto-SPT, a novel framework to automatically construct synthetic-data generators for code. Auto-SPT is designed to produce Semantic Preserving Transformations (SPTs) that alter a program's syntactic structure while preserving its functionality and is instantiated on top of Large Language Models (LLMs). In particular, we use LLMs to craft a diverse set of SPTs, generate strong implementations for these SPTs, and compose them to result into strong transformations. Our formal analysis shows that the diversity of SPTs impacts the strength of their composition. We then empirically demonstrate that Auto-SPT generates more diverse SPTs than existing approaches and these SPTs significantly drop the performance of state-of-the-art code clone detectors. Further experiments show Auto-SPT can be used to enhance code datasets for training, to produce code-clone detection models that are robust to real-world, adversarial code transformations.