Dissect-and-Restore: AI-based Code Verification with Transient Refactoring

Changjie Wang, Mariano Scazzariello, Anoud Alshnakat, Roberto Guanciale, Dejan Kostic, Marco ChiesaarXiv 2025 · DOI

Abstract

Formal verification is the gold standard for software reliability, yet it remains a significant challenge for Large Language Models (LLMs) due to the "reasoning wall" encountered with complex, nested code structures. We present Prometheus, a system that utilizes a "Dissect-and-Restore" strategy to bridge this gap. By transiently refactoring complex logic into modular sub-methods and decomposing proofs into a hierarchy of simpler lemmas, Prometheus enhances verification success rates from 68% to 86% on challenging algorithmic tasks. Notably, it achieves a 100% success rate on nested loop benchmarks, demonstrating a scalable path for automated formal verification.

Introduction

Formal verification involves mathematically proving that code adheres to a specific formal requirement. While tools like Dafny automate parts of this process, they require developers to provide intricate loop invariants and auxiliary lemmas. LLMs, despite their proficiency in code generation, often fail at verification because they struggle to coordinate multiple logical steps simultaneously, leading to hallucinations or search space exhaustion in complex programs. Prometheus addresses this "reasoning gap" by simplifying the problem space through structural decomposition.

Methodology: The Dissect-and-Restore Strategy

Prometheus operates on the principle that modularity is not just for human readability but serves as a critical anchor for AI reasoning. The system employs three core mechanisms:

1. Code-level Decomposition (Transient Refactoring)

Prometheus identifies complex structures, such as nested loops, and performs "loop lifting." This process refactors messy code into smaller, named sub-methods with clear pre- and post-conditions. This refactoring is transient: it is used to isolate logic for the LLM to verify, and once a proof is found, it is mapped back to the original code structure.

The Prometheus pipeline: from modularization of complex code to sub-method verification and final code restoration.

2. Proof-level Decomposition

Instead of attempting to prove a massive property in one step, Prometheus breaks the proof into a tree of structured helper lemmas. If an assertion fails, the system prompts the LLM to generate a specific sub-lemma to bridge that logical gap, preventing state explosion.

The system utilizes a Depth-First Search (DFS) approach combined with a "simulated annealing" temperature schedule. It attempts to verify a node in the proof tree; upon failure, it uses verifier error messages to re-prompt the LLM. If a path remains blocked, the system rolls back to explore alternative decomposition strategies.

The Prometheus verification tree and feedback loop, illustrating how the system explores sub-lemmas and handles verification errors.

Experimental Evaluation

The researchers evaluated Prometheus across several rigorous datasets:

  • MBPP-DFY-153: 90 programs requiring non-trivial Dafny annotations.
  • TitanBench: A new benchmark of 22 complex LeetCode-style algorithmic tasks (e.g., "MaxSub"), 12 of which contain nested loops.
  • Complex Algorithm Set: 8 high-complexity programs requiring over 200 lines of verification code (LOVC).

Key Results

  • Performance Gains: On TitanBench, Prometheus achieved an 86% success rate, significantly outperforming the 68% baseline.
  • Nested Loop Mastery: Prometheus solved 100% (10/10) of the nested loop tasks in TitanBench, compared to only 60% for the baseline.
  • Scalability: The system successfully verified 7 out of 8 tasks in the high-complexity set, generating over 1,000 lines of verification code in some instances—a scale previously unreachable for automated systems.
  • Human-AI Synergy: When provided with a lightweight natural language "proof outline," the success rate on the most difficult tasks rose from 25% to 87%.

Discussion and Conclusion

A primary insight from this work is that modularity prevents the "state explosion" that typically occurs in nested logic. Furthermore, Prometheus demonstrates that many verification failures are due to SMT solver "quirks" rather than flawed logic; the system overcomes these by generating "surgical assertions" to guide the solver through tricky sequence or set operations.

Despite these successes, challenges remain. The system assumes the initial formal specification is correct, and search times for extremely complex programs can be high. Future work will focus on improving lemma reusability and further pushing the complexity ceiling that even modular decomposition eventually encounters.

Summary updated

BibTeX
@misc{wang2025dissect,
  author = {Changjie Wang and Mariano Scazzariello and Anoud Alshnakat and Roberto Guanciale and Dejan Kostic and Marco Chiesa},
  title = {{Dissect-and-Restore: AI-based Code Verification with Transient Refactoring}},
  year = {2025},
  eprint = {2510.25406},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.25406},
}
Figure