用有限状态机引导大模型生成更安全高效的智能合约。
Guiding LLM-based Smart Contract Generation with Finite State Machine
- 将用户需求转为有限状态机,指导大模型生成合约代码。
- 编译成功率最高提升48%,漏洞风险平均降低68%。
- 适合需要高效、安全生成智能合约的研发人员。
智能合约是基于区块链技术的自执行代码,应用场景广泛,但传统生成方法依赖人工编码和专家审计,门槛高且效率低。尽管大语言模型在编程任务中表现优异,但在智能合约生成方面仍面临有效性和安全性挑战。为此,本文提出基于有限状态机(FSM)与大语言模型的智能合约生成框架FSM-SCG,通过将用户需求抽象为有限状态机,指导大模型生成合约代码,并结合编译与安全检测反馈进行迭代优化,显著提升生成代码质量。实验结果表明,相比最佳基线,FSM-SCG使生成代码的编译成功率最高提升48%,平均漏洞风险评分降低约68%。
原文摘要 · Abstract (English)
Smart contract is a kind of self-executing code based on blockchain technology with a wide range of application scenarios, but the traditional generation method relies on manual coding and expert auditing, which has a high threshold and low efficiency. Although Large Language Models (LLMs) show great potential in programming tasks, they still face challenges in smart contract generation w.r.t. effectiveness and security. To solve these problems, we propose FSM-SCG, a smart contract generation framework based on finite state machine (FSM) and LLMs, which significantly improves the quality of the generated code by abstracting user requirements to generate FSM, guiding LLMs to generate smart contracts, and iteratively optimizing the code with the feedback of compilation and security checks. The experimental results show that FSM-SCG significantly improves the quality of smart contract generation. Compared to the best baseline, FSM-SCG improves the compilation success rate of generated smart contract code by at most 48%, and reduces the average vulnerability risk score by approximately 68%.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。