arXiv:2608.22345cs.CRAug 2026

Manuscript Offprint

arXiv:2608.22345

Mitigating Error Propagation in Chain-of-Thought: A Tree-of-Thought Framework for Smart Contract Repair

Jingping Zhu, Hongping Wang, Xiaoqi Li

ABSTRACT

Smart contracts power blockchain applications such as DeFi and NFTs. However, once deployed, they cannot be modified. Even minor bugs can result in significant financial losses. Current AI-based repair methods rely on linear reasoning, which leads to the accumulation of errors and unreliable patches. Our method combines document parsing, static analysis, and Tree of Thoughts reasoning. We first convert audit reports into structured data. Then we use Slither to locate the exact vulnerable code. Our three-step framework explores multiple repair paths simultaneously, evaluates options, and eliminates poor choices. Finally, we verify patches through compilation and manual checks. We test our method on 50 real vulnerabilities from Code4Rena. Our method achieves a 62% single success rate and an 84% top-3 success rate, outperforming ContractTinker by 12 and 6 percentage points, respectively. We also increase the proportion of fully effective patches to 44%, while reducing defective patches from 38% to 22% and invalid patches from 10% to 4%. This approach overcomes the limitations of linear reasoning and makes smart contract repair more accurate and practical.

Keywords Vulnerability Repair · Tree of Thoughts · Large Language Models

1 Introduction

Blockchain technology has transformed traditional business practices in fields such as finance, supply chain management, digital assets, government services, and intelligent transportation [1]. Smart contracts are a core application of blockchain, they significantly reduce transaction costs, improve execution efficiency, and enable trusted transactions without the need for third parties. Since Ethereum’s launch, over 50 million smart contracts have been deployed on the Ethereum mainnet alone, providing technical support for the circulation of digital assets and applications such as DeFi, NFTs, gambling applications, and the metaverse [2, 3]. However, this scale of growth has also brought greater security risks [4, 5, 6]. Once deployed, smart contracts are difficult to modify, leaving vulnerabilities exposed in the public domain for extended periods. Attackers who discover vulnerabilities can exploit them repeatedly, causing cascading losses [7, 8]. In 2016, the infamous The DAO attack exploited a reentrancy vulnerability to steal approximately 60millionworthofEther,directlyleadingtoahardforkoftheEthereumblockchain.In2023,theCurveFinanceprotocolwasattackedduetoanintegeroverflowvulnerability,resultinginlossesexceeding60 million worth of Ether, directly leading to a hard fork of the Ethereum blockchain. In 2023, the Curve Finance protocol was attacked due to an integer overflow vulnerability, resulting in losses exceeding70 million. In recent years, numerous techniques for identifying smart contract vulnerabilities have emerged [9, 10, 11, 12, 13, 14]. While these methods are effective at pinpointing issues [15], vulnerability fixes primarily rely on manual effort. Developers must analyze the root causes of vulnerabilities, assess their impact, and then write and verify patch code. When projects undergo frequent iterations or contract logic is complex, this process can significantly prolong the time required for fixes. Additionally, some developers lack security experience and may introduce new defects during the repair process [16].

In recent years, advancements in large language models and multi-agent technologies have provided new approaches to the automated repair of smart contract vulnerabilities. The powerful capabilities of large language models in code understanding and generation allow them to learn vulnerability patterns and repair methods from vast amounts of code.

and security data, they have already demonstrated practical utility in program repair tasks. However, existing large language model-based methods for repairing smart contract vulnerabilities are still not fully mature. Models may suffer from hallucination, generating patches that appear reasonable but are actually incorrect. When domain knowledge of smart contracts is lacking, patches may deviate from business requirements. Linear, single-path reasoning makes results highly sensitive to prompts and context, leading to significant fluctuations in patch quality. At the same time, many methods lack rigorous patch verification steps, making it difficult to promptly detect cases where a fix “appears to resolve the issue but actually introduces new risks.” In contrast, traditional template or search-driven methods are more stable but have limited coverage, low generation efficiency, and insufficient capability to handle vulnerabilities involving complex control flows or cross-function dependencies. Therefore, combining the reasoning capabilities of large language models with formal methods such as static code analysis to improve accuracy and verifiability while ensuring efficiency is a key technical challenge that needs to be addressed in the current field of smart contract automatic repair. This paper focuses on this issue and proposes a thought-tree-based method for the automatic repair of smart contract vulnerabilities. By generating and filtering multiple path candidates, this method mitigates the problem of inconsistent patch quality, providing a more reliable automated solution for smart contract security. It addresses issues in existing smart contract vulnerability auto-repair methods, such as significant fluctuations in patch quality, low repair success rates, and the lack of a verifiable patch validation process. This paper proposes an auto-repair method that combines structured document parsing, static program analysis, and multi-branch reasoning based on thought trees.

This paper makes the following contributions:

(1) We propose and implement a module for the structured parsing of audit reports. To address the inconsistencies in report formats across different audit agencies, this module employs multi-pattern regular expression matching and semantic segmentation to extract key information. From the text, it converts natural language reports into computable structured data and thereby reduces the comprehension costs associated with format heterogeneity.

(2) We build a Slither-based static analysis module. This module parses contract code to generate a function call graph, extracting program semantic information. Simultaneously, through multi-granularity matching, it maps vulnerability descriptions in natural language to specific code entities, providing large language models with more focused and accurate context, thereby reducing window pressure and interference from irrelevant information caused by directly inputting the entire contract.

(3) We design a vulnerability repair reasoning framework based on a thought tree to mitigate the problem of errors amplifying at each stage in a linear thought chain.

References (69)