Exploiting The Laws of Order in Smart Contracts

Aashish Kolluri, Ivica Nikolic, Ilya Sergey, Aquinas Hobor, Prateek Saxena · DOI

Introduction

Smart contracts on the Ethereum blockchain are inherently concurrent objects. While individual transactions are executed atomically, the specific sequence in which multiple transactions are processed is determined by miners, not the users who submit them. This non-determinism introduces a significant class of vulnerabilities known as event-ordering (EO) bugs. An EO bug occurs when the final state of a contract—such as account balances or ownership—depends on the specific interleaving of concurrent transactions.

Example of an event-ordering (EO) bug where transaction interleaving leads to different outcomes.

As illustrated in the figure above, a classic example involves the approve and transferFrom functions in ERC-20 tokens. If a user attempts to change an allowance from 300 to 100 while a spender concurrently executes a transfer, the spender might successfully withdraw 100 and still retain a 100-unit allowance, effectively spending more than intended. Detecting these bugs is computationally difficult due to the combinatorial explosion of possible transaction orderings; for $N$ transactions, there are $N!$ possible sequences.

Methodology: The ETHRACER Framework

To address this challenge, we present ETHRACER, an automated tool designed to detect EO bugs directly from Ethereum bytecode. ETHRACER treats smart contracts as shared-memory concurrent objects and applies formal verification techniques to navigate the state space efficiently.

The architecture of ETHRACER, illustrating the pipeline from bytecode to bug detection.

As shown in the architecture diagram, ETHRACER utilizes several key innovations:

  1. Dynamic Symbolic Execution (DSE): The tool explores execution paths by treating inputs as symbolic variables, allowing it to identify feasible state transitions and constraints.
  2. Happens-Before (HB) Relations: To mitigate combinatorial blowup, ETHRACER infers dependencies between functions. If Function B requires a state change produced by Function A, the tool prunes invalid sequences (e.g., [B, A]) from its search.
  3. Partial-Order Reduction: By identifying "pure" functions that do not modify global state, the system avoids redundant testing of permutations that yield identical results.
  4. Linearizability Checking: This specialized module focuses on asynchronous patterns, such as those used by the Oraclize service, ensuring that interleaved call-return patterns behave consistently with sequential executions.
  5. Witness Generation: Upon detecting a vulnerability, the tool generates a concrete, replayable transaction trace to assist human auditors in verification.

Evaluation and Key Results

ETHRACER was evaluated against a dataset of 10,000 smart contracts, including 5,000 with source code and 5,000 bytecode-only contracts. The tool flagged between 7% and 11% of these contracts as vulnerable, identifying 789 synchronization violations and 47 linearizability violations. Many of these contracts were high-stakes ICOs and popular tokens managing hundreds of millions of dollars.

In a comparative study with OYENTE, a standard security tool, ETHRACER demonstrated significantly higher recall. While it successfully identified all 78 bugs found by OYENTE, it uncovered an additional 596 true EO bugs that the previous tool missed. Despite the complexity of the analysis, ETHRACER remained efficient, averaging 18.5 minutes per contract.

Discussion and Limitations

By defining bugs based on output divergence rather than specific code patterns, ETHRACER captures a broad spectrum of logical errors. However, the current implementation focuses on local state changes within a single contract. Future work is required to model "non-local" EO bugs that affect external contracts and to refine the "weak" happens-before relations to further reduce potential false negatives. Nevertheless, ETHRACER represents a significant step forward in securing the concurrent execution environment of the blockchain.

Summary updated

BibTeX
@inproceedings{kolluri2018exploiting,
  author = {Aashish Kolluri and Ivica Nikolic and Ilya Sergey and Aquinas Hobor and Prateek Saxena},
  title = {{Exploiting The Laws of Order in Smart Contracts}},
  booktitle = {ISSTA},
  year = {2018},
  doi = {10.1145/3293882.3330560},
}
Figure