EthScope: A Transaction-centric Security Analytics Framework to Detect Malicious Smart Contracts on Ethereum

Lei Wu, Siwei Wu, Yajin Zhou, Runhuai Li, Zhi Wang, Xiapu Luo, Cong Wang, Kui Ren

Abstract

As one of the representative blockchain platforms, Ethereum has attracted lots of attacks. Due to the existed financial loss, there is a pressing need to perform timely investigation and detect more attack instances. Though multiple systems have been proposed, they suffer from the scalability issue due to the following reasons. First, the tight coupling between malicious contract detection and blockchain data importing makes them infeasible to repeatedly detect different attacks. Second, the coarse-grained archive data makes them inefficient to replay transactions. Third, the separation between malicious contract detection and runtime state recovery consumes lots of storage. In this paper, we present the design of a scalable attack detection framework on Ethereum. It overcomes the scalability issue by saving the Ethereum state into a database and providing an efficient way to locate suspicious transactions. The saved state is fine-grained to support the replay of arbitrary transactions. The state is well-designed to avoid saving unnecessary state to optimize the storage consumption. We implement a prototype named EthScope and solve three technical challenges, i.e., incomplete Ethereum state, scalability, and extensibility. The performance evaluation shows that our system can solve the scalability issue, i.e., efficiently performing a large-scale analysis on billions of transactions, and a speedup of around 2,300x when replaying transactions. It also has lower storage consumption compared with existing systems. The result with three different types of information as inputs shows that our system can help an analyst understand attack behaviors and further detect more attacks.

Introduction

As Ethereum’s DeFi and DApp ecosystems have exploded, so have the financial incentives for attackers. Investigating these attacks is currently a major challenge for security researchers due to three "scalability walls":

  1. Tight Coupling: Most detection tools run during the blockchain synchronization process. If an analyst wants to update detection rules or debug a script, they often have to re-import the entire chain—a process that can take over 10 days.
  2. Coarse-grained Data: Standard Ethereum "archive nodes" are inefficient for replaying specific transactions. To replay a single transaction, these nodes often have to re-execute every preceding transaction in that block.
  3. Storage Explosion: Existing research tools that attempt to store logical relations of transactions consume massive amounts of disk space, making full-chain analysis practically impossible for most labs.

EthScope addresses these challenges by implementing a two-step forensic workflow: understanding the attack through suspicious transaction analysis and then scaling that knowledge to detect new attack instances across the entire history of the blockchain.

The two-step workflow of EthScope: understanding the attack and detecting more instances.

System Architecture

EthScope breaks the scalability bottlenecks through a three-component architecture designed for high-performance "time-travel" forensics:

  • Data Aggregator: This component modifies the Go-Ethereum (Geth) client to extract fine-grained state (internal transactions, account balances, and storage variables) at the transaction level. This data is indexed in a searchable database, allowing researchers to perform complex queries to find suspicious activity.
  • Replay Engine: Because the aggregator saves the exact state of the world immediately before any given transaction, the Replay Engine can perform isolated execution. It pulls the necessary state from the database and executes the transaction without re-running unrelated blockchain data.
  • Instrumentation Framework: To detect attacks, the system provides a JavaScript-based API and a dynamic taint engine. This allows analysts to write scripts that "hook" into specific EVM opcodes to track data flows, such as checking if a block's timestamp influences a "random" number.
The EthScope architecture, featuring the Data Aggregator, Replay Engine, and Instrumentation Framework.

Key Insights and Methodology

The core innovation of EthScope is Transaction-Level Granularity. Saving the state at the start of every transaction—rather than every block—eliminates the redundant execution that plagues standard Ethereum clients. Furthermore, the system employs Selective Storage, only saving variables "touched" by a transaction. This "lazy" approach keeps the storage footprint manageable without sacrificing the ability to reconstruct the state.

To maintain high performance during analysis, EthScope utilizes On-Demand Context Switching. The system only switches from the high-speed EVM to the slower JavaScript analysis engine when a specific instrumentation point is hit, rather than for every single opcode.

Evaluation and Results

The researchers evaluated EthScope using the entire Ethereum blockchain from the genesis block to block 10,400,000 (July 2020).

  • Performance: EthScope replayed 100 transactions in ~1.2 seconds, compared to 47 minutes for Geth’s built-in JSTracer—a speedup of roughly 2,300x.
  • Storage Efficiency: The system required only 1,844 GB to store the state for 10.5 million blocks. For comparison, previous state-of-the-art systems required nearly 3,000 GB for just 0.2 million blocks.
  • Real-World Detection:
    • Detected 272 malicious smart contracts exploiting "bad randomness" in gambling games.
  • Identified 2,973 re-entrancy attack transactions in the wild, including 579 attacks that occurred after the 9 millionth block, proving that legacy vulnerabilities remain a persistent threat.

Conclusion

EthScope demonstrates that by decoupling data ingestion from analysis and focusing on transaction-centric state storage, security researchers can perform large-scale forensics on Ethereum with unprecedented speed and efficiency. While the system currently relies on heuristics and manual verification, it provides a robust foundation for future automated detection tools using symbolic execution or machine learning.

Summary updated

Abstract

As one of the representative blockchain platforms, Ethereum has attracted lots of attacks. Due to the existed financial loss, there is a pressing need to perform timely investigation and detect more attack instances. Though multiple systems have been proposed, they suffer from the scalability issue due to the following reasons. First, the tight coupling between malicious contract detection and blockchain data importing makes them infeasible to repeatedly detect different attacks. Second, the coarse-grained archive data makes them inefficient to replay transactions. Third, the separation between malicious contract detection and runtime state recovery consumes lots of storage. In this paper, we present the design of a scalable attack detection framework on Ethereum. It overcomes the scalability issue by saving the Ethereum state into a database and providing an efficient way to locate suspicious transactions. The saved state is fine-grained to support the replay of arbitrary transactions. The state is well-designed to avoid saving unnecessary state to optimize the storage consumption. We implement a prototype named EthScope and solve three technical challenges, i.e., incomplete Ethereum state, scalability, and extensibility. The performance evaluation shows that our system can solve the scalability issue, i.e., efficiently performing a large-scale analysis on billions of transactions, and a speedup of around 2,300x when replaying transactions. It also has lower storage consumption compared with existing systems. The result with three different types of information as inputs shows that our system can help an analyst understand attack behaviors and further detect more attacks. To engage the community, we will release our system and the dataset of detected attacks.
BibTeX
@misc{wu2020ethscope,
  author = {Lei Wu and Siwei Wu and Yajin Zhou and Runhuai Li and Zhi Wang and Xiapu Luo and Cong Wang and Kui Ren},
  title = {{EthScope: A Transaction-centric Security Analytics Framework to Detect Malicious Smart Contracts on Ethereum}},
  year = {2020},
  eprint = {2005.08278},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2005.08278},
}
Figure