Guiding LLM-based Smart Contract Generation with Finite State Machine

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Luo, Hao, Lin, Yuhao, Yan, Xiao, Hu, Xintong, Wang, Yuxiang, Zeng, Qiming, Wang, Hao, Jiang, Jiawei
Format: Preprint
Published: 2025
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866918019008036864
author Luo, Hao
Lin, Yuhao
Yan, Xiao
Hu, Xintong
Wang, Yuxiang
Zeng, Qiming
Wang, Hao
Jiang, Jiawei
author_facet Luo, Hao
Lin, Yuhao
Yan, Xiao
Hu, Xintong
Wang, Yuxiang
Zeng, Qiming
Wang, Hao
Jiang, Jiawei
contents 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%.
format Preprint
id arxiv_https___arxiv_org_abs_2505_08542
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Guiding LLM-based Smart Contract Generation with Finite State Machine
Luo, Hao
Lin, Yuhao
Yan, Xiao
Hu, Xintong
Wang, Yuxiang
Zeng, Qiming
Wang, Hao
Jiang, Jiawei
Artificial Intelligence
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%.
title Guiding LLM-based Smart Contract Generation with Finite State Machine
topic Artificial Intelligence
url https://arxiv.org/abs/2505.08542