BugSweeper: Function-Level Detection of Smart Contract Vulnerabilities Using Graph Neural Networks

Uisang Lee, Changhoon Chung, Junmo Lee, Soo-Mook Moon

TL;DR

BugSweeper is a new end-to-end deep learning framework that detects smart contract vulnerabilities directly from Solidity source code without relying on rigid, expert-crafted rules. By representing code as a novel "Function-Level Abstract Syntax Graph" (FLAG) and processing it through a specialized two-stage Graph Neural Network, it achieves state-of-the-art accuracy across multiple vulnerability types, including reentrancy and unchecked low-level calls.

What Problem Does This Paper Address?

Smart contracts are the backbone of decentralized finance, but their immutability is a double-edged sword: once deployed, a bug cannot be "patched" without a costly and complex redeployment. High-profile exploits like the DAO attack have shown that even a single oversight can lead to millions of dollars in losses.

Traditional security tools rely on static analysis or symbolic execution, which use manually defined rules to find known bug patterns. However, these tools struggle with novel attack variations. Recent deep learning approaches have tried to automate this, but they often use rule-based "preprocessing" to slice the code into manageable chunks. This creates a "catch-22": if the preprocessing rules are too narrow, the model misses context; if they are too broad, the model gets lost in the "noise" of irrelevant code.

An example of a reentrancy attack where a malicious contract repeatedly calls back into a vulnerable function.

Methods

The authors introduce BugSweeper, which moves away from manual engineering in favor of a data-driven, two-stage approach.

  1. Graph Construction (FLAG): Instead of simple text or basic trees, BugSweeper converts Solidity functions into Function-Level Abstract Syntax Graphs (FLAGs). These graphs start with an Abstract Syntax Tree (AST) and augment it with explicit control-flow (how the execution moves) and data-flow (how variables change) edges. A "coverage" hyperparameter allows the graph to include neighboring functions and variables, providing necessary context for complex inter-function bugs.
  2. Two-Stage GNN Architecture:
    • Stage 1: Code Graph Neural Network (CGNN). This stage uses a novel pooling method called Code Graph Pool (CGPool). Unlike generic graph pooling that might discard important nodes, CGPool groups nodes based on their syntactic roles (e.g., merging all nodes related to a specific function declaration into a single "supernode"). This effectively "denoises" the graph while preserving the program's logic.
  3. Stage 2: Second-Stage GNN. A Graph Attention Network (GAT) then analyzes these simplified, pooled graphs. It assigns dynamic weights to the connections between supernodes, allowing the model to focus on the most critical relationships that signal a vulnerability.
The overall architecture of BugSweeper, showing the transition from raw contracts to FA-ASGs, FLAGs, and finally vulnerability detection.

Datasets

The researchers evaluated BugSweeper on two major benchmarks:

  • AME Dataset: A specialized dataset of 1,224 smart contracts focused specifically on reentrancy vulnerabilities.
  • SmartBugs Wild Dataset: A massive collection of over 47,000 real-world Solidity files. To ensure high-quality labels, the authors used a "consensus" approach, labeling a contract as vulnerable only if multiple existing heuristic tools agreed on the bug. This dataset was used for multi-class detection (Reentrancy, Unchecked Low-Level Calls, and Time Manipulation).

Key Insights and Ideas

  • Context vs. Noise: The paper highlights that vulnerabilities often arise from how different functions interact. By using a "coverage" parameter, BugSweeper can look "next door" to related functions. The authors found that a coverage of 4 (including 3-hop neighbors) provided the best balance between rich context and manageable noise.
  • Semantic Pooling is Key: Standard graph pooling methods (like TopKPool) are "blind" to code structure. The authors' CGPool is deterministic and language-aware; it understands that a "FunctionDefinition" node is more important than a generic syntax node, leading to much better abstraction.
  • End-to-End is the Future: By removing the need for security experts to write "slicing" rules, BugSweeper becomes more adaptable to new, "zero-day" style variations of attacks that don't fit established patterns.

Key Results

BugSweeper significantly outperformed both traditional tools and previous deep learning models:

  • Reentrancy Detection: On the AME dataset, it achieved an F1-score of 98.57%, a 3.1% improvement over the previous state-of-the-art (AME).
  • Multi-Class Performance: On the SmartBugs Wild dataset, the "SAGE + GAT" configuration reached F1-scores of 91.61% for reentrancy, 80.15% for unchecked calls, and 79.63% for time manipulation.
  • Ablation Success: The two-stage architecture consistently beat single-stage baselines, proving that the "summarization" step performed by the first stage is vital for high-level reasoning.

Limitations and Future Work

While highly effective, BugSweeper's performance was slightly lower on "Unchecked Low-Level Calls" and "Time Manipulation" compared to reentrancy. The authors attribute this to data imbalance—there are simply fewer examples of these bugs in the wild to train on.

Future work could involve expanding the framework to cover a wider array of the "Smart Contract Weakness Classification" (SWC) registry and exploring techniques like data augmentation to help the model learn from rarer vulnerability types. Additionally, while the consensus-based labeling for SmartBugs Wild is robust, it still relies on the underlying accuracy of the heuristic tools used for the consensus.

Summary updated

BibTeX
@inproceedings{lee2026bugsweeper,
  author = {Uisang Lee and Changhoon Chung and Junmo Lee and Soo-Mook Moon},
  title = {{BugSweeper: Function-Level Detection of Smart Contract Vulnerabilities Using Graph Neural Networks}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2026},
  doi = {10.1609/aaai.v40i1.37021},
}
Figure