LLM-Powered Detection of Price Manipulation in DeFi

Lu Liu, Wuqi Zhang, Lili Wei, Hao Guan, Yongqiang Tian, Yepang LiuarXiv 2025 · DOI

Introduction

Decentralized Finance (DeFi) protocols rely heavily on price oracles to determine asset values. However, these oracles are susceptible to manipulation. Attackers often utilize "flash loans" to temporarily distort prices in liquidity pools, enabling them to borrow excessive funds or execute unfair swaps.

Existing detection mechanisms generally fall into two categories: post-mortem tools, which analyze attacks after financial loss has occurred, and static analysis tools, which are proactive but often limited by rigid, hand-crafted rules. These traditional tools frequently fail to capture "novel" attack variants or understand the underlying economic intent of the code, leading to high false-positive rates or missed vulnerabilities.

The PMDetector Framework

To address these challenges, we introduce PMDetector, a hybrid security framework that integrates static taint analysis with the semantic reasoning capabilities of Large Language Models (LLMs). PMDetector is designed to proactively identify price manipulation vulnerabilities by following a structured three-stage pipeline.

PMDetector Pipeline Architecture

The framework is guided by a formal five-phase attack model: Setup, Taint Introduction, Propagation, Value Extraction, and Cleanup. This model provides a systematic way to trace how manipulated inputs can lead to unauthorized value extraction.

Five-Phase Attack Model for Price Manipulation

Methodology

  1. Static Taint Analysis: Utilizing Slither Intermediate Representation (SlithIR), PMDetector identifies data flows where external, attacker-controlled inputs reach critical "sinks"—operations that modify ledgers or move assets. To optimize LLM costs, syntactically distinct but semantically similar paths are grouped into clusters.
  2. Two-Stage LLM Reasoning:
  3. Path Filtering: An LLM acts as a triage auditor, evaluating paths against a checklist of economic intent and existing mitigations to prune benign code.
  4. Attack Simulation: For high-risk paths, the LLM employs Chain-of-Thought (CoT) reasoning to construct detailed exploit scenarios, explaining the mechanism of potential profit for an attacker.
  5. Semantic Sanity Checker: To mitigate LLM hallucinations, a rule-based static checker validates the LLM's findings against known defense patterns, such as time-based cooldowns or privilege modifiers.

Evaluation and Results

PMDetector was evaluated against a comprehensive benchmark consisting of 73 real-world vulnerable protocols ($D_{vul}$) and 288 audited benign protocols ($D_{safe}$).

The results demonstrate significant improvements over state-of-the-art (SOTA) tools:

  • High Accuracy: Using GPT-4.1, PMDetector achieved 100% precision and 90% recall. Even with more cost-effective models like Gemini 2.5-flash, it maintained 88% precision.
  • Efficiency: The tool identifies vulnerabilities for approximately $0.03 per instance, taking only 4.0 seconds on average. This represents a massive reduction in cost compared to manual audits, which can exceed $10,000.
  • Real-World Impact: PMDetector successfully identified a previously unknown (zero-day) price manipulation vulnerability in a live contract, highlighting its practical utility for proactive security.

Discussion and Future Work

While PMDetector shows great promise, certain limitations remain. The static taint analysis can struggle with highly modular architectures (e.g., those using delegatecall), and the tool currently generates natural language reports rather than executable Proof-of-Concept (PoC) scripts.

Future developments will focus on integrating "mainnet forking" to provide LLMs with real-time on-chain context, such as actual liquidity balances, further enhancing the accuracy of attack simulations. By combining the precision of static analysis with the "intent-aware" reasoning of LLMs, PMDetector sets a new standard for automated DeFi security.

Summary updated

BibTeX
@misc{liu2025llm,
  author = {Lu Liu and Wuqi Zhang and Lili Wei and Hao Guan and Yongqiang Tian and Yepang Liu},
  title = {{LLM-Powered Detection of Price Manipulation in DeFi}},
  year = {2025},
  eprint = {2510.21272},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.21272},
}
Figure