Machine Learning Guided Cross-Contract Fuzzing

Yinxing Xue, Jiaming Ye, Wei Zhang, Jun Sun, Lei Ma, Haijun Wang, Jianjun Zhao · DOI

Abstract

Smart contract transactions are increasingly interleaved by cross-contract calls. While many tools have been developed to identify a common set of vulnerabilities, the cross-contract vulnerability is overlooked by existing tools. Cross-contract vulnerabilities are exploitable bugs that manifest in the presence of more than two interacting contracts. Existing methods are however limited to analyze a maximum of two contracts at the same time. Detecting cross-contract vulnerabilities is highly non-trivial. With multiple interacting contracts, the search space is much larger than that of a single contract. To address this problem, we present xFuzz, a machine learning guided smart contract fuzzing framework. The machine learning models are trained with novel features (e.g., word vectors and instructions) and are used to filter likely benign program paths. Comparing with existing static tools, machine learning model is proven to be more robust, avoiding directly adopting manually-defined rules in specific tools. We compare xFuzz with three state-of-the-art tools on 7,391 contracts. xFuzz detects 18 exploitable cross-contract vulnerabilities, of which 15 vulnerabilities are exposed for the first time. Furthermore, our approach is shown to be efficient in detecting non-cross-contract vulnerabilities as well -- using less than 20% time as that of other fuzzing tools, xFuzz detects twice as many vulnerabilities.

Introduction

Smart contracts on platforms like Ethereum rarely operate in isolation; they frequently call each other to swap tokens, check balances, or delegate logic. However, most security tools are "myopic"—they typically analyze only one or two contracts at a time. This creates a massive blind spot: cross-contract vulnerabilities. These are exploitable bugs that manifest only during complex interleavings of three or more contracts.

Detecting them is a "needle in a haystack" problem because the search space (the number of possible ways contracts can call each other) grows exponentially with every additional contract involved. Existing fuzzers get bogged down in this infinite search space, while static analyzers produce too many false alarms. To navigate this complexity, we propose xFuzz, a machine learning-guided fuzzing framework.

Methodology

The xFuzz framework operates in two distinct phases: a machine learning training phase and a guided fuzzing phase.

The xFuzz framework architecture, illustrating the Machine Learning Training Phase and the Guided Fuzzing Phase.

1. Machine Learning Training Phase

The goal of this phase is to train a model to distinguish between "vulnerable-looking" and "benign-looking" functions.

  • Feature Engineering: Bytecode is transformed into vectors using Word2Vec and combined with seven manually designed static features, such as balance checks or the use of delegatecall.
  • Model Selection: The authors evaluated several models, ultimately choosing the EasyEnsembleClassifier (EEC). As shown in the performance comparison, EEC achieved a 95% recall rate, ensuring that very few actual vulnerabilities are filtered out during the pre-screening process.

2. Guided Fuzzing Phase

Instead of fuzzing all possible paths, xFuzz uses the trained model to filter out likely benign functions, reducing the search space by approximately 80%. Remaining paths are prioritized based on a "suspiciousness score" derived from function complexity and reachability. The fuzzer then executes these prioritized paths on a local private blockchain to identify actual exploits.

Experimental Results

The effectiveness of xFuzz was evaluated against 7,391 real-world contracts from Etherscan and curated benchmarks like SmartBugs.

Performance comparison of different machine learning models, highlighting the high recall of the EasyEnsembleClassifier.

Key Findings

  • Vulnerability Discovery: xFuzz detected 18 exploitable cross-contract vulnerabilities, 15 of which were previously unknown (Zero-Days).
  • Efficiency: Compared to sFuzz, a leading fuzzer, xFuzz detected twice as many vulnerabilities while using less than 20% of the time.
  • Search Space Reduction: The ML guidance allowed the tool to filter out 80.1% of non-vulnerable contracts before the expensive fuzzing process began, significantly optimizing the "fuzzing budget."
  • Robustness: On non-cross-contract vulnerabilities, the ML model achieved 95.5% precision and 84.6% recall, outperforming traditional static tools.

Conclusion and Future Work

By leveraging machine learning to prioritize suspicious execution paths, xFuzz effectively addresses the exponential search space of cross-contract interactions. While highly effective, the tool currently faces challenges with complex path conditions (e.g., specific hardcoded values in "if" statements). Future work will explore Hybrid Fuzzing, combining xFuzz with constraint solvers like Z3 to mathematically solve for the inputs needed to penetrate deep logic paths.

Summary updated

BibTeX
@article{xue2024machine,
  author = {Yinxing Xue and Jiaming Ye and Wei Zhang and Jun Sun and Lei Ma and Haijun Wang and Jianjun Zhao},
  title = {{Machine Learning Guided Cross-Contract Fuzzing}},
  journal = {IEEE Trans. Dependable Secur. Comput.},
  year = {2024},
  url = {https://openreview.net/forum?id=XBnPie9nAy},
}
Figure