[Paper Review] G-Scan: Graph Neural Networks for Line-Level Vulnerability Identification in Smart Contracts
G-Scan is the first end-to-end graph neural network system for fine-grained, line-level vulnerability detection in Ethereum smart contracts. It constructs dependency- and hierarchy-preserving code graphs from Solidity source code, uses a GCN to predict vulnerable nodes, and maps predictions back to source lines, achieving 93.69% F1-score in line-level localization on a novel real-world reentrancy vulnerability dataset.
Due to the immutable and decentralized nature of Ethereum (ETH) platform, smart contracts are prone to security risks that can result in financial loss. While existing machine learning-based vulnerability detection algorithms achieve high accuracy at the contract level, they require developers to manually inspect source code to locate bugs. To this end, we present G-Scan, the first end-to-end fine-grained line-level vulnerability detection system evaluated on the first-of-its-kind real world dataset. G-Scan first converts smart contracts to code graphs in a dependency and hierarchy preserving manner. Next, we train a graph neural network to identify vulnerable nodes and assess security risks. Finally, the code graphs with node vulnerability predictions are mapped back to the smart contracts for line-level localization. We train and evaluate G-Scan on a collected real world smart contracts dataset with line-level annotations on reentrancy vulnerability, one of the most common and severe types of smart contract vulnerabilities. With the well-designed graph representation and high-quality dataset, G-Scan achieves 93.02% F1-score in contract-level vulnerability detection and 93.69% F1-score in line-level vulnerability localization. Additionally, the lightweight graph neural network enables G-Scan to localize vulnerabilities in 6.1k lines of code smart contract within 1.2 seconds.
Motivation & Objective
- To address the gap in fine-grained, line-level vulnerability detection in smart contracts, which existing tools fail to localize accurately.
- To overcome limitations of prior GNN-based methods that cannot map node-level predictions back to source code lines.
- To create and evaluate the first real-world, line-level annotated dataset for reentrancy vulnerabilities in smart contracts.
- To design a graph representation that preserves data dependencies and code hierarchies for improved vulnerability detection.
- To enable efficient, low-overhead inference for large contracts, reducing developer debugging time.
Proposed method
- Convert Solidity smart contracts into code graphs using their Abstract Syntax Tree (AST) with added edges for data dependencies and control hierarchies.
- Assign node features including function types (e.g., While, For), variable properties (visibility, storage), and member access (send, transfer).
- Use a Graph Convolutional Network (GCN) to learn hidden representations that encode vulnerability patterns across the graph.
- Train the GCN for node-level classification to predict whether each code graph node corresponds to a vulnerable line.
- Map predicted vulnerable nodes back to their original source code lines using a 'src' attribute stored during AST construction.
- Evaluate the model on a newly collected real-world dataset of 13,773 smart contracts with line-level reentrancy vulnerability annotations.
Experimental results
Research questions
- RQ1Can a graph neural network effectively detect reentrancy vulnerabilities at the line level in real-world smart contracts?
- RQ2How does preserving code dependencies and hierarchies in the graph representation affect detection performance?
- RQ3Can G-Scan localize vulnerabilities efficiently in large contracts with low inference overhead?
- RQ4How does G-Scan's performance compare to existing contract-level and node-level detection systems on fine-grained localization?
- RQ5To what extent does using a real-world annotated dataset improve detection accuracy compared to synthetic injection methods?
Key findings
- G-Scan achieves a 93.02% F1-score in contract-level vulnerability detection on the real-world dataset, demonstrating high classification accuracy.
- The system attains a 93.69% F1-score in line-level vulnerability localization, significantly outperforming prior methods that lack back-mapping capability.
- G-Scan localizes vulnerabilities in 6.1k lines of code within 1.2 seconds, indicating low inference overhead suitable for practical use.
- The use of a real-world dataset with line-level annotations leads to higher detection accuracy than synthetic injection methods used in prior work.
- Preserving code dependencies and hierarchies in the graph construction improves model performance by capturing critical vulnerability patterns.
- The integration of source code line mappings via 'src' attributes enables accurate and actionable vulnerability localization for developers.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.