arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2403.16073cs.SE
收藏

结合微调与基于LLM的智能体实现带依据的直观智能合约审计

Combining Fine-Tuning and LLM-based Agents for Intuitive Smart Contract Auditing with Justifications

Wei Ma, Daoyuan Wu, Yuqiang Sun, Tianwen Wang, Shangqing Liu, Jian Zhang, Yue Xue, Yang Liu

AI总结:

针对现有大语言模型智能合约审计准确率低的问题,提出结合两阶段微调与排序、评判双智能体的iAudit框架,在真实漏洞数据集上实现91.21%的F1值。

摘要:

智能合约是构建在以太坊等区块链之上的去中心化应用。近期研究表明,大语言模型(LLM)在智能合约审计方面具备潜力,但现有最优结果显示,即便GPT-4也仅能达到30%的准确率(要求决策与依据均正确时)。这可能是因为现成的LLM主要在通用文本/代码语料上预训练,并未针对Solidity智能合约审计这一特定领域进行微调。\n 本文提出iAudit,这是一个结合微调与基于LLM的智能体的通用框架,可实现带依据的直观智能合约审计。具体而言,iAudit的设计灵感来源于一项观察:人类专家审计师会先感知可能存在的问题,再对代码展开详细分析以确定成因。据此,iAudit采用两阶段微调方法:首先微调Detector(检测器)模型以做出决策,随后微调Reasoner(推理器)模型以生成漏洞成因。然而,仅靠微调难以准确识别漏洞的最优成因。因此,我们引入两个基于LLM的智能体——Ranker(排序器)和Critic(评判器),基于微调后的Reasoner模型的输出,迭代式地筛选并论证最合适的漏洞成因。为评估iAudit,我们收集了一个包含1734个正样本和1810个负样本的均衡数据集用于微调iAudit。随后我们将其与传统微调模型(CodeBERT、GraphCodeBERT、CodeT5和UnixCoder)以及基于提示学习的LLM(GPT4、GPT-3.5和CodeLlama-13b/34b)进行对比。在包含263个真实智能合约漏洞的数据集上,iAudit取得了91.21%的F1值和91.11%的准确率。iAudit生成的漏洞成因与真实成因相比,一致性约为38%。

英文摘要:

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.

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

↑