Skip to content
Crypto.world

Research

TaintSentinel: Path-Level Randomness Vulnerability Detection for Ethereum Smart Contracts

Blockchains are deterministic, so a smart contract cannot produce truly random values; when contracts use predictable on-chain data such as block.timestamp, block.number, blockhash, or…

TaintSentinel: Path-Level Randomness Vulnerability Detection for Ethereum Smart Contracts
arXiv
2510.18192
Published
2025-10-21
Authors
Hadis Rezaei, Ahmed Afif Monrat, Karl Andersson, Francesco Flammini

AI summary

Overview

Research area: Blockchain security — static and learning-based vulnerability detection for Ethereum smart contracts, specifically the "bad randomness" (weak pseudo-randomness) class.

Technical level: Advanced. The paper combines program-analysis concepts (taint tracking, control-flow/semantic graphs, source–sink reachability) with graph neural networks (GCN, BiLSTM, gated fusion). Readers need familiarity with smart contracts and deep learning to follow Section IV.

Scope (one sentence): The paper proposes TaintSentinel, a two-phase detector that extracts risk-labeled taint paths from contract source code and classifies them with a dual-stream graph neural network, evaluated on 4,844 labeled contracts.

What This Paper Is About

Blockchains are deterministic, so a smart contract cannot produce truly random values; when contracts use predictable on-chain data such as block.timestamp, block.number, blockhash, or block.difficulty to decide who wins a lottery or receives a payout, attackers (or miners) can predict or steer the outcome. The paper argues that existing detectors either flag every use of such a variable — producing very high false-positive rates — or analyze the contract only as a whole, ignoring the specific execution paths where randomness actually reaches money-moving code. TaintSentinel's goal is to judge randomness at the level of individual execution paths, distinguishing a block.timestamp used inside a modulo-based lottery draw from the same call used in a 15-minute time lock.

Key Contributions

  1. Path-level bad randomness detection. The authors describe TaintSentinel as the first system in this vulnerability class that analyzes complete execution paths from entropy source to sensitive sink, rather than isolated code fragments or the contract as a single unit.
  2. Rule-augmented taint analysis. Traditional taint tracking is combined with domain-specific, context-sensitive rules that can override the initial source/sink classification — the same source may be HIGH risk in one pattern and Safe in another.
  3. Dual-input graph neural network with gated fusion. A path-focused stream (BiLSTM over tainted paths plus hierarchical attention/mean/max aggregation) is fused with a global stream (three GCN layers over the contract's semantic graph) through a learned gate, so the model can weigh local path evidence against whole-contract context.
  4. Evidence-based parameter initialization and a new metric. Sources and sinks are classified with reference to OWASP, CWE, and SWC standards to avoid treating every blockchain variable as vulnerable, and the paper introduces Path Risk Accuracy (PRA) to measure how well the model reproduces the three-level HIGH/MEDIUM/LOW path risk labels.

Main Findings

  • Headline numbers (abstract): on 4,844 contracts, TaintSentinel reports an F1-score of 0.892, AUC-ROC of 0.94, and PRA accuracy of 97%.
  • Headline numbers (experimental section) differ: the balanced-dataset results are F1 0.875, precision 0.921, recall 0.833, AUC-ROC 0.951, PRA 0.970. The 0.892 F1 in the abstract does not match any figure in the results tables, and this discrepancy is not explained in the provided text.
  • Balanced confusion matrix: of 41 vulnerable contracts, 37 (90.2%) were correctly identified with 4 false negatives; of 24 safe contracts, 20 (83.3%) were correctly identified, i.e. a 16.7% false-positive rate on that set.
  • Imbalanced setting (96% safe, 4% vulnerable): threshold optimization raised recall from 0.439 to 0.707 while precision fell from 0.783 to 0.537, and false negatives dropped by 61% (29 of 41 vulnerable contracts caught); the optimized F1 is reported as 0.611.
  • Path-level risk prediction is the strongest result: PRA of 0.970 (balanced) and 0.920 (imbalanced), which the authors use as evidence that graduated, context-sensitive taint labeling is meaningful.
  • Threshold-independent discrimination holds up: AUC-ROC of 0.951 (balanced) and 0.940 (imbalanced).
  • Training behavior: the balanced run converged at epoch 28 with loss falling from about 0.68 to about 0.44; the imbalanced run was more volatile (validation loss fluctuating between 0.55 and 0.80) and stabilized at epoch 25.
  • Runtime: training took 55 minutes for 500 balanced samples and 460 minutes for 4,600 imbalanced samples (6.6 s and 6.0 s per sample); inference averages 7.57 s per contract (balanced) and 6.25 s per contract (imbalanced).
  • Dataset reality check: of 47,398 SmartBugs-Wild contracts, 6,586 (14%) contained at least one known bad-randomness source, but only 348 (5.3%) were clearly misusing it; 4,445 (67.5%) used it safely and 1,793 (27.2%) were ambiguous. This is the paper's core empirical argument that naive source-matching massively over-reports vulnerability.
  • Which sources dominate: among 1,947 primary source instances, block.timestamp/now accounts for 892 (45.8%), block.number 356 (18.3%), blockhash 248 (12.7%), tx.gasprice 187 (9.6%), gasleft() 142 (7.3%), and block.difficulty/prevrandao 122 (6.3%); a further 723 combined-source cases were found, including 275 with keccak256, 438 with msg.sender, and 89 with address(this).balance.
  • Label quality check: about 150 randomly selected contracts were manually reviewed by smart contract security experts, yielding 94% agreement with the automatic classification for vulnerable contracts and 91% for safe contracts.
  • Comparison gap: despite the claim of superiority over existing tools, the provided results contain no head-to-head benchmark against RNVulDet, TONScanner, Slither, or Mythril on a shared dataset; Table I compares tools by attributes (specialization, analysis level, method, reported accuracy) rather than by measured performance here.
  • Internal inconsistency: the text alternately states recall "increases from 0.833 to 0.707" and that the optimized setting has "better recall (0.707 vs. 0.833)"; 0.707 is lower than 0.833, so the direction is stated incorrectly in at least one place.

Methodology in Plain English

The system works in two stages.

Stage 1 — reading the code and following the data. The contract's Solidity source is parsed into an abstract syntax tree, then turned into a directed "semantic graph" containing three kinds of edges: control flow (what executes next), data dependency (which variable feeds which), and state changes (writes to storage). Functions and modifiers are recorded as execution contexts, because a random draw inside an onlyOwner function is less dangerous than the same code in a public function.

The tool then marks sources — predictable blockchain values such as block.timestamp, blockhash(), block.difficulty, and block.number — and sinks — places where unpredictability matters, such as random-number generation, value transfer, prize assignment, state modification, external calls, and conditional logic. Each is tagged with a risk level tied to CWE or SWC identifiers. Taint is then propagated outward from sources with breadth-first search, but with a twist: propagation is graduated, so taint keeps full strength across control edges and is attenuated across data edges, on the reasoning that heavy transformation reduces exploitability. Finally, every source-to-sink path is scored using rules that inspect context (keywords like "lottery", access control, modulo arithmetic, hash-based RNG) and can downgrade a path to Safe — for instance block.timestamp >= deadline + 15 min or use purely for event logging.

Stage 2 — learning from paths and from the whole contract. Each risk-labeled path is encoded by a BiLSTM and combined with path features, then aggregated three ways: attention weighting (emphasize the most suspicious paths), mean pooling (overall distribution), and max pooling (worst case). In parallel, the full semantic graph is passed through three GCN layers and pooled (mean and max) into a 256-dimensional global embedding; the path stream produces a 64-dimensional embedding. The two are concatenated into 320 dimensions, a gating network (128-dimensional) computes element-wise weights, and the gated fusion output feeds a classifier. A second head predicts path risk level, and training minimizes cross-entropy for classification plus 0.3 times cross-entropy for path risk.

Why This Matters

Research impact. The paper reframes bad randomness from a pattern-matching problem into a context problem and provides a concrete, reproducible-ish pipeline (semantic graph, graduated taint, dual-stream GNN) plus a new evaluation metric (PRA) that rewards getting risk gradations right rather than only binary labels. Its dataset statistics — 67.5% of source-containing contracts using randomness safely — are a direct challenge to the rule-based detectors that dominate practice.

Real-world applications:

  • DeFi protocols whose liquidation, auction, or reward logic depends on unpredictable values.
  • Blockchain gaming and NFT drops, where predictable draws can be farmed.
  • Lottery and betting contracts, the setting of the paper's own motivating example and of the reported block-number manipulation thefts of more than 400 Ethereum.
  • Continuous integration / pre-deployment audit pipelines, which the authors explicitly target given the 6–7.5 second per-contract inference time.

Industry relevance. Security auditors and smart contract developers currently face a choice between fast, noisy rule checkers (Slither, Mythril) and manual review; a path-level classifier that suppresses benign block.timestamp use while flagging modulo-based draws is directly actionable, and the tooling gap the authors document — only two specialized bad-randomness tools in the literature (RNVulDet and TONScanner, the latter for TON rather than Ethereum) — shows how thin commercial coverage is in this vulnerability class.

Future Directions

  • A genuine head-to-head benchmark. The paper's superiority claim is not backed in the provided text by same-dataset comparisons with RNVulDet, TONScanner, Slither, or Mythril; running all of them on the 394 vulnerable / 4,447 safe set is the obvious next experiment.
  • Resolving the reported-metric discrepancies. The abstract's F1 of 0.892 versus the table's 0.875, and the mis-stated recall direction (0.833 vs. 0.707), need reconciliation before the numbers can be cited confidently; similarly, the truncated PRA value for the imbalanced default setting in Table VI is missing.
  • Handling the 1,793 "suspicious" contracts. More than a quarter of source-containing contracts could not be definitively labeled; semi-automated labeling, symbolic execution, or expert-in-the-loop annotation could convert these into usable training signal and improve the 4% vulnerable / 96% safe imbalance.
  • Extending beyond Ethereum and beyond bad randomness. TONScanner's existence shows the TON logical-time mechanism; generalizing the path-level formulation to other context-dependent flaws (reentrancy, access control, oracle manipulation) and to other chains is a natural extension, as is reducing the 6–7.5 second per-contract cost for whole-repository scanning.
  • Improving recall under imbalance. The default imbalanced recall of 0.439 is the weakest number in the paper; better class-imbalance handling than post-hoc threshold tuning would matter most in a security context where missed vulnerabilities are costlier than false alarms.

Target Audience

Smart contract security researchers and auditors; blockchain engineers evaluating pre-deployment analysis tooling; and graduate-level readers in program analysis or applied machine learning who are interested in combining taint analysis with graph neural networks. Practitioners wanting an off-the-shelf tool will find the architectural detail useful but should note that no public implementation, code link, or baseline comparison is reported in the provided text, and that Section V-C (Implementation and Experimental Setup) is present only as a heading with no content.

Authors’ abstract

The inherent determinism of blockchain technology poses a significant challenge to generating secure random numbers within smart contracts, leading to exploitable vulnerabilities, particularly in decentralized finance (DeFi) ecosystems and blockchain-based gaming applications. From our observations, the current state-of-the-art detection tools suffer from inadequate precision while dealing with random number vulnerabilities. To address this problem, we propose TaintSentinel,…

The full abstract on arXiv
Read the original paper