Skip to main content
QUICK REVIEW

[论文解读] Combining Fine-Tuning and LLM-based Agents for Intuitive Smart Contract Auditing with Justifications

Wei Ma, Daoyuan Wu|arXiv (Cornell University)|Mar 24, 2024
Blockchain Technology Applications and SecurityComputer Science被引用 5
一句话总结

TrustLLM 将两阶段微调方法(Detector 和 Reasoner)与 Ranker 和 Critic 基于 LLM 的代理相结合,以仅凭证据审计 Solidity 智能合约,并在真实世界数据上实现高漏洞检测性能与解释一致性。

ABSTRACT

Smart contracts are decentralized applications built atop blockchains like Ethereum. Recent research has shown that large language models (LLMs) have potential in auditing smart contracts, but the state-of-the-art indicates that even GPT-4 can achieve only 30% precision (when both decision and justification are correct). This is likely because off-the-shelf LLMs were primarily pre-trained on a general text/code corpus and not fine-tuned on the specific domain of Solidity smart contract auditing. In this paper, we propose iAudit, a general framework that combines fine-tuning and LLM-based agents for intuitive smart contract auditing with justifications. Specifically, iAudit is inspired by the observation that expert human auditors first perceive what could be wrong and then perform a detailed analysis of the code to identify the cause. As such, iAudit employs a two-stage fine-tuning approach: it first tunes a Detector model to make decisions and then tunes a Reasoner model to generate causes of vulnerabilities. However, fine-tuning alone faces challenges in accurately identifying the optimal cause of a vulnerability. Therefore, we introduce two LLM-based agents, the Ranker and Critic, to iteratively select and debate the most suitable cause of vulnerability based on the output of the fine-tuned Reasoner model. To evaluate iAudit, we collected a balanced dataset with 1,734 positive and 1,810 negative samples to fine-tune iAudit. We then compared it with traditional fine-tuned models (CodeBERT, GraphCodeBERT, CodeT5, and UnixCoder) as well as prompt learning-based LLMs (GPT4, GPT-3.5, and CodeLlama-13b/34b). On a dataset of 263 real smart contract vulnerabilities, iAudit achieves an F1 score of 91.21% and an accuracy of 91.11%. The causes generated by iAudit achieved a consistency of about 38% compared to the ground truth causes.

研究动机与目标

  • 通过模仿人类直觉来激发改进的智能合约审计:先感知潜在漏洞,再分析原因。
  • 开发一个两阶段微调框架,将漏洞检测(Detector)与原因推理(Reasoner)分离。
  • 利用基于 LLM 的 Ranker 和 Critic 代理进行辩论并选择最佳漏洞原因,以提升解释质量。
  • 利用高质量的审计报告和数据增强技术,汇集用于微调的平衡训练数据。
  • 在检测和辩护任务上,将 TrustLLM 与传统微调模型和零-shot LLMs 进行比较评估。

提出的方法

  • 两阶段微调:训练一个 Detector 以判断漏洞存在性,另一个单独的 Reasoner 以生成原因。
  • 对每个输入使用多种提示创建多样的推理路径,并对(Detector)应用多数投票以获得鲁棒决策。
  • 用零-shot 链式推理提示对 Reasoner 进行微调,以为给定标签生成多种解释。
  • 引入基于 LLM 的 Ranker 和 Critic 代理,迭代地选择并辩论最合适的漏洞原因(排序与验证)。
  • 从审计报告(正样本)和数据增强管道(负样本)组装训练数据,形成平衡数据集(1,734 个正样本,1,810 个负样本)。
  • 在漏洞检测方面将 TrustLLM 与传统微调模型(CodeBERT、GraphCodeBERT、CodeT5、UnixCoder)以及零-shot LLM(GPT-4、GPT-3.5、CodeLlama)进行比较。

实验结果

研究问题

  • RQ1RQ1:TrustLLM 的漏洞检测性能与现有微调模型和零-shot LLMs 相比如何?
  • RQ2RQ2:Reasoner 生成的解释与真实漏洞原因的对齐程度如何?
  • RQ3RQ3:两阶段方法是否优于输出标签和原因的联合集成模型?
  • RQ4RQ4:多数投票是否提升检测器的性能与稳定性?
  • RQ5RQ5:额外信息(如调用图)对检测和解释质量有何影响?

主要发现

  • TrustLLM 在漏洞检测上优于零-shot LLMs 和传统微调模型,达到 F1 0.9121 和 accuracy 0.9111。
  • 在零-shot 基线中,GPT-4 和 GPT-3.5 的召回率为 1.0,但精确度和整体准确率远低于 TrustLLM。
  • Reasoner 的解释与真实原因的对齐度更高(一致性 37.99%),优于 GPT-4(24.13%)。
  • 多数投票和多提示策略在漏洞决策的稳定性和性能方面优于单提示方法。
  • 调用图信息在某些情况下有帮助,但也可能混淆模型,对性能的影响呈现混合。

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。