Published in IEEE Xplore

A Bias-Corrected Dataset Construction Framework for Machine Learning-Based Smart Contract Vulnerability Detection

Dharshan Kumar J · Srija J · Shivanthana S

School of Computer Science and Technology · Karunya Institute of Technology and Sciences

2026 International Conference on Secure IoT and Cybersecurity (ICOSICS) 23–25 September 2026 · Bengaluru, India
  • Machine Learning
  • Smart Contract Security
  • Dataset Bias
  • Solidity
  • Vulnerability Detection
  • Cybersecurity
3,316 Ethereum contracts
9 Security features
93.37% Test accuracy
0.9710 ROC-AUC

Abstract

Smart contracts governing Decentralized Finance (DeFi) protocols on Ethereum handle billions of dollars in assets, making reliable vulnerability detection a practical necessity rather than an academic exercise. Existing machine learning studies achieve strong benchmark numbers, yet a fundamental problem in how training datasets are assembled has received little attention: audited safe contracts drawn from large DeFi protocols are structurally much larger than exploited vulnerable ones, creating a size-proxy bias that inflates reported accuracy without teaching the model anything about security. This paper identifies and corrects that bias through a nine-stage automated pipeline that produces a curated dataset of 3,316 real-world Ethereum contracts, extracts nine security-oriented features via Slither static analysis and source-code metrics, trains a Gradient Boosting classifier, and applies SHAP attribution to verify that predictions are driven by genuine security patterns rather than contract size. On the raw biased dataset the model reached 98.49% accuracy with function_count capturing 89.51% of feature importance; after correction, accuracy settles to a realistic 93.37%, with assembly_flag becoming the dominant predictor at a SHAP value of 2.02. Full evaluation on the held-out test set yields 90.51% precision, 83.14% recall, 86.67% F1-score, and 0.9710 ROC-AUC, outperforming Random Forest and Logistic Regression baselines trained on identical features and splits. The 4.88 percentage-point accuracy drop after bias correction is not a performance loss but a removal of a confounding factor, and the shift in feature importance from size proxies to security indicators confirms the model is learning what it is supposed to learn.

What the paper contributes

Quantifies a hidden dataset bias

Safe audited DeFi contracts average 91.9 functions; exploited vulnerable contracts average 6.2—a 14.9× size gap that lets models learn size instead of security.

Builds a reproducible corrected corpus

A nine-stage pipeline scrapes, resolves, verifies, flattens, and labels contracts, producing 3,316 Ethereum contracts with nine security-oriented features.

Replaces size proxies with security signals

After correction, function_count no longer dominates. assembly_flag becomes the top predictor at a SHAP value of 2.02, followed by external_calls (0.92) and function_count (0.71); unchecked calls and delegatecall follow at 0.64 each.

Benchmarks with identical splits

On the same features and test split, Gradient Boosting leads both baselines on accuracy and ROC-AUC, reaching 90.51% precision and 83.14% recall.

When 98.49% accuracy is a warning sign

Audited safe contracts from large DeFi protocols average 91.9 functions; exploited vulnerable contracts average 6.2. That 14.9× gap is enough for a model to learn contract size as a stand-in for vulnerability. On the raw 4,492-contract dataset, function_count absorbed 89.51% of Gradient Boosting’s impurity importance and accuracy reached 98.49%—a number that measured size discrimination, not security learning.

Raw dataset 98.49%

accuracy

function_count · 89.51% of feature importance

After correction 93.37%

accuracy

assembly_flag · SHAP value 2.02

The 4.88 percentage-point drop is not a performance loss. It is the removal of a confounding factor.

A nine-stage, reproducible pipeline

