# Two Timin': Repairing Smart Contracts With A Two-Layered Approach

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

## Key facts

- No citing papers in the map yet (data through 14 Oct 2026).
- Builds on 14 of its 22 references that are in the map.
- First posted on arXiv 14 Sep 2023.

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

- [Chain-of-Thought Prompting Elicits Reasoning in Large Language Models](https://mlsanity.com/paper/2201.11903/) (2022)
- [Slither: A Static Analysis Framework For Smart Contracts](https://mlsanity.com/paper/1908.09878/) (2019)
- [Do you still need a manual smart contract audit?](https://mlsanity.com/paper/2306.12338/) (2023)
- [Sci-CoT: Leveraging Large Language Models for Enhanced Knowledge Distillation in Small Models for Scientific QA](https://mlsanity.com/paper/2308.04679/) (2023)
- [Optimizing Machine Translation through Prompt Engineering: An Investigation into ChatGPT's Customizability](https://mlsanity.com/paper/2308.01391/) (2023)
- [Smart Contract Vulnerability Detection Technique: A Survey](https://mlsanity.com/paper/2209.05872/) (2022)
- [Defending Against Poisoning Attacks in Federated Learning with Blockchain](https://mlsanity.com/paper/2307.00543/) (2023)
- [SmartBugs 2.0: An Execution Framework for Weakness Detection in Ethereum Smart Contracts](https://mlsanity.com/paper/2306.05057/) (2023)
- [Elysium: Context-Aware Bytecode-Level Patching to Automatically Heal Vulnerable Smart Contracts](https://mlsanity.com/paper/2108.10071/) (2021)
- [Vulnerable Smart Contract Function Locating Based on Multi-Relational Nested Graph Convolutional Network](https://mlsanity.com/paper/2306.04479/) (2023)
- [Vulnerability Analysis of Smart Contracts](https://mlsanity.com/paper/2212.07387/) (2022)
- [Usenix'23 Extended Version: Smart Learning to Find Dumb Contracts](https://mlsanity.com/paper/2304.10726/) (2023)
- [Deep Smart Contract Intent Detection](https://mlsanity.com/paper/2211.10724/) (2022)
- [CONTRACTFIX: A Framework for Automatically Fixing Vulnerabilities in Smart Contracts](https://mlsanity.com/paper/2307.08912/) (2023)

## Abstract (arXiv)

Due to the modern relevance of blockchain technology, smart contracts present both substantial risks and benefits. Vulnerabilities within them can trigger a cascade of consequences, resulting in significant losses. Many current papers primarily focus on classifying smart contracts for malicious intent, often relying on limited contract characteristics, such as bytecode or opcode. This paper proposes a novel, two-layered framework: 1) classifying and 2) directly repairing malicious contracts. Slither's vulnerability report is combined with source code and passed through a pre-trained RandomForestClassifier (RFC) and Large Language Models (LLMs), classifying and repairing each suggested vulnerability. Experiments demonstrate the effectiveness of fine-tuned and prompt-engineered LLMs. The smart contract repair models, built from pre-trained GPT-3.5-Turbo and fine-tuned Llama-2-7B models, reduced the overall vulnerability count by 97.5% and 96.7% respectively. A manual inspection of repaired contracts shows that all retain functionality, indicating that the proposed method is appropriate for automatic batch classification and repair of vulnerabilities in smart contracts.
