Empirical Analysis of Prompt Engineering Strategies for Smart Contract Vulnerability Detection: A Multi-model Comparison
DOI:
https://doi.org/10.18178/JAAI.2026.4.1.1-10Keywords:
Smart contracts, vulnerability detection, large language models, prompt engineering, DeFi securityAbstract
Smart contract vulnerabilities have resulted in billions of dollars in losses across Decentralized Finance (DeFi) ecosystems. While recent work explores fine-tuned Large Language Models (LLMs) for vulnerability detection, little research systematically examines prompt engineering strategies with pre-trained models. This paper presents the first comprehensive empirical study comparing five code-understanding LLMs (CodeLlama, CodeBERT, InCoder, DeepSeek-Coder, StarCoder) for smart contract security analysis without fine-tuning. Through 15 experimental iterations testing different prompting approaches across 21 vulnerability types using real DeFi exploit patterns, we discover a strong inverse correlation between prompt complexity and detection success: simple prompts (200–400 characters) achieve 100% response reliability while complex structured prompts (1500+ characters) result in complete failure. Our multi-model comparison reveals dramatic architectural differences: CodeBERT and InCoder achieve 92% accuracy but 0% recall (classifying everything as safe), while CodeLlama demonstrates superior detection with 66.67% recall using few-shot learning. DeepSeek-Coder offers optimal balance with 33.33% recall at 6.1 s inference time. These findings establish baseline performance metrics for prompt-based approaches and provide practical deployment guidelines for security practitioners.
References
[1] Chainalysis. (2023). The 2023 Crypto Crime Report. Chainalysis Inc.
[2] Mueller, B. (2018). Mythril: Security Analysis Tool for Ethereum Smart Contracts [GitHub repository]. GitHub. Retrieved from https://github.com/ConsenSys/mythril
[3] Feist, J., Feist, F., Krupp, A., & Katz, D. (2019). Slither: A static analysis framework for smart contracts. Proceedings of 2019 IEEE/ACM International Workshop on Emerging Trends in Software Engineering for Blockchain (WETSEB) (pp. 8–15). IEEE.
[4] Tsankov, P., Dan, A., Drachsler-Cohen, D., Fisch, F., Gazzola, S., Bürgisser, E., & Vechev, M. (2018). Securify: Practical security analysis of smart contracts. Proceedings of the 2018 ACM SIGSAC Conference on Computer and Communications Security (pp. 67–82). ACM.
[5] Durieux, T., Naveh, E., & Feitelson, D. G. (2020). An empirical study on the effectiveness of static analysis tools for security vulnerability detection in Java and C code. Empirical Software Engineering, 25(6), 4052–4087.
[6] Ding, H., Liu, Y., Piao, X., Song, H., & Ji, Z. (2025). SmartGuard: An LLM-enhanced framework for smart contract vulnerability detection. Expert Systems with Applications, 266, 126479. https://doi.org/10.1016/j.eswa.2025.126479
[7] Bu, J., Li, W., Li, Z., Zhang, Z., & Li, X. (2025). Enhancing smart contract vulnerability detection in DApps leveraging fine-tuned LLM. arXiv preprint, arXiv:2504.05006.
[8] OpenAI. (2023). Prompt engineering guide. Retrieved from https://platform.openai.com/docs/guides/prompt-engineering
[9] Maiti, A., Adewumi, S., Tikure, T. A., Wang, Z., Sengupta, N., Sukhanova, A., & Jana, A. (March, 2025). Comparative analysis of OpenAI GPT-4o and DeepSeek R1 for scientific text categorization using prompt engineering. Presented at the 2025 ASEE North Central Section Annual Conference, Huntington, WV, United States. https://doi.org/10.18260/1-2--54654
[10] Grieco, G., Braun, L., & Braun, D. (2020). Echidna: Effective, usable, and fast fuzzing for smart contracts. Proceedings of the 29th ACM SIGSOFT International Symposium on Software Testing and Analysis (pp. 557–560). ACM.
[11] Wüstholz, M., & Christakis, C. (2020). Harvey: A greybox fuzzer for smart contracts. Proceedings of the 28th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering (pp. 1398–1409). ACM.
[12] Bhargavan, K., Delignat-Lavaud, A., Fournet, C., & Médard, M. (2016). Formal verification of smart contracts. Proceedings of the 2016 ACM Workshop on Programming Languages and Analysis for Security (pp. 91–96). ACM.
[13] Kalra, S., Goel, S., Govindarajan, M., & Kannan, S. P. (2018). Zeus: Analyzing safety of smart contracts. Proceedings of the Network and Distributed System Security Symposium (NDSS).
[14] Momeni, M., Gharaee, M., & Rezazadeh, M. (2019). Machine learning model for smart contracts security analysis. Proceedings of 2019 International Congress on Technology, Communication and Knowledge (ICTCK) (pp. 1–6). IEEE.
[15] Qian, Z., Zhao, Y., & Li, X. (2020). Towards automated reentrancy detection for smart contracts based on sequential models. IEEE Access, 8, 96685–96695.
[16] Zhuang, L., Liang, Z., & Cui, B. (2020). Smart contract vulnerability detection using graph neural network. Proceedings of the Twenty-Ninth International Joint Conference on Artificial Intelligence (pp. 3283–3290).
[17] Wang, W., Zhong, Y., Jiang, H., & Zheng, F. (2021). ContractWard: Automated vulnerability detection models for Ethereum smart contracts. IEEE Transactions on Network Science and Engineering, 8(2), 1133–1144.
[18] Feng, Z., Jiang, H., Huang, Z., & Zhang, X. (2020). CodeBERT: A pre-trained model for programming and natural languages. Proceedings of Findings of the Association for Computational Linguistics: EMNLP 2020 (pp. 1536–1547). Association for Computational Linguistics.
[19] Pearce, H., Rodrigues, D., & Pereira, F. (2022). Asleep at the keyboard? Assessing the security of GitHub Copilot’s code contributions. Proceedings of 2022 IEEE Symposium on Security and Privacy (SP) (pp. 754–768). IEEE.
[20] Microsoft. (September 30, 2025). Secure AI by Design Series: Embedding Security and Governance Across the AI Lifecycle. Microsoft Defender for Cloud Blog. Retrieved from https://techcommunity.microsoft.com/blog/microsoftdefendercloudblog/secure-ai-by-design-series-embedding-security-and-governance-across-the-ai-lifec/4457200
[21] Microsoft. (2023). Azure OpenAI Service documentation. Retrieved from https://learn.microsoft.com/azure/ai-services/openai/
Downloads
Published
Issue
Section
License
Copyright (c) 2026 by the authors.

This work is licensed under a Creative Commons Attribution 4.0 International License.