Angels or Demons: Investigating and Detecting Decentralized Financial Traps on Ethereum Smart Contracts

Jiachi Chen, Jiang Hu, Xin Xia, David Lo, John Grundy, Zhipeng Gao, Ting Chen

Abstract

Decentralized Finance (DeFi) uses blockchain technologies to transform traditional financial activities into decentralized platforms that run without intermediaries and centralized institutions. Smart contracts are programs that run on the blockchain, and by utilizing smart contracts, developers can more easily develop DeFi applications. Some key features of smart contracts—self-execution and immutability—ensure the trustworthiness, transparency, and efficiency of DeFi applications, and have led to a fast-growing DeFi market. However, misbehaving developers can add traps or backdoor code snippets to a smart contract, which are hard for contract users to discover. We call these code snippets in a DeFi smart contract "DeFi Contract Traps" (DCTs). In this paper, we identify five DeFi contract traps and introduce their behaviors, describe how attackers use them to make unfair profits, and analyze their prevalence in the Ethereum platform. We propose a symbolic execution tool, DeFiDefender, to detect such traps and use a manually labeled small-scale dataset that consists of 700 smart contracts to evaluate it. Our results show that our tool is not only highly effective but also highly efficient. DeFiDefender only needs 0.48s to analyze one DeFi smart contract and obtains a high average accuracy (98.17%), precision (99.74%), and recall (89.24%). Among the five DeFi contract traps introduced in this paper, four of them can be detected through contract bytecode without the need for source code. We also apply DeFiDefender to a large-scale dataset that consists of 20,679 real DeFi-related Ethereum smart contracts. We found that 52.13% of these DeFi smart contracts contain at least one contract trap. Although a smart contract that contains contract traps is not necessarily malicious, our finding suggests that DeFi-related contracts have many centralized issues in a zero-trust environment and in the absence of a trusted party.

Introduction

The core appeal of Decentralized Finance (DeFi) is its reliance on immutable, self-executing smart contracts that remove the need for centralized intermediaries. However, the authors argue that this creates a potential false sense of security. Unlike traditional software vulnerabilities—which are unintentional errors that anyone can exploit—DeFi Contract Traps (DCTs) are intentional code snippets that grant contract owners special privileges to manipulate the system.

These traps are often buried deep within bytecode or hidden in unexecuted parts of the source code, making them nearly invisible to the average user. This research seeks to categorize these traps, understand their prevalence, and provide an automated way to detect them before users lose their assets.

Categorizing DeFi Contract Traps (DCTs)

The researchers identified five primary types of traps that allow developers to maintain centralized control or siphon funds from users. These traps are often hidden within complex bytecode or unexecuted source code sections, making them difficult for non-expert users to detect.

Definitions of the five identified DeFi Contract Traps (DCTs).

As detailed in the table above, the identified traps include:

  • Tricky Send (TS): Deliberately failing to check transfer success, allowing the contract to reset a user's balance even if the Ether transfer failed.
  • Super Storage Permission (SSP): Backdoor snippets allowing owners to freely change key storage variables, such as interest rates or fee structures.
  • Super Transfer Permission (STP): Code that permits the owner to transfer the contract's Ether balance to themselves at any time.
  • Selfdestruct Permission (SP): A function allowing the owner to destroy the contract and claim all remaining funds, often referred to as a "rug pull."
  • Forged Transfer (FT): Misleading users by placing promised functionalities in subcontracts that are never actually inherited or called by the main contract.

Methodology: DeFiDefender

To address the challenge of detecting these traps, the authors developed DeFiDefender, a tool that utilizes symbolic execution and Abstract Syntax Tree (AST) analysis. The tool's workflow is split based on the type of trap:

  1. Bytecode Analysis: For four of the five traps (TS, SSP, STP, and SP), DeFiDefender analyzes the contract's runtime and creation bytecode. It builds a Control Flow Graph (CFG) and uses symbolic execution to track storage slots and permission owners. It then applies predefined symbolic patterns to identify suspicious logic (e.g., a selfdestruct function reachable only by the owner).
  2. Source Code Analysis: For the "Forged Transfer" trap, the tool parses the Solidity source code into an AST to build a Contract Call Graph (CCG). This allows it to identify "dead code" subcontracts that contain promised functionalities (like withdrawal logic) that can never actually be executed.

DeFiDefender is optimized for speed, utilizing an updated version of the DefectChecker engine to support a wide range of Solidity compiler versions (v0.4.11 to v0.8.17).

Experimental Results

The study utilized two primary datasets: a small-scale dataset of 700 manually labeled DeFi smart contracts used to evaluate the tool's accuracy, and a large-scale dataset of 20,679 real-world DeFi-related Ethereum smart contracts extracted from Etherscan.

DeFiDefender demonstrated remarkable efficiency, requiring only 0.48 seconds on average to analyze a single contract. On the labeled dataset, the tool achieved an average accuracy of 98.17%, with a precision of 99.74% and a recall of 89.24%.

In the large-scale analysis, 52.13% of the contracts contained at least one trap. The most common trap, "Super Storage Permission," was found in 50.56% of the contracts, highlighting how common it is for developers to retain the ability to manipulate contract states.

Conclusion

The high prevalence of DCTs reveals a "Centralization Paradox" in the DeFi ecosystem. Despite the "decentralized" label, many projects maintain centralized control, allowing owners to change interest rates, drain funds, or destroy the contract at will. While the presence of a trap doesn't guarantee malicious intent—some might be intended as emergency "circuit breakers"—their existence in a zero-trust environment poses a significant risk. DeFiDefender provides a scalable and efficient means for users and auditors to identify these traps, bringing much-needed transparency to the Ethereum DeFi landscape.

Summary updated

Abstract

<title>Abstract</title> Decentralized Finance (DeFi) uses blockchain technologies to transform traditional financial activities into decentralized platforms that run without intermediaries and centralized institutions. Smart contracts are programs that run on the blockchain, and by utilizing smart contracts, developers can more easily develop DeFi applications. Some key features of smart contracts -- self-executed and immutability -- ensure the trustworthiness, transparency and efficiency of DeFi applications, and have led to a fast-growing DeFi market. However, misbehaving developers can add traps or backdoor code snippets to a smart contract, which are hard for contract users to discover. We call these code snippets in a DeFi smart contract as ''DeFi Contract Traps" (DCTs). In this paper, we identify five DeFi contract traps and introduce their behaviors, describe how attackers use them to make unfair profits, and analyse their prevalence in the Ethereum platform. We propose a symbolic execution tool, DeFiDefender, to detect such traps and use a manually labeled small-scale dataset that consists of 700 smart contracts to evaluate it. Our results show that our tool is not only highly effective but also highly efficient. DeFiDefender only needs 0.48s to analyze one DeFi smart contract and obtains a high average accuracy (98.17%), precision (99.74%), and recall (89.24%). Among the five DeFi contract traps introduced in this paper, four of them can be detected through contract bytecode without the need for source code. We also apply DeFiDefender to a large-scale dataset that consists of 20,679 real DeFi related Ethereum smart contracts. We found that 52.13% of these DeFi smart contracts contain at least one contract trap. Although a smart contract that contains contract traps is not necessarily malicious, our finding suggests that DeFi related contracts have many centralized issues in a zero-trust environment and in the absence of a trusted party.
BibTeX
@article{chen2024angels,
  author = {Jiachi Chen and Jiang Hu and Xin Xia and David Lo and John Grundy and Zhipeng Gao and Ting Chen},
  title = {{Angels or Demons: Investigating and Detecting Decentralized Financial Traps on Ethereum Smart Contracts}},
  journal = {Autom. Softw. Eng.},
  year = {2024},
  doi = {10.1007/s10515-024-00459-4},
}
Figure