TL;DR
While Decentralized Finance (DeFi) promises a "trustless" financial system, many smart contracts contain intentional "backdoors" that allow developers to unfairly profit at the expense of users. This paper introduces DeFiDefender, a symbolic execution tool that identifies five specific "DeFi Contract Traps" (DCTs), revealing that over 52% of analyzed Ethereum DeFi contracts contain at least one such trap.
What Problem Does This Paper Address?
The core appeal of 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 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. The paper seeks to categorize these traps, understand their prevalence, and provide an automated way to detect them before users lose their assets.
Methods
The authors developed DeFiDefender, a tool designed to detect DCTs using a combination of symbolic execution and Abstract Syntax Tree (AST) analysis.
The tool's workflow is split based on the type of trap:
- Bytecode Analysis: For four of the five traps, 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
selfdestructfunction reachable only by the owner). - 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).
Datasets
The study utilized two primary datasets:
- Small-scale Dataset: 700 manually labeled DeFi smart contracts used to evaluate the tool's accuracy. This dataset was curated by independent developers with years of experience in smart contract security.
- Large-scale Dataset: 20,679 real-world DeFi-related Ethereum smart contracts extracted from a pool of over 117,000 verified contracts on Etherscan (as of February 2022).
Key Insights and Ideas
- DCTs vs. Vulnerabilities: This is the paper's most important conceptual contribution. A vulnerability is a bug; a DCT is a "feature" for the owner. While a vulnerability might hurt both the owner and the user, a DCT specifically benefits the owner at the user's expense.
- The "Centralization" Paradox: Despite the "decentralized" label, the high prevalence of these traps suggests that many DeFi projects maintain centralized control. Owners can often change interest rates, drain funds, or destroy the contract at will.
- The Five Traps:
- Tricky Send: Deliberately failing to check the return value of a transfer, allowing the contract to "clear" a user's balance even if the money wasn't actually sent.
- Super Storage Permission: Backdoors that let owners change critical variables (like interest rates) after deployment.
- Super Transfer Permission: Functions that allow owners to drain the contract's Ether balance.
- Selfdestruct Permission: The "rug pull" button; owners can kill the contract and pocket all remaining funds.
- Forged Transfer: Misleading users by putting withdrawal logic in subcontracts that are never actually inherited or called by the main contract.
Key Results
- High Efficiency: DeFiDefender is remarkably fast, requiring only 0.48 seconds on average to analyze a single contract.
- Strong Accuracy: 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%.
- Widespread Prevalence: In the large-scale analysis of ~20k contracts, 52.13% 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.
Limitations and Future Work
- Intent vs. Functionality: The authors acknowledge that the presence of a trap doesn't guarantee malicious intent. Some "traps" might be intended as emergency "circuit breakers." Future work aims to analyze historical transactions to see if these traps were actually used maliciously.
- Path Explosion: As smart contracts grow in complexity, symbolic execution faces the "path explosion" problem, where the number of possible execution paths becomes too large to process.
- Source Code Dependency: The "Forged Transfer" trap currently requires source code for detection, which isn't always available on the blockchain.
- Evasion: Now that these patterns are defined, malicious developers may find more sophisticated ways to obfuscate these traps to bypass detection tools.
Summary updated