Efficient Avoidance of Vulnerabilities in Auto-completed Smart Contract Code Using Vulnerability-constrained Decoding
Not on the map. Why?
Abstract (arXiv)
Auto-completing code enables developers to speed up coding significantly. Recent advances in transformer-based large language model (LLM) technologies have been applied to code synthesis. However, studies show that many of such synthesized codes contain vulnerabilities. We propose a novel vulnerability-constrained decoding approach to reduce the amount of vulnerable code generated by such models. Using a small dataset of labeled vulnerable lines of code, we fine-tune an LLM to include vulnerability labels when generating code, acting as an embedded classifier. Then, during decoding, we deny the model to generate these labels to avoid generating vulnerable code. To evaluate the method, we chose to automatically complete Ethereum Blockchain smart contracts (SCs) as the case study due to the strict requirements of SC security. We first fine-tuned the 6-billion-parameter GPT-J model using 186,397 Ethereum SCs after removing the duplication from 2,217,692 SCs. The fine-tuning took more than one week using ten GPUs. The results showed that our fine-tuned model could synthesize SCs with an average BLEU (BiLingual Evaluation Understudy) score of 0.557. However, many codes in the auto-completed SCs were vulnerable. Using the code before the vulnerable line of 176 SCs containing different types of vulnerabilities to auto-complete the code, we found that more than 70% of the auto-completed codes were insecure. Thus, we further fine-tuned the model on other 941 vulnerable SCs containing the same types of vulnerabilities and applied vulnerability-constrained decoding. The fine-tuning took only one hour with four GPUs. We then auto-completed the 176 SCs again and found that our approach could identify 62% of the code to be generated as vulnerable and avoid generating 67% of them, indicating the approach could efficiently and effectively avoid vulnerabilities in the auto-completed code.
Key facts. Cited by 14 papers in the map (data through 14 Oct 2026). Builds on 26 of its 44 references that are in the map. First posted on arXiv 18 Sep 2023.
Builds on
26 of 44 references.
References · 26
- 2022Training language models to follow instructions with human feedbackcited by 15,971
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2021RoFormer: Enhanced Transformer with Rotary Position Embeddingcited by 4,703
- 2020The Pile: An 800GB Dataset of Diverse Text for Language Modelingcited by 2,411
- 2018Deep contextualized word representationscited by 2,290
- 2022Competition-Level Code Generation with AlphaCodecited by 1,462
- 2021Offline Reinforcement Learning as One Big Sequence Modeling Problemcited by 644
- 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 479
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 431
- 2022CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learningcited by 358
- 2018code2vec: Learning Distributed Representations of Codecited by 250
- 2017Lexically Constrained Decoding for Sequence Generation Using Grid Beam Searchcited by 237
14 more
- 2017Beam Search Strategies for Neural Machine Translationcited by 232
- 2018Fast Lexically Constrained Decoding with Dynamic Beam Allocation for Neural Machine Translationcited by 182
- 2018The Adverse Effects of Code Duplication in Machine Learning Models of Codecited by 126
- 2023Execution-based Code Generation using Deep Reinforcement Learningcited by 99
- 2019Slither: A Static Analysis Framework For Smart Contractscited by 89
- 2023How Secure is Code Generated by ChatGPT?cited by 81
- 2022PanGu-Coder: Program Synthesis with Function-Level Language Modelingcited by 48
- 2019Empirical Review of Automated Analysis Tools on 47,587 Ethereum Smart Contractscited by 36
- 2023Beyond the Safeguards: Exploring the Security Risks of ChatGPTcited by 36
- 2018ContractFuzzer: Fuzzing Smart Contracts for Vulnerability Detectioncited by 32
- 2020How Effective are Smart Contract Analysis Tools? Evaluating Smart Contract Static Analysis Tools Using Bug Injectioncited by 20
- 2020sFuzz: An Efficient Adaptive Fuzzer for Solidity Smart Contractscited by 19
- 2021Detecting Gender Bias in Transformer-based Models: A Case Study on BERTcited by 8
- 2022Secure-by-Construction Synthesis of Cyber-Physical Systemscited by 1
Built on by
Citing papers per year: 2024: 6; 2025: 6; 2026: 2.
14 papers.
Sort:
By area:
- 2024When LLMs Meet Cybersecurity: A Systematic Literature Reviewcited by 71
- 2024Constrained Decoding for Secure Code Generationcited by 37
- 2024From Vulnerabilities to Remediation: A Systematic Literature Review of LLMs in Code Securitycited by 10
- 2024Smart-LLaMA: Two-Stage Post-Training of Large Language Models for Smart Contract Vulnerability Detection and Explanationcited by 8
- 2025SCALM: Detecting Bad Practices in Smart Contracts Through LLMscited by 8
- 2025Smart-LLaMA-DPO: Reinforced Large Language Model for Explainable Smart Contract Vulnerability Detectioncited by 7
- 2024Blockchain Meets LLMs: A Living Survey on Bidirectional Integrationcited by 2
- 2025CodeBC: A More Secure Large Language Model for Smart Contract Code Generation in Blockchaincited by 2
- 2024DISL: Fueling Research with A Large Dataset of Solidity Smart Contractscited by 1
- 2025Towards Secure and Explainable Smart Contract Generation with Security-Aware Group Relative Policy Optimizationcited by 1
- 2025Towards Automated Smart Contract Generation: Evaluation, Benchmarking, and Retrieval-Augmented Repaircited by 0
- 2025Learning to Guarantee Type Correctness in Code Generation through Type-Guided Program Synthesiscited by 0
2 more
- 2026STELP: Secure Transpilation and Execution of LLM-Generated Programscited by 0
- 2026LLMs + Security = Troublecited by 0
- 2026LLMs + Security = Trouble9 Feb 2026
- 2026STELP: Secure Transpilation and Execution of LLM-Generated Programs9 Jan 2026
- 2025Learning to Guarantee Type Correctness in Code Generation through Type-Guided Program Synthesis11 Oct 2025
- 2025Towards Secure and Explainable Smart Contract Generation with Security-Aware Group Relative Policy Optimization12 Sep 2025
- 2025Smart-LLaMA-DPO: Reinforced Large Language Model for Explainable Smart Contract Vulnerability Detection23 Jun 2025
- 2025CodeBC: A More Secure Large Language Model for Smart Contract Code Generation in Blockchain28 Apr 2025
- 2025Towards Automated Smart Contract Generation: Evaluation, Benchmarking, and Retrieval-Augmented Repair3 Mar 2025
- 2025SCALM: Detecting Bad Practices in Smart Contracts Through LLMs4 Feb 2025
- 2024From Vulnerabilities to Remediation: A Systematic Literature Review of LLMs in Code Security19 Dec 2024
- 2024Blockchain Meets LLMs: A Living Survey on Bidirectional Integration25 Nov 2024
- 2024Smart-LLaMA: Two-Stage Post-Training of Large Language Models for Smart Contract Vulnerability Detection and Explanation9 Nov 2024
- 2024When LLMs Meet Cybersecurity: A Systematic Literature Review6 May 2024
2 more
- 2024Constrained Decoding for Secure Code Generation30 Apr 2024
- 2024DISL: Fueling Research with A Large Dataset of Solidity Smart Contracts25 Mar 2024
- 2024When LLMs Meet Cybersecurity: A Systematic Literature Reviewcited by 71
- 2024Constrained Decoding for Secure Code Generationcited by 37
- 2024From Vulnerabilities to Remediation: A Systematic Literature Review of LLMs in Code Securitycited by 10
- 2024Smart-LLaMA: Two-Stage Post-Training of Large Language Models for Smart Contract Vulnerability Detection and Explanationcited by 8
- 2025SCALM: Detecting Bad Practices in Smart Contracts Through LLMscited by 8
- 2024Blockchain Meets LLMs: A Living Survey on Bidirectional Integrationcited by 2
- 2025CodeBC: A More Secure Large Language Model for Smart Contract Code Generation in Blockchaincited by 2
- 2024DISL: Fueling Research with A Large Dataset of Solidity Smart Contractscited by 1
- 2025Towards Automated Smart Contract Generation: Evaluation, Benchmarking, and Retrieval-Augmented Repaircited by 0
- 2025Learning to Guarantee Type Correctness in Code Generation through Type-Guided Program Synthesiscited by 0
- 2026LLMs + Security = Troublecited by 0
- 2026LLMs + Security = Trouble9 Feb 2026
- 2025Learning to Guarantee Type Correctness in Code Generation through Type-Guided Program Synthesis11 Oct 2025
- 2025CodeBC: A More Secure Large Language Model for Smart Contract Code Generation in Blockchain28 Apr 2025
- 2025Towards Automated Smart Contract Generation: Evaluation, Benchmarking, and Retrieval-Augmented Repair3 Mar 2025
- 2025SCALM: Detecting Bad Practices in Smart Contracts Through LLMs4 Feb 2025
- 2024From Vulnerabilities to Remediation: A Systematic Literature Review of LLMs in Code Security19 Dec 2024
- 2024Blockchain Meets LLMs: A Living Survey on Bidirectional Integration25 Nov 2024
- 2024Smart-LLaMA: Two-Stage Post-Training of Large Language Models for Smart Contract Vulnerability Detection and Explanation9 Nov 2024
- 2024When LLMs Meet Cybersecurity: A Systematic Literature Review6 May 2024
- 2024Constrained Decoding for Secure Code Generation30 Apr 2024
- 2024DISL: Fueling Research with A Large Dataset of Solidity Smart Contracts25 Mar 2024