TL;DR
This paper introduces EVulHunter, the first automated tool to detect "fake transfer" vulnerabilities in EOSIO smart contracts compiled to WebAssembly (WASM). By analyzing WASM code and simulating execution, EVulHunter can identify these critical vulnerabilities, which have led to significant financial losses, with high accuracy and efficiency.
What Problem Does This Paper Address?
The rapid growth of blockchain technology, particularly platforms like EOSIO, has led to an increase in smart contract development. However, this also brings a rise in vulnerabilities and associated attacks, causing substantial financial damages. A significant challenge in securing EOSIO smart contracts is that many are not open-sourced, leaving their WebAssembly (WASM) bytecode as the primary analyzable artifact. Existing security tools are often designed for web applications and cannot directly analyze WASM code, creating a gap in vulnerability detection for EOSIO. This paper specifically targets "fake transfer" vulnerabilities, a class of exploits that have resulted in millions of dollars in losses, particularly in gambling DApps.
Methods
EVulHunter employs a static analysis approach to detect fake transfer vulnerabilities in EOSIO WASM code. The core of the system comprises three modules:
- CFG Builder: This module parses the EOSIO WASM code and constructs Control Flow Graphs (CFGs). It specifically focuses on the
applyfunction, which is crucial for handling incoming actions. - WASM Simulator: Designed as a lightweight virtual machine, this module simulates the execution of specific basic blocks within the WASM code. It maintains a stack and linear memory to reconstruct the execution state, enabling deeper analysis and the recovery of semantic information from the bytecode. This is particularly useful for identifying indirect function calls within the
applyfunction, which is a challenge due to the lack of explicit symbol information in WASM. - Detector Engine: This module houses specialized detectors for different types of fake transfer vulnerabilities. It interacts with the WASM simulator when necessary. The paper details two detectors:
- Fake EOS Transfer Detector: This detector checks if the contract's
applyfunction properly verifies thecodeparameter. If the contract doesn't adequately check that the incoming action is authorized byeosio.token(or a whitelisted account), it's flagged as vulnerable. - Fake EOS Notice Detector: This detector looks for comparisons between the
toand_selfparameters within thetransferfunction. If such a comparison is missing, the contract is flagged as potentially vulnerable to this advanced variant.
The system also addresses variants in WASM code arising from the evolution of the EOSIO Contract Development Toolkit (CDT) and different implementation strategies for the same logic.
Datasets
The authors did not find existing public benchmarks for vulnerable EOS smart contracts. Therefore, they manually crafted a benchmark dataset. This involved:
- Identifying reported vulnerable DApps and their corresponding attacks (e.g., EOSBet).
- Collecting both the vulnerable versions of these smart contracts and their patched, non-vulnerable counterparts.
The final benchmark consists of 241 EOS smart contracts in total, with 159 identified as vulnerable. Specifically, 184 contracts were used for evaluating fake EOS transfer detection, and 195 for fake EOS notice detection.
Key Insights and Ideas
- WASM as the primary analysis target: The paper highlights that for many EOSIO smart contracts, WASM bytecode is the only analyzable artifact, necessitating tools that can operate at this level.
- Simulating WASM execution is crucial: Directly analyzing WASM is challenging due to the lack of high-level information. Simulating execution, as done by EVulHunter, allows for the recovery of semantic meaning and the identification of critical control flow.
- "Fake transfer" vulnerabilities are a real threat: The paper underscores the significant financial impact of these vulnerabilities, motivating the development of specialized detection tools.
- Handling CDT evolution is essential: The dynamic nature of blockchain development means that tools must be robust enough to handle variations in contract development toolkits.
Key Results
EVulHunter demonstrated strong performance in detecting fake transfer vulnerabilities:
- Fake EOS Transfer: Achieved an overall accuracy of 85.87%, with a precision of 74.26% and a recall of 100%. It identified 75 true positives and had 26 false positives.
- Fake EOS Notice: Achieved an impressive 100% accuracy, precision, and recall, identifying 141 true positives and 0 false positives.
- Performance: The detection time for smart contracts was found to increase linearly with their size, but remained very fast, ranging from 1 to 3 seconds per contract. This suggests EVulHunter is efficient and scalable.
Limitations and Future Work
- False Positives for Fake EOS Transfer: The 26 false positives for fake EOS transfer were attributed to a specific contract ("eosbetdice11") that acknowledged an additional legal account (
eosbettokens) beyondeosio.token. This suggests a need for more flexible whitelisting mechanisms. - Pattern-based Detection: The current detection relies on predefined patterns. For other types of vulnerabilities, more advanced program analysis techniques like symbolic execution might be necessary.
- Future Work: The authors suggest exploring advanced program analysis techniques to improve accuracy for a wider range of vulnerabilities and revising the system design to support these advanced analyses. They also propose extending the system with a more flexible whitelisting mechanism to handle legitimate custom accounts.
Summary updated