Proceedings

Guiding LLM-based Smart Contract Generation with Finite State Machine

Download BibTeX Cite

Proceedings of the Thirty-Fourth International Joint Conference on Artificial Intelligence. Main Track. Pages 5869-5877.

https://doi.org/10.24963/ijcai.2025/653

Abstract

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%.

  1. [Almakhour et al., 2020] Mouhamad Almakhour, Layth Sli- man, Abed Ellatif Samhat, and Abdelhamid Mellouk. Ver- ification of smart contracts: A survey. Pervasive and Mo- bile Computing, 67:101227, 2020.
  2. [Chatterjee and Ramamurthy, 2024] Siddhartha Chatterjee and Bina Ramamurthy. Efficacy of various large language models in generating smart contracts. arXiv preprint arXiv:2407.11019, 2024.
  3. [Clack et al., 2019] Christopher D Clack, Vikram A Bakshi, and Lee Braine. Smart contract templates: foundations, design landscape and research directions (2016). Preprint. arXiv, 1608, 2019.
  4. [Feist et al., 2019] Josselin Feist, Gustavo Grieco, and Alex Groce. Slither: a static analysis framework for smart contracts. In IEEE/ACM 2nd International Workshop on Emerging Trends in Software Engineering for Blockchain (WETSEB), pages 8-15, 2019.
  5. [Hu et al., 2022] Edward J Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, Weizhu Chen, et al. Lora: Low-rank adaptation of large language models. ICLR, 1(2):3, 2022.
  6. [Huang et al., 2024a] Hao Huang, Qian Yan, Keqi Han, Ting Gan, Jiawei Jiang, Quanqing Xu, and Chuanhui Yang. Learning diffusions under uncertainty. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 38, pages 20430-20437, 2024.
  7. [Huang et al., 2024b] Qiang Huang, Xiao Yan, Xin Wang, Susie Xi Rao, Zhichao Han, Fangcheng Fu, Wen- tao Zhang, and Jiawei Jiang. Retrofitting temporal graph neural networks with transformer. arXiv preprint arXiv:2409.05477, 2024.
  8. [Jiang et al., 2024a] Jiawei Jiang, Hao Huang, Zhigao Zheng, Yi Wei, Fangcheng Fu, Xiaosen Li, and Bin Cui. Detecting and analyzing motifs in large-scale online trans- action networks. IEEE Transactions on Knowledge and Data Engineering, 2024.
  9. [Jiang et al., 2024b] Juyong Jiang, Fan Wang, Jiasi Shen, Sungju Kim, and Sunghun Kim. A survey on large language models for code generation. arXiv preprint arXiv:2406.00515, 2024. [Kenton and Toutanova, 2019]
  10. Jacob Devlin Ming- Wei Chang Kenton and Lee Kristina Toutanova. Bert: Pre-training of deep bidirectional transformers for lan- guage understanding. In Proceedings of NAACL-HLT, volume 1, page 2, 2019.
  11. [Khan et al., 2021] Shafaq Naheed Khan, Faiza Loukil, Chirine Ghedira-Guegan, Elhadj Benkhelifa, and Anoud Bani-Hani. Blockchain smart contracts: Applications, challenges, and future trends. Peer-to-peer Networking and Applications, 14:2901-2925, 2021.
  12. [Li et al., 2024] Zihao Li, Yucheng Shi, Zirui Liu, Fan Yang, Ali Payani, Ninghao Liu, and Mengnan Du. Quantifying multilingual performance of large language models across languages. arXiv preprint arXiv:2404.11553, 2024.
  13. [Liu et al., 2024] Qidong Liu, Xian Wu, Xiangyu Zhao, Yuanshao Zhu, Derong Xu, Feng Tian, and Yefeng Zheng. When moe meets llms: Parameter efficient fine-tuning for multi-task medical applications. In Proceedings of the 47th International ACM SIGIR Conference on Research and Development in Information Retrieval, pages 1104- 1114, 2024.
  14. [Li♂ et al., 2023] Jia Li♂, Ge Li, Yongmin Li, and Zhi Jin. Structured chain-of-thought prompting for code genera- tion. ACM Transactions on Software Engineering and Methodology, 2023.
  15. [López-Pintado et al., 2017] Orlenys López-Pintado, Lu- ciano García-Bañuelos, Marlon Dumas, and Ingo Weber. Caterpillar: A blockchain-based business process manage- ment system. BPM (Demos), 172:1-5, 2017.
  16. [Luo et al., 2024] Ling Luo, Jinzhong Ning, Yingwen Zhao, Zhijun Wang, Zeyuan Ding, Peng Chen, Weiru Fu, Qinyu Han, Guangtao Xu, Yunzhi Qiu, et al. Taiyi: a bilingual fine-tuned large language model for diverse biomedical tasks. Journal of the American Medical Informatics As- sociation, page ocae037, 2024.
  17. [Luo et al., 2025] Hao Luo, Yuhao Lin, Xiao Yan, Xintong Hu, Yuxiang Wang, Qiming Zeng, Hao Wang, and Jiawei Jiang. Guiding llm-based smart contract generation with finite state machine. arXiv preprint arXiv:2505.08542, 2025.
  18. [Luu et al., 2016] Loi Luu, Duc-Hiep Chu, Hrishi Olickel, Prateek Saxena, and Aquinas Hobor. Making smart con- tracts smarter. In Proceedings of the 2016 ACM SIGSAC conference on Computer and Communications Security, pages 254-269, 2016.
  19. [Mao et al., 2019] Dianhui Mao, Fan Wang, Yalei Wang, and Zhihao Hao. Visual and user-defined smart contract de- signing system based on automatic coding. IEEE Access, 7:73131-73143, 2019.
  20. [Mavridou and Laszka, 2018] Anastasia Mavridou and Aron Laszka. Tool demonstration: Fsolidm for designing secure ethereum smart contracts. In Principles of Security and Trust: 7th International Conference, POST 2018, Held as Part of the European Joint Conferences on Theory and Practice of Software, pages 270-277, 2018.
  21. [Napoli et al., 2024] Emanuele Antonio Napoli, Fadi Bar- bàra, Valentina Gatteschi, and Claudio Schifanella. Lever- aging large language models for automatic smart contract generation. In IEEE 48th Annual Computers, Software, and Applications Conference (COMPSAC), pages 701- 710, 2024.
  22. [Petrović and Al-Azzoni, 2023] Nenad Petrović and Issam Al-Azzoni. Model-driven smart contract generation lever- aging chatgpt. In International Conference On Systems Engineering, pages 387-396, 2023.
  23. [Poesia et al., 2022] Gabriel Poesia, Oleksandr Polozov, Vu Le, Ashish Tiwari, Gustavo Soares, Christopher Meek, and Sumit Gulwani. Synchromesh: Reliable code gener- ation from pre-trained language models. arXiv preprint arXiv:2201.11227, 2022.
  24. [Qasse et al., 2023] Ilham Qasse, Shailesh Mishra, Björn þór Jónsson, Foutse Khomh, and Mohammad Hamdaqa. Chat2code: A chatbot for model specification and code generation, the case of smart contracts. In IEEE In- ternational Conference on Software Services Engineering (SSE), pages 50-60, 2023.
  25. [Sayeed et al., 2020] Sarwar Sayeed, Hector Marco-Gisbert, and Tom Caira. Smart contract: Attacks and protections. IEEE Access, 8:24416-24427, 2020.
  26. [Skotnica and Pergl, 2019] Marek Skotnica and Robert Pergl. Das contract-a visual domain specific language for modeling blockchain smart contracts. In Enterprise Engineering Working Conference, pages 149-166, 2019.
  27. [Suvorov and Ulyantsev, 2019] Dmitrii Suvorov and Vladimir Ulyantsev. Smart contract design meets state machine synthesis: Case studies. arXiv preprint arXiv:1906.02906, 2019.
  28. [Tran et al., 2018] An Binh Tran, Qinghua Lu, and Ingo Weber. Lorikeet: A model-driven engineering tool for blockchain-based business process execution and as- set management. In BPM (dissertation/demos/industry), pages 56-60, 2018.
  29. [Wang et al., 2018] Shuai Wang, Yong Yuan, Xiao Wang, Juanjuan Li, Rui Qin, and Fei-Yue Wang. An overview of smart contract: architecture, applications, and future trends. In 2018 IEEE Intelligent Vehicles Symposium (IV), pages 108-113, 2018.
  30. [Wang et al., 2024] Yuxiang Wang, Xiao Yan, Shiyu Jin, Hao Huang, Quanqing Xu, Qingchen Zhang, Bo Du, and Jiawei Jiang. Self-supervised learning for graph dataset condensation. In Proceedings of the 30th ACM SIGKDD Conference on Knowledge Discovery and Data Mining, pages 3289-3298, 2024.
  31. [Wei et al., 2022] Jason Wei, Xuezhi Wang, Dale Schuur- mans, Maarten Bosma, Fei Xia, Ed Chi, Quoc V Le, Denny Zhou, et al. Chain-of-thought prompting elicits reasoning in large language models. Advances in Neural Information Processing Systems, 35:24824-24837, 2022.
  32. [Wöhrer and Zdun, 2020] Maximilian Wöhrer and Uwe Zdun. Domain specific language for smart contract devel- opment. In IEEE International Conference on Blockchain and Cryptocurrency (ICBC), pages 1-9, 2020.
  33. [Xia et al., 2024] Yifei Xia, Fangcheng Fu, Wentao Zhang, Jiawei Jiang, and Bin Cui. Efficient multi-task llm quanti- zation and serving for multiple lora adapters. Advances in Neural Information Processing Systems, 37:63686-63714, 2024.
  34. [Yang et al., 2024] Jingfeng Yang, Hongye Jin, Ruixiang Tang, Xiaotian Han, Qizhang Feng, Haoming Jiang, Shaochen Zhong, Bing Yin, and Xia Hu. Harnessing the power of llms in practice: A survey on chatgpt and be- yond. ACM Transactions on Knowledge Discovery from Data, 18(6):1-32, 2024.
  35. [Yong et al., 2024] Chen Yong, Hu Defeng, Xu Chao, Chen Nannan, Fanfan Shen, and Jianbo Liu. Smart contract gen- eration model based on code annotation and ast-lstm tun- ing, 2024.
  36. [Zhang et al., 2024] Qinbo Zhang, Xiao Yan, Yukai Ding, Quanqing Xu, Chuang Hu, Xiaokai Zhou, and Jiawei Jiang. Treecss: An efficient framework for verti- cal federated learning. In International Conference on Database Systems for Advanced Applications, pages 425- 441. Springer, 2024.
  37. [Zhao et al., 2024] Zihuai Zhao, Wenqi Fan, Jiatong Li, Yun- qing Liu, Xiaowei Mei, Yiqi Wang, Zhen Wen, Fei Wang, Xiangyu Zhao, Jiliang Tang, et al. Recommender systems in the era of large language models (llms). IEEE Transac- tions on Knowledge and Data Engineering, 2024.

References were extracted automatically from the PDF and may contain errors.

Welcome Future Conferences AI Journal Division IJCAI Proceedings About IJCAI IJCAI Awards