Introduction
Smart contracts are self-executing programs on blockchain platforms that manage significant financial assets. Their immutability, while a core security feature, means that vulnerabilities cannot be easily patched once deployed. High-profile exploits, such as the DAO attack, underscore the critical need for robust vulnerability detection tools. BugSweeper is an end-to-end deep learning framework designed to detect these vulnerabilities directly from Solidity source code by leveraging a novel graph-based representation and a specialized two-stage Graph Neural Network (GNN).
The Vulnerability Challenge
Traditional security tools for smart contracts primarily rely on static analysis or symbolic execution. These methods use manually defined, expert-crafted rules to identify known bug patterns. However, they often struggle with novel attack variations and can produce high false-positive rates. Recent deep learning approaches have attempted to automate detection but frequently rely on rule-based preprocessing to "slice" code into manageable segments. This creates a trade-off: narrow rules may miss vital context, while broad rules introduce excessive noise that hinders model performance.
The BugSweeper Architecture
BugSweeper addresses these limitations by moving away from manual rule engineering toward a data-driven, two-stage approach.
1. Graph Construction: Function-Level Abstract Syntax Graphs (FLAGs)
Instead of treating code as simple text or basic trees, BugSweeper converts Solidity functions into Function-Level Abstract Syntax Graphs (FLAGs). This process begins with an Abstract Syntax Tree (AST) and augments it with explicit edges representing control-flow (execution paths) and data-flow (variable state changes). A "coverage" hyperparameter allows the graph to incorporate neighboring functions and variables, providing the necessary context for complex inter-function vulnerabilities.
2. Two-Stage GNN Processing
The framework employs a specialized architecture to process these graphs:
- Stage 1: Code Graph Neural Network (CGNN): This stage utilizes a novel Code Graph Pool (CGPool) method. Unlike generic pooling that might discard critical nodes, CGPool groups nodes based on their syntactic roles—for instance, merging nodes related to a specific function declaration into a single "supernode." This "denoises" the graph while preserving the underlying program logic.
- Stage 2: Second-Stage GNN: A Graph Attention Network (GAT) analyzes the simplified, pooled graphs. It assigns dynamic weights to the connections between supernodes, allowing the model to focus on the most critical relationships indicative of a vulnerability.
Experimental Evaluation
BugSweeper was evaluated on two major benchmarks: the AME Dataset (1,224 contracts focused on reentrancy) and the SmartBugs Wild Dataset (over 47,000 real-world files). Labels for the latter were established using a consensus approach among existing heuristic tools.
Key Results
BugSweeper demonstrated state-of-the-art performance across multiple vulnerability types:
- Reentrancy Detection: Achieved an F1-score of 98.57% on the AME dataset, a 3.1% improvement over previous models.
- Multi-Class Performance: On the SmartBugs Wild dataset, the model reached F1-scores of 91.61% for reentrancy, 80.15% for unchecked calls, and 79.63% for time manipulation.
- Ablation Studies: The two-stage architecture consistently outperformed single-stage baselines, confirming that the "summarization" step in the first stage is vital for high-level reasoning.
Conclusion
BugSweeper represents a significant advancement in automated smart contract security. By utilizing semantic-aware pooling and rich graph representations, it reduces reliance on expert-crafted rules and improves detection accuracy. Future research will focus on addressing data imbalance for rarer vulnerability types and expanding the framework to cover the full spectrum of the Smart Contract Weakness Classification (SWC) registry.
Summary updated