Robust Smart Contract Vulnerability Detection via Contrastive Learning-Enhanced Granular-ball Training
Organizations: Chongqing Key Laboratory of Computational Intelligence, Key Laboratory of Cyberspace Big Data Intelligent Security, Ministry of Education, and Key Laboratory of Big Data Intelligent Computing, Chongqing University of Posts and Telecommunications. · the School of Cyber Science and Engineering, Huazhong University of Science and Technology. · School of Computer Science and Artificial Intelligence, Zhengzhou University, China. · the College of Computer and Information Science, Southwest University, China.
Abstract
Deep neural networks (DNNs) have emerged as a prominent approach for detecting smart contract vulnerabilities, driven by the growing contract datasets and advanced deep learning techniques. However, DNNs typically require large-scale labeled datasets to model the relationships between contract features and vulnerability labels. In practice, the labeling process often depends on existing open-sourced tools, whose accuracy cannot be guaranteed. Consequently, label noise poses a significant challenge for the accuracy and robustness of the smart contract, which is rarely explored in the literature. To this end, we propose Contrastive learning-enhanced Granular-Ball smart Contracts training, CGBC, to enhance the robustness of contract vulnerability detection. Specifically, CGBC first introduces a Granular-ball computing layer between the encoder layer and the classifier layer, to group similar contracts into Granular-Balls (GBs) and generate new coarse-grained representations (i.e., the center and the label of GBs) for them, which can correct noisy labels based on the most correct samples. An inter-GB compactness loss and an intra-GB looseness loss are combined to enhance the effectiveness of clustering. Then, to improve the accuracy of GBs, we pretrain the model through unsupervised contrastive learning supported by our novel semantic-consistent smart contract augmentation method. This procedure can discriminate contracts with different labels by dragging the representation of similar contracts closer, assisting CGBC in clustering. Subsequently, we leverage the symmetric cross-entropy loss function to measure the model quality, which can combat the label noise in gradient computations. Finally, extensive experiments show that the proposed CGBC can significantly improve the robustness and effectiveness of the smart contract vulnerability detection when contrasted with baselines.
Figures & tables
| Ref. | Main work | Remarks |
|---|---|---|
| [ 22 ] | Symbolic execution is used to explore contract execution paths for vulnerability detection. | It gives clear semantic analysis, but it suffers from path explosion and high analysis cost. |
| [ 23 ] | Static analysis is performed by extracting structural and dependency information from smart contracts. | It is practical and efficient, but it still relies heavily on handcrafted rules. |
| [ 24 ] | Formal verification is used to check safety properties of smart contracts. | It provides stronger theoretical support, but it needs formal modeling and has high verification cost. |
| [ 25 ] | Fuzzing is combined with taint analysis and feedback guidance to generate exploit-oriented test cases. | It can better validate triggerable vulnerabilities than pure static analysis, but it is still sensitive to seed quality and path coverage. |
| [ 26 ] | Graph neural networks are combined with interpretable graph features and expert patterns for smart contract vulnerability detection. | It balances representation learning and interpretability, but its flexibility is limited by expert-designed knowledge. |
| [ 3 ] | Vulnerability subgraphs are constructed and graph neural networks are used for Ethereum smart contract vulnerability detection. | It improves vulnerability-oriented structural modeling, but it still assumes relatively reliable labels during training. |
| Formalized Word | Meaning | Example |
|---|---|---|
| TYPE | Variable type | ‘uint256’, ‘bool’ |
| MOD | Modifier | ‘public’, ‘private’ |
| VAR | Variable name | ‘V1’, ‘V2’ |
| OP | Arithmetic Operation | ‘=’, ‘+’, ‘-’, ‘*’, ‘/’ |
| CTRL | Control statement | ‘if’, ‘while’, ‘for’ |
| Line # | Methods | RE | TD | IO | Average | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| R(%) | P(%) | F(%) | R(%) | P(%) | F(%) | R(%) | P(%) | F(%) | R(%) | P(%) | F(%) | ||
| 1 | sFuzz [ 47 ] | 14.95 | 10.88 | 12.59 | 27.01 | 23.15 | 24.93 | 47.22 | 58.62 | 52.31 | 29.73 | 30.88 | 29.94 |
| 2 | Smartcheck [ 28 ] | 16.34 | 45.71 | 24.07 | 79.34 | 47.89 | 59.73 | 56.21 | 45.56 | 50.33 | 50.63 | 46.39 | 44.71 |
| 3 | Osiris [ 48 ] | 63.88 | 40.94 | 49.90 | 55.42 | 59.26 | 57.28 | n/a | n/a | n/a | n/a | n/a | n/a |
| 4 | Oyente [ 22 ] | 63.02 | 46.56 | 53.55 | 59.97 | 61.04 | 59.47 | n/a | n/a | n/a | n/a | n/a | n/a |
| 5 | Mythril [ 49 ] | 75.51 | 42.86 | 54.68 | 49.80 | 57.50 | 53.37 | 62.07 | 72.30 | 66.80 | 62.46 | 57.55 | 58.28 |
| RE | TD | IO | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Noise | BaseLine | CGBC | BaseLine | CGBC | BaseLine | CGBC | ||||||||||||
| Levels | P(%) | R(%) | F(%) | P(%) | R(%) | F(%) | P(%) | R(%) | F(%) | P(%) | R(%) | F(%) | P(%) | R(%) | F(%) | P(%) | R(%) | F(%) |
| 0% | 74.49 | 60.83 | 66.97 | 92.65 | 96.92 | 94.74 | 65.91 | 82.86 | 73.42 | 98.55 | 95.77 | 97.14 | 60.57 | 81.40 | 69.46 | 96.77 | 100 | 98.36 |
| 10% | 58.08 | 45.65 | 51.12 | 90.62 | 87.88 | 89.23 | 76.11 | 46.77 | 57.94 | 86.16 | 96.55 | 91.06 | 90.04 | 63.53 | 74.50 | 86.15 | 96.55 | 91.05 |
| 20% | 47.86 | 39.53 | 43.30 | 71.43 | 97.83 | 82.57 | 61.66 | 37.77 | 46.84 | 72.41 | 84.00 | 77.78 | 86.29 | 56.45 | 68.25 | 75.44 | 72.88 | 74.14 |
| 30% | 50.34 | 34.82 | 41.17 | 70.17 | 78.43 | 74.07 | 45.61 | 41.68 | 43.56 | 65.57 | 81.63 | 72.73 | 80.77 | 53.99 | 64.72 | 71.88 | 77.97 | 74.80 |
| Type | RE | TD | IO | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Noise Level | 0% | 20% | 40% | 0% | 20% | 40% | 0% | 20% | 40% | |||||||||
| Methods | Clear | CGBC | Clear | CGBC | Clear | CGBC | Clear | CGBC | Clear | CGBC | Clear | CGBC | Clear | CGBC | Clear | CGBC | Clear | CGBC |
| P(%) | 96.81 | 92.65 | 58.00 | 71.43 | 50.93 | 64.10 | 94.30 | 98.55 | 66.17 | 72.41 | 50.54 | 57.58 | 89.81 | 96.77 | 66.53 | 75.44 | 52.80 | 68.12 |
| R(%) | 96.43 | 96.92 | 59.18 | 97.83 | 35.50 | 60.98 | 98.41 | 95.77 | 65.19 | 84.00 | 64.83 | 69.10 | 91.48 | 100.00 | 69.30 | 72.88 | 80.73 | 79.67 |
| F(%) | 96.62 | 94.74 | 58.59 | 82.57 | 41.84 | 62.50 | 96.31 | 97.14 | 67.18 | 77.78 | 56.80 | 62.81 | 90.64 | 98.36 | 67.88 | 74.14 | 63.84 | 73.44 |
Software Vulnerability Detection
Software vulnerability detection identifies insecure code, pinpoints weaknesses, and helps developers validate or prevent exploitable bugs.
See all 139 papers