Skip to content
Crypto.world

Research

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

Smart contracts cannot be patched after deployment, so vulnerabilities must be caught before shipping, yet most automated detectors depend on hand-written expert rules that miss novel attack variants…

BugSweeper: Function-Level Detection of Smart Contract Vulnerabilities Using Graph Neural Networks
arXiv
2512.09385
Published
2025-12-10
Authors
Uisang Lee, Changhoon Chung, Junmo Lee, Soo-Mook Moon

AI summary

Overview

Research area: Blockchain security — automated smart contract vulnerability detection using deep learning (graph neural networks) over Solidity source code.

Technical level: Advanced. The paper assumes familiarity with abstract syntax trees, control-flow and data-flow graphs, and graph neural network architectures (GraphSAGE, graph attention networks, graph pooling).

Scope: The paper introduces BugSweeper, a rule-free, function-level vulnerability detector that converts Solidity functions into enriched syntax graphs and classifies them with a two-stage GNN.

What This Paper Is About

Smart contracts cannot be patched after deployment, so vulnerabilities must be caught before shipping, yet most automated detectors depend on hand-written expert rules that miss novel attack variants and discard source-code context. BugSweeper aims to remove those handcrafted rules entirely: it parses each function into a graph that preserves syntax, control flow and data flow, then lets a two-stage graph neural network learn vulnerability patterns directly from labelled code. The goal is a single framework that detects several vulnerability types in an end-to-end, data-driven way.

Key Contributions

  1. A rule-free, multi-class detection framework. BugSweeper is presented as the first unified, rule-free framework that detects multiple vulnerability classes directly from code structure, demonstrated on three types: reentrancy, unchecked low-level calls, and time manipulation.

  2. The Function-Level Abstract Syntax Graph (FLAG). A new graph representation that decomposes a contract's AST into per-function subgraphs and augments them with explicit control-flow edges (CondTrue, CondFalse, WhileExecution, ForExecution, WhileNext, ForNext, NextStatement) and data-flow edges (ReferencedDeclaration, FunctionReturnParameter, SuperFunction, Assignment), plus basic Child/Parent edges.

  3. A two-stage GNN architecture with a domain-specific pooling operator. A Code Graph Neural Network (CGNN) using GraphSAGE and a novel deterministic Code Graph Pool (CGPool) reduces AST-level noise by merging syntactically related nodes into supernodes; a second-stage Graph Attention Network then reasons over the compacted "Pooled FLAG."

  4. The coverage hyperparameter. A tunable control on how many hops of inter-function neighbourhood expansion are included in each FLAG (coverage 1 = the function alone; coverage 2 = direct callees and referenced variables; and so on).

Main Findings

  • Reentrancy detection beats all baselines on the AME dataset. BugSweeper reaches 99.87% precision, 97.35% recall and 98.57% F1, versus the closest competitor AME at 95.45% / 95.38% / 95.42% F1 — a gap the authors describe as approximately 3.1%.

  • Traditional tools have low recall on reentrancy. Slither scores 94.74% precision but only 34.62% recall (50.70% F1); SmartCheck 88.57 / 55.36 / 68.13; Mythril 84.48 / 47.12 / 60.49; Slise 95.56 / 45.26 / 61.43. Deep learning baselines are stronger: TMP 87.06 / 83.74 / 85.36, Peculiar 92.58 / 94.40 / 93.48, ReVulDL 92.95 / 94.62 / 93.74.

  • Two stages beat one stage. On SmartBugs Wild at coverage 4, the best two-stage configuration (SAGE + GAT) reaches F1 of 91.61% (reentrancy), 80.15% (unchecked low-level calls) and 79.63% (time manipulation), versus single-stage baselines such as GAT at 84.77% / 71.43% / 74.72% and GraphSAGE at 83.11% / 66.20% / 74.77%.

  • GraphSAGE-then-GAT is the strongest pairing. Other two-stage combinations underperform on reentrancy F1: GAT+SAGE 82.46%, GAT+GAT 85.66%, SAGE+SAGE 88.89%, against SAGE+GAT at 91.61%. The authors attribute this to GraphSAGE capturing broad structural context while GAT's attention sharpens the reduced graph.

  • CGPool outperforms general pooling methods. In multi-class detection, CGPool achieves 91.27% precision, 84.21% recall and 87.32% F1, against TopKPool (75.29% F1), SAGPool (77.10% F1) and ASAPool (82.41% F1) in the two-stage setting; replacement poolings on the single-stage CGNN range from 75.13% to 80.32% F1.

  • Non-reentrancy classes are harder. Unchecked low-level calls and time manipulation score lower than reentrancy; the authors attribute this to data imbalance in the SmartBugs Wild labels.

  • Coverage 4 is the sweet spot. Preprocessed data grows from 355 MB at coverage 1 to 560 MB at coverage 2, 691 MB at coverage 3, 742 MB at coverage 4 and 762 MB at coverage 5, while test F1 moves 86.57, 85.05, 87.61, 87.73 and 86.92 respectively. Higher coverage adds context but also noise.

  • Gains are largely statistically significant. Experiments were repeated four times with different seeds; most comparisons pass a paired t-test at p ≤ 0.05, though some individual metric comparisons are not significant (for example, the single-stage GAT on unchecked low-level calls at p = 0.234 for precision and p = 0.310 for recall).

Methodology in Plain English

The pipeline has three parts.

Graph construction. The Solidity compiler solc parses the source into an AST. The AST is then enriched into a flow-augmented abstract syntax graph by adding control-flow edges (which branch is taken when a condition is true or false, how loops iterate, the order statements execute) and data-flow edges (which declaration a name refers to, what a function returns, assignment targets, function overriding). The graph is cut into per-function subgraphs, and each function's graph is expanded outward to include the functions and variables it touches, up to the coverage depth.

Stage one — CGNN. Each node carries a textual label such as FunctionDefinition; these labels are tokenised with BPE, then processed by three GraphSAGE layers (512→1024, 1024→1024, 1024→1024, ReLU activations) that pass messages between neighbouring nodes. CGPool then collapses nodes that belong to the same function declaration or variable definition into single supernodes and reconnects them according to the original control- and data-flow links, producing a smaller "Pooled FLAG." Unlike TopKPool, SAGPool or ASAPool, this merging is deterministic and does not learn which nodes to drop.

Stage two — GAT classifier. A Graph Attention Network (three GATConv layers at 1024→1024, the first with 4 attention heads, the latter two with 1 head) weights edges by importance so the model can emphasise connections among function nodes and their variables. A global readout produces one vector per graph, and three linear layers (two ReLU, final softmax over C classes) output the class probabilities.

Training used the Adam optimiser at learning rate 1e-4, weight decay 1e-5, batch size 64, up to 500 epochs, dropout 0.5 in the GNN layers and 0.3 in the classifier, fixed seed 42, on a single NVIDIA RTX 4090 with 24GB memory. Evaluation uses macro-averaged precision, recall and F1.

Data: the AME dataset (1,224 contracts, split 719 train / 505 test; at function level 4,305 non-reentrant and 215 reentrant functions in train, 3,159 and 151 in test) for reentrancy comparison, and a subset of SmartBugs Wild (47,398 Solidity files, 203,716 contracts) for multi-class work, where labels require consensus of three or more heuristic tools (four or more for reentrancy). The final multi-class subset contains 462 reentrancy, 88 unchecked low-level call and 49 time manipulation contracts, splitting at function level into 11,101 train, 5,602 validation and 5,190 test functions.

Why This Matters

Impact on research. The paper argues that rule-based preprocessing — the explicit expert patterns in AME, the heuristic graph simplification in TMP — is the binding constraint on deep-learning vulnerability detectors, and offers a design that removes it. It also contributes a reusable representation (FLAG) and a cheap, semantics-aware pooling operator (CGPool) that could be applied to other code-analysis tasks.

Real-world applications:

  • Pre-deployment auditing of DeFi and token contracts, where a reentrancy bug can drain funds — the paper cites the DAO attack, which stole 3.6 million Ether, valued at $60 million at the time.
  • CI/CD gating in smart contract development pipelines, giving a fast automated check before code is deployed immutably.
  • Triage support for security auditors, prioritising functions that warrant manual review.
  • Monitoring newly deployed contracts for unchecked low-level calls and timestamp dependence.

Industry relevance. Because deployed contracts generally cannot be modified — only deleted and redeployed — catching bugs pre-deployment is the main line of defence, and a detector that generalises to unseen vulnerability variants reduces dependence on scarce security experts.

Future Directions

  • Extending beyond three vulnerability classes. The authors state the model can be extended to a broader range of vulnerabilities but demonstrate only reentrancy, unchecked low-level calls and time manipulation.
  • Improving performance on data-scarce vulnerabilities. Detection of unchecked low-level calls (80.15% F1) and time manipulation (79.63% F1) lags reentrancy (91.61% F1); the paper attributes this to data imbalance and leaves the remedy open.
  • Better handling of high-coverage noise. Data size grows to 762 MB at coverage 5 while F1 falls to 86.92% versus 87.73% at coverage 4, suggesting room for better context selection.
  • Reproducibility across prior work. The authors note that other methods were either limited to reentrancy or did not specify their preprocessing, so cross-method comparison beyond reentrancy was not possible — implying a need for shared, reproducible benchmarks.

Target Audience

Researchers and graduate students in blockchain security and machine learning for code; smart contract auditors and security engineers evaluating automated tooling; and practitioners building GNN-based program analysis systems who want a worked example of combining AST structure with control- and data-flow edges and a semantic pooling layer. Readers need a working understanding of GNN message passing to follow the architecture sections, though the experimental results are legible to a broader security audience.

Authors’ abstract

The rapid growth of Ethereum has made it more important to quickly and accurately detect smart contract vulnerabilities. While machine-learning-based methods have shown some promise, many still rely on rule-based preprocessing designed by domain experts. Rule-based preprocessing methods often discard crucial context from the source code, potentially causing certain vulnerabilities to be overlooked and limiting adaptability to newly emerging threats. We introduce BugSweeper,…

The full abstract on arXiv
Read the original paper