Papers
Topics
Authors
Recent
Gemini 2.5 Flash
Gemini 2.5 Flash
144 tokens/sec
GPT-4o
7 tokens/sec
Gemini 2.5 Pro Pro
45 tokens/sec
o3 Pro
4 tokens/sec
GPT-4.1 Pro
38 tokens/sec
DeepSeek R1 via Azure Pro
28 tokens/sec
2000 character limit reached

Guiding LLM-based Smart Contract Generation with Finite State Machine (2505.08542v1)

Published 13 May 2025 in cs.AI

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

Summary

Guiding LLM-based Smart Contract Generation with Finite State Machines

The paper "Guiding LLM-based Smart Contract Generation with Finite State Machine" introduces FSM-SCG, a framework integrating Finite State Machines (FSM) with LLMs to enhance the quality and security of smart contract generation. Smart contracts are essential for deploying decentralized applications on blockchain platforms, and their correct and secure generation poses significant challenges due to the required precision and the high stakes involved.

Motivation and Approach

The traditional approach to smart contract development involves manual coding and expert audits, both of which are resource-intensive and error-prone. While LLMs have shown promise in automating code generation, they often struggle with domain-specific requirements such as smart contract security and correctness. The authors of the paper propose leveraging FSMs as an intermediate representation to bridge user requirements and smart contract code. This inclusion addresses critical challenges in generation tasks: improving the overall effectiveness and bolstering security by guiding the LLM in a structured manner.

FSM-SCG Framework

The FSM-SCG framework operates in several phases:

  1. Requirement Processing: User requirements are transformed into prompts that the LLM can interpret to generate an FSM model.
  2. FSM Generation: The model, enhancing traditional Mealy FSMs, includes components like states, triggers, and transitions, specifically tailored to represent smart contract logic.
  3. FSM Validation: The generated FSM undergoes format and graph checks to ensure syntactic integrity and logical consistency.
  4. Smart Contract Generation and Refinement: Using the verified FSM, smart contracts are generated. They are then iteratively refined with feedback from compilation and security analysis to enhance reliability.
  5. Feedback Mechanism: Compilation and security checks are conducted using tools like Slither, and feedback is incorporated to iteratively correct identified issues, which significantly increases the compilation success rate (CPR) and reduces the vulnerability risk score (VRS).

Experimental Results

The experimental evaluation reveals substantial improvements when the proposed FSM-SCG framework is compared against baseline methods for smart contract generation. Key results include:

  • Compilation Success Rate: FSM-SCG achieves up to a 95.1% CPR with LlaMa3.1-8B, outperforming other methods by a substantial margin.
  • Security Metrics: The framework reduces the average vulnerability risk score by approximately 68% compared to the best-performing baseline, highlighting its effectiveness in generating more secure contracts.

Implications and Future Directions

The introduction of FSM as an intermediary step in LLM-driven smart contract generation offers significant theoretical and practical benefits. Theoretically, it underlines the importance of structured intermediates in mitigating the domain-specific limitations of LLMs. Practically, FSM-SCG provides a robust method for improving smart contract development, making it more accessible and reliable.

Looking forward, advancements in LLM technology combined with methodologies like FSM-SCG could drastically alter the landscape of software engineering for decentralized applications. The paper opens up several avenues for further exploration, such as optimizing the FSM construction process, improving the LLM training datasets to better capture state transitions, and refining the feedback mechanism for more complex contract logic. The integration of these components could potentially automate the rigorous demands of smart contract verification and construction with higher efficiency and dependability.

X Twitter Logo Streamline Icon: https://streamlinehq.com