[Paper Review] Combining Fine-Tuning and LLM-based Agents for Intuitive Smart Contract Auditing with Justifications
TrustLLM combines a two-stage fine-tuning approach (Detector and Reasoner) with Ranker and Critic LLM-based agents to audit Solidity smart contracts with justifications, achieving high vulnerability detection performance and explanation consistency on real-world data.
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.
Motivation & Objective
- Motivate improved smart contract auditing by mimicking human intuition: first perceive potential vulnerabilities, then analyze causes.
- Develop a two-stage fine-tuning framework to separate vulnerability detection (Detector) from cause reasoning (Reasoner).
- Enhance explanation quality with LLM-based Ranker and Critic agents that debate and select the best vulnerability cause.
- Leverage high-quality auditing reports and data-enhancement techniques to assemble balanced training data for fine-tuning.
- Evaluate TrustLLM against traditional fine-tuned models and zero-shot LLMs across detection and justification tasks.
Proposed method
- Two-stage fine-tuning: train a Detector to decide vulnerability presence and a separate Reasoner to generate causes.
- Use multiple prompts per input to create diverse inference paths and apply majority voting for robust decisions (Detector).
- Fine-tune Reasoner with zero-shot chain-of-thought prompts to generate multiple explanations for a given label.
- Introduce Ranker and Critic LLM-based agents to iteratively select and debate the most appropriate vulnerability cause (ranking and validation).
- Assemble training data from auditing reports (positive samples) and a data-enhancement pipeline (negative samples) to create a balanced dataset (1,734 positive, 1,810 negative).
- Compare TrustLLM to traditional fine-tuned models (CodeBERT, GraphCodeBERT, CodeT5, UnixCoder) and zero-shot LLMs (GPT-4, GPT-3.5, CodeLlama) on vulnerability detection.
Experimental results
Research questions
- RQ1RQ1: How does TrustLLM's vulnerability detection performance compare to existing fine-tuned models and zero-shot LLMs?
- RQ2RQ2: How well do Reasoner-generated explanations align with ground-truth vulnerability causes?
- RQ3RQ3: Does the two-stage approach outperform an integrated model that outputs labels and causes jointly?
- RQ4RQ4: Does majority voting improve detector performance and stability?
- RQ5RQ5: What is the impact of additional information (e.g., call graphs) on detection and explanation quality?
Key findings
- TrustLLM outperforms zero-shot LLMs and traditional fine-tuned models on vulnerability detection, achieving F1 0.9121 and accuracy 0.9111.
- Among zero-shot baselines, GPT-4 and GPT-3.5 achieved recall of 1.0 but much lower precision and overall accuracy compared to TrustLLM.
- Reasoner explanations showed higher alignment with ground-truth causes (consistency 37.99%), outperforming GPT-4 (24.13%).
- Majority voting and multi-prompt strategies improve vulnerability decision stability and performance over single-prompt approaches.
- Call graph information can help in some cases but may also confuse the model, with mixed impact on performance.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.