# Guiding LLM-based Smart Contract Generation with Finite State Machine

arXiv: https://arxiv.org/abs/2505.08542 · HTML: https://mlsanity.com/paper/2505.08542/

## Key facts

- Cited by 5 papers in the map (data through 14 Oct 2026).
- Builds on 17 of its 38 references that are in the map.
- First posted on arXiv 13 May 2025.

## Builds on (most cited first, 17 of 17)

- [BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding](https://mlsanity.com/paper/1810.04805/) (2018)
- [Chain-of-Thought Prompting Elicits Reasoning in Large Language Models](https://mlsanity.com/paper/2201.11903/) (2022)
- [A Survey on Large Language Models for Code Generation](https://mlsanity.com/paper/2406.00515/) (2024)
- [Harnessing the Power of LLMs in Practice: A Survey on ChatGPT and Beyond](https://mlsanity.com/paper/2304.13712/) (2023)
- [Recommender Systems in the Era of Large Language Models (LLMs)](https://mlsanity.com/paper/2307.02046/) (2023)
- [Synchromesh: Reliable code generation from pre-trained language models](https://mlsanity.com/paper/2201.11227/) (2022)
- [Structured Chain-of-Thought Prompting for Code Generation](https://mlsanity.com/paper/2305.06599/) (2023)
- [When MOE Meets LLMs: Parameter Efficient Fine-tuning for Multi-task Medical Applications](https://mlsanity.com/paper/2310.18339/) (2023)
- [Slither: A Static Analysis Framework For Smart Contracts](https://mlsanity.com/paper/1908.09878/) (2019)
- [Taiyi: A Bilingual Fine-Tuned Large Language Model for Diverse Biomedical Tasks](https://mlsanity.com/paper/2311.11608/) (2023)
- [Smart Contract Templates: foundations, design landscape and research directions](https://mlsanity.com/paper/1608.00771/) (2016)
- [Retrofitting Temporal Graph Neural Networks with Transformer](https://mlsanity.com/paper/2409.05477/) (2024)
- [Efficacy of Various Large Language Models in Generating Smart Contracts](https://mlsanity.com/paper/2407.11019/) (2024)
- [Learning Diffusions under Uncertainty](https://mlsanity.com/paper/2312.07942/) (2023)
- [TreeCSS: An Efficient Framework for Vertical Federated Learning](https://mlsanity.com/paper/2408.01691/) (2024)
- [Tool Demonstration: FSolidM for Designing Secure Ethereum Smart Contracts](https://mlsanity.com/paper/1802.09949/) (2018)
- [Smart Contract Design Meets State Machine Synthesis: Case Studies](https://mlsanity.com/paper/1906.02906/) (2019)

## Built on by (most cited first, 5 of 5)

- [SoK: Security and Privacy of AI Agents for Blockchain](https://mlsanity.com/paper/2509.07131/) (2025)
- [On LLM-Assisted Generation of Smart Contracts from Business Processes](https://mlsanity.com/paper/2507.23087/) (2025)
- [Curriculum-Guided Reinforcement Learning for Synthesizing Gas-Efficient Financial Derivatives Contracts](https://mlsanity.com/paper/2509.23976/) (2025)
- [LLMs + Security = Trouble](https://mlsanity.com/paper/2602.08422/) (2026)
- [An end-to-end agentic pipeline for smart contract translation and quality evaluation](https://mlsanity.com/paper/2602.13808/) (2026)

## Abstract (arXiv)

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