Smart Contracts are critical components of blockchain ecosystems, with Solidity as the dominant programming language. While LLMs excel at general-purpose code generation, the unique constraints of Smart Contracts, such as gas consumption, security, and determinism, raise open questions about the reliability of LLM-generated Solidity code. Existing studies lack a comprehensive evaluation of these critical functional and non-functional properties. We benchmark four state-of-the-art models under zero-shot and retrieval-augmented generation settings across 500 real-world functions. Our multi-faceted assessment employs code similarity metrics, semantic embeddings, automated test execution, gas profiling, and cognitive and cyclomatic complexity analysis. Results show that while LLMs produce code with high semantic similarity to real contracts, their functional correctness is low: only 20% to 26% of zero-shot generations behave identically to ground-truth implementations under testing. The generated code is consistently simpler, with significantly lower complexity and gas consumption, often due to omitted validation logic. Retrieval-Augmented Generation markedly improves performance, boosting functional correctness by up to 45% and yielding more concise and efficient code. Our findings reveal a significant gap between semantic similarity and functional plausibility in LLM-generated Smart Contracts. We conclude that while RAG is a powerful enhancer, achieving robust, production-ready code generation remains a substantial challenge, necessitating careful expert validation.


翻译:智能合约是区块链生态系统的关键组成部分,其中Solidity是主导编程语言。尽管大语言模型(LLM)在通用代码生成方面表现出色,但智能合约的独特约束(如燃料消耗、安全性和确定性)引发了关于LLM生成的Solidity代码可靠性的开放性问题。现有研究缺乏对这些关键功能和非功能属性的全面评估。我们在零样本和检索增强生成设置下,对四个前沿模型在500个真实世界函数上进行了基准测试。我们的多维度评估采用代码相似性度量、语义嵌入、自动化测试执行、燃料分析,以及认知和圈复杂度分析。结果显示,尽管LLM生成的代码与真实合约具有高语义相似性,但其功能正确性较低:在测试中,仅20%至26%的零样本生成与真实实现行为完全一致。生成的代码普遍更简单,具有显著更低的复杂性和燃料消耗,这通常源于省略了验证逻辑。检索增强生成显著提升了性能,将功能正确性提高多达45%,并产生更简洁高效的代码。我们的发现揭示了LLM生成的智能合约在语义相似性与功能合理性之间存在显著差距。我们得出结论:虽然RAG是一种强大的增强手段,但实现稳健、可用于生产的代码生成仍是一个重大挑战,需要专家的仔细验证。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
VIP会员
最新内容
人工智能赋能无人机:俄乌战争(万字长文)
专知会员服务
4+阅读 · 今天6:56
国外海军作战管理系统与作战训练系统
专知会员服务
2+阅读 · 今天4:16
美军条令《海军陆战队规划流程(2026版)》
专知会员服务
9+阅读 · 今天3:36
《压缩式分布式交互仿真标准》120页
专知会员服务
4+阅读 · 今天3:21
《电子战数据交换模型研究报告》
专知会员服务
6+阅读 · 今天3:13
《基于Transformer的异常舰船导航识别与跟踪》80页
《低数据领域军事目标检测模型研究》
专知会员服务
6+阅读 · 今天2:37
【CMU博士论文】物理世界的视觉感知与深度理解
专知会员服务
10+阅读 · 4月22日
伊朗战争停火期间美军关键弹药状况分析
专知会员服务
8+阅读 · 4月22日
电子战革命:塑造战场的十年突破(2015–2025)
Top
微信扫码咨询专知VIP会员