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

识别 Stack Overflow 代码片段中的智能合约安全问题

Identifying Smart Contract Security Issues in Code Snippets from Stack Overflow

Jiachi Chen, Chong Chen, Jiang Hu, John Grundy, Yanlin Wang, Ting Chen, Zibin Zheng

AI总结:

针对Stack Overflow代码片段易含漏洞且现有工具难以分析不完整代码的问题,提出SOChecker工具,结合微调Llama2模型与符号执行检测漏洞,F1分数达68.2%,显著优于GPT-3.5和GPT-4。

摘要:

智能合约开发者经常在 Stack Overflow (SO) 等问答平台上寻求开发挑战的解决方案。尽管社区回复通常提供了可行的方案,但其中嵌入的代码片段也可能包含隐藏的漏洞。将此类代码直接集成到智能合约中可能会使其容易受到恶意攻击。我们进行了一项在线调查,并收到了 74 份来自智能合约开发者的回复。调查结果表明,大多数(86.4%)参与者在重用 SO 代码片段时没有充分考虑安全性。尽管存在各种旨在检测智能合约漏洞的工具,但这些工具通常是为分析完整的智能合约而开发的,因此对于分析 SO 上的典型代码片段无效。我们引入了 SOChecker,这是首个旨在识别不完整的 SO 智能合约代码片段中潜在漏洞的工具。SOChecker 首先利用微调的 Llama2 模型进行代码补全,随后应用符号执行方法进行漏洞检测。我们的实验结果基于从智能合约相关的 SO 帖子中收集的 897 个代码片段的数据集,表明 SOChecker 达到了 68.2% 的 F1 分数,大大超过了 GPT-3.5 和 GPT-4(F1 分数分别为 20.9% 和 33.2%)。我们的研究结果强调需要提高问答网站代码片段的安全性。

英文摘要:

Smart contract developers frequently seek solutions to developmental challenges on Q&A platforms such as Stack Overflow (SO). Although community responses often provide viable solutions, the embedded code snippets can also contain hidden vulnerabilities. Integrating such code directly into smart contracts may make them susceptible to malicious attacks. We conducted an online survey and received 74 responses from smart contract developers. The results of this survey indicate that the majority (86.4%) of participants do not sufficiently consider security when reusing SO code snippets. Despite the existence of various tools designed to detect vulnerabilities in smart contracts, these tools are typically developed for analyzing fully-completed smart contracts and thus are ineffective for analyzing typical code snippets as found on SO. We introduce SOChecker, the first tool designed to identify potential vulnerabilities in incomplete SO smart contract code snippets. SOChecker first leverages a fine-tuned Llama2 model for code completion, followed by the application of symbolic execution methods for vulnerability detection. Our experimental results, derived from a dataset comprising 897 code snippets collected from smart contract-related SO posts, demonstrate that SOChecker achieves an F1 score of 68.2%, greatly surpassing GPT-3.5 and GPT-4 (20.9% and 33.2% F1 Scores respectively). Our findings underscore the need to improve the security of code snippets from Q&A websites.

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

↑