StateGuard: Detecting State Derailment Defects in Decentralized Exchange Smart Contract
Zongwei Li, Wenkai Li, Xiaoqi Li, Yuqing Zhang
TL;DR
This work tackles the challenge of state derailment defects in decentralized exchange (DEX) smart contracts, where complex multi-contract state logic can lead to unauthorized or incorrect state changes. It introduces StateGuard, a deep learning framework that converts contract code to ASTs, extracts five dependency features to represent state relationships, and uses a Graph Convolutional Network to detect defects across multi-contract DEX projects. Experimental results on 46 DEX projects (5,671 contracts) show high performance (accuracy around 94%, precision around 98%), and StateGuard identifies novel real-world CVEs (e.g., CVE-2023-47033/47034/47035) that other tools miss, highlighting practical impact for DeFi security. The approach is open-sourced, demonstrating real-world applicability for auditing large-scale smart-contract ecosystems.
Abstract
Decentralized Exchanges (DEXs), leveraging blockchain technology and smart contracts, have emerged in decentralized finance. However, the DEX project with multi-contract interaction is accompanied by complex state logic, which makes it challenging to solve state defects. In this paper, we conduct the first systematic study on state derailment defects of DEXs. These defects could lead to incorrect, incomplete, or unauthorized changes to the system state during contract execution, potentially causing security threats. We propose StateGuard, a deep learning-based framework to detect state derailment defects in DEX smart contracts. StateGuard constructs an Abstract Syntax Tree (AST) of the smart contract, extracting key features to generate a graph representation. Then, it leverages a Graph Convolutional Network (GCN) to discover defects. Evaluating StateGuard on 46 DEX projects with 5,671 smart contracts reveals its effectiveness, with a precision of 92.24%. To further verify its practicality, we used StateGuard to audit real-world smart contracts and successfully authenticated multiple novel CVEs.