The final corpus contains 3,316 real-world Ethereum contracts: 924 vulnerable and 2,392 safe. Every stage runs with checkpoints every 100 contracts, and nine security-oriented features combine Slither analysis with source-code metrics.

  1. 01

    Source scraping

    Collect vulnerable-contract leads and incident metadata from rekt.news, DefiLlama, and SlowMist.

  2. 02

    Address merge

    Deduplicate addresses across sources so the same incident is not counted twice.

  3. 03

    URL extraction

    Use LLM-assisted extraction to resolve each incident to its Ethereum contract address.

  4. 04

    Source download

    Fetch verified Solidity source code through the Etherscan API.

  5. 05

    Flattening

    Merge multi-file contracts and imports into a single compilable Solidity unit.

  6. 06

    Slither analysis

    Run Slither with solc-select across compiler versions to extract security flags.

  7. 07

    Feature extraction

    Combine Slither JSON output with regex-based source-code metrics into nine features.

  8. 08

    Safe collection

    Gather Etherscan-verified safe contracts while excluding proxies and empty source code.

  9. 09

    Assembly

    Validate, label, and export the final CSV used for training, validation, and testing.

What changes when size stops being the signal

The held-out test set contains 664 contracts: 172 vulnerable and 492 safe. Gradient Boosting outperforms both baselines on accuracy and ROC-AUC, and Random Forest on precision. Logistic Regression has higher precision, but it misses nearly one in three vulnerable contracts.

Model Accuracy Precision Recall ROC-AUC
Gradient Boosting (ours) 93.37% 90.51% 83.14% 0.9710
Random Forest 92.77% 86.47% 85.47% 0.9630
Logistic Regression 90.51% 93.60% 68.02% 0.9289

All models use identical features and the same held-out split.

SHAP feature importance

After correction, security flags dominate. assembly_flag leads at 2.02, followed by external_calls (0.92) and function_count (0.71). Size now provides context instead of driving the decision.

  • assembly_flag 2.02
    Slither flag
  • external_calls 0.92
    Code metric
  • function_count 0.71
    Code metric
  • unchecked_call_flag 0.64
    Slither flag
  • delegatecall_flag 0.64
    Slither flag
  • modifier_count 0.25
    Code metric
  • tx_origin_flag 0.20
    Slither flag
  • reentrancy_flag 0.18
    Slither flag
  • selfdestruct_flag 0.00
    Slither flag

On the raw biased dataset, Gradient Boosting reached 98.49% accuracy while function_count captured 89.51% of impurity importance.

After correction, accuracy settled at 93.37% and assembly_flag became the dominant predictor at a SHAP value of 2.02.

The held-out 664-contract test set produced 90.51% precision, 83.14% recall, 86.67% F1-score, and 0.9710 ROC-AUC.

Removing assembly_flag reduced F1 by 6.04 percentage points; removing function_count reduced it by only 1.12 points.

Security flags collectively contributed 3.648 mean |SHAP|, compared with 1.870 for structural code metrics.

Official record

Both official IEEE Xplore screenshots and the paper’s framework and first page are included as publication evidence. Select any image to view it at full size.

IEEE Xplore proceedings listing — title, authors, publication year, and pages 1436–1442.
Official IEEE Xplore publication page — title, authors, publisher, and abstract.
The bias-corrected explainable framework: dataset construction, structural bias analysis, correction, feature extraction, classification, and SHAP explainability.
First page of the published conference paper, including the abstract and index terms.

The two IEEE Xplore screenshots document the official record; the framework diagram summarizes the paper’s pipeline, and the first page is reproduced from the published PDF.

Cite this paper

If you reference this work, please use the BibTeX entry below.

@inproceedings{Dharshan2026BiasCorrected,
  author    = {Dharshan Kumar J and Srija J and Shivanthana S},
  title     = {A Bias-Corrected Dataset Construction Framework for Machine Learning-Based Smart Contract Vulnerability Detection},
  booktitle = {2026 International Conference on Secure IoT and Cybersecurity (ICOSICS)},
  publisher = {IEEE},
  year      = {2026},
  pages     = {1436--1442},
  doi       = {10.1109/ICOSICS70095.2026.11746875},
  url       = {https://ieeexplore.ieee.org/document/11746875}
}

Read the full paper

Explore the methodology, results, and SHAP analysis on IEEE Xplore.

Open IEEE Xplore