一句话:结合知识图谱与检索增强生成,用知识引导加思维链的两阶段策略实现智能合约漏洞自动修补。
智能合约部署后代码不可更改,漏洞往往造成重大经济损失,而现有工具只能检测漏洞、无法有效修复。本文提出 SCPatcher 框架,将检索增强生成(RAG)与知识图谱结合用于智能合约自动修复。作者从 5,000 个已验证的以太坊合约中抽取函数级关系,构建语义网络作为外部知识库,用以增强大语言模型的推理能力并支持精确的漏洞修补。修复过程采用两阶段策略:先进行知识引导的初步修复,再针对复杂漏洞引入思维链(Chain-of-Thought)推理。在一组多样化的含漏洞合约上评估,SCPatcher 达到 81.5% 的整体修复率与 91.0% 的编译通过率,显著优于现有方法。
Smart contract vulnerabilities can cause substantial financial losses due to the immutability of code after deployment. While existing tools detect vulnerabilities, they cannot effectively repair them. In this paper, we propose SCPatcher, a framework that combines retrieval-augmented generation with a knowledge graph for automated smart contract repair. We construct a knowledge graph from 5,000 verified Ethereum contracts, extracting function-level relationships to build a semantic network. This graph serves as an external knowledge base that enhances Large Language Model reasoning and enables precise vulnerability patching. We introduce a two-stage repair strategy, initial knowledge-guided repair followed by Chain-of-Thought reasoning for complex vulnerabilities. Evaluated on a diverse set of vulnerable contracts, SCPatcher achieves 81.5% overall repair rate and 91.0% compilation pass rate, substantially outperforming existing methods.
DOI 原文 · arXiv · PDF(开放获取) · DBLP
@inproceedings{abs-2604-00687,
title = {SCPatcher: Automated Smart Contract Code Repair via Retrieval-Augmented Generation and Knowledge Graph},
author = {Xiaoqi Li and Shipeng Ye and Wenkai Li and Zongwei Li},
booktitle = {FSE},
year = {2026},
doi = {10.1145/3803437.3805558}
}