LLMs Struggle with Smart Contract Code Reliability, Study Finds

In the rapidly evolving landscape of blockchain technology, smart contracts have emerged as a critical component, enabling secure and transparent transactions without intermediaries. Solidity, a programming language specifically designed for writing smart contracts, has become the dominant language in this space. However, the unique constraints of smart contracts, such as gas consumption, security, and determinism, pose significant challenges for code generation. A team of researchers from the University of Molise in Italy, led by Francesco Salzano, has delved into the capabilities of large language models (LLMs) in generating reliable Solidity code, shedding light on the current limitations and potential improvements.

The study, published in the journal Empirical Software Engineering, benchmarks four state-of-the-art LLMs under two different settings: zero-shot and retrieval-augmented generation (RAG). The researchers evaluated the models across 500 real-world functions, employing a multi-faceted assessment that included code similarity metrics, semantic embeddings, automated test execution, gas profiling, and cognitive and cyclomatic complexity analysis.

The findings reveal that while LLMs excel at producing code with high semantic similarity to real contracts, their functional correctness is notably low. Only 20% to 26% of zero-shot generations behaved identically to ground-truth implementations under testing. The generated code was consistently simpler, with significantly lower complexity and gas consumption, often due to omitted validation logic. This discrepancy highlights a significant gap between semantic similarity and functional plausibility in LLM-generated smart contracts.

Retrieval-Augmented Generation, however, markedly improved performance. By providing the models with relevant context and examples, functional correctness was boosted by up to 45%, and the generated code was more concise and efficient. Despite these improvements, achieving robust, production-ready code generation remains a substantial challenge. The researchers emphasize the need for careful expert validation to ensure the reliability and security of smart contracts.

For the energy sector, which is increasingly exploring blockchain technology for applications such as peer-to-peer energy trading and renewable energy certificates, these findings are particularly relevant. As the industry moves towards more decentralized and transparent energy systems, the ability to generate reliable and efficient smart contracts will be crucial. The insights from this study underscore the importance of leveraging advanced techniques like RAG and the necessity of expert oversight in developing smart contracts for energy applications.

This article is based on research available at arXiv.

Scroll to Top
×