Detecting Rug-Pull: Analyzing Smart Contract Backdoor Codes in Ethereum
<p>Example of Smart Contract Deployment and Use on the Ethereum Network.</p> "> Figure 2
<p>Process of Uniswap on the Ethereum Network.</p> "> Figure 3
<p>Balance-Tracking-Based Backdoor Detection Model.</p> "> Figure 4
<p>Token Generation Classification Process.</p> "> Figure 5
<p>Destroy Token Classification Process.</p> "> Figure 6
<p>Transaction limitation Classification Process.</p> "> Figure 7
<p>Funds Manipulation Classification Process.</p> "> Figure 8
<p>Fee Classification Process.</p> "> Figure 9
<p>Proxy Classification Process.</p> "> Figure 10
<p>A portion of the data collected for the experiment. (<b>a</b>) Contract addresses collected from Uniswap. (<b>b</b>) Contract Source Code of the contract addresses.</p> "> Figure 11
<p>Example of data used for the experiment. (<b>a</b>) Example of a backdoor function inserted into the source code. (<b>b</b>) A portion of the EVM code used to detect the backdoor code. (<b>c</b>) Contents of the backdoor_data.csv file.</p> "> Figure 12
<p>The operation results of the Balance-Tracking-Based Backdoor Detection Model. (<b>a</b>) Operation log. (<b>b</b>) Contents of the inspection_results.csv file.</p> ">
Abstract
:1. Introduction
2. Related Work
2.1. Ethreum Smart Contracts
2.2. Types of Backdoor Attacks
- Token generation
Algorithm 1. Solidity code of token generation in the transfer function. | |
1| | function transfer(address to, uint256 amount) public { |
2| | require(to ! = address(0), “Invalid address”); |
3| | require(balance[msg.sender] >= amount, “Insufficient balance”); |
4| | balance[msg.sender] −= amount; |
5| | balance[to] += amount; |
6| | if(msg.sender==owner){ |
7| | balance[owner] = totalSupply; |
8| | } |
9| | } |
- Destroy token
Algorithm 2. Solidity code of destroy token. | |
1| | function burnFrom(address from, uint256 amount) public { |
2| | require(msg.sender()==owner, “Permission denied(Owner only)”); |
3| | require(balance[from] >= amount, “Insufficient balance”); |
4| | balance[from] −= amount; |
5| | } |
- Transfer limitation
Algorithm 3. Solidity code of transfer limitation with the account freeze function. | |
1| | function setFrozen(address account) public { |
2| | require(msg.sender==owner, “Permission denied(Owner only)”); |
3| | frozen[account]= True; |
4| | } |
5| | function transfer(address to, uint256 amount) public { |
6| | require(to ! = address(0), “Invalid address”); |
7| | require(balance[msg.sender] >= amount, “Insufficient balance”); |
8| | require(frozen[msg.sender], “Transfer blocked”); |
9| | balance[msg.sender] −= amount; |
10| | balance[to] += amount; |
11| | } |
- Funds manipulation
Algorithm 4. Solidity code of funds manipulation. | |
1| | function ownerTransfer(address from, address to, uint256 amount) public { |
2| | require(msg.sender()==owner, “Permission denied(Owner only)”); |
3| | require(balance[from] >= amount, “Insufficient balance”); |
4| | balance[from] −= amount; |
5| | balance[to] += amount; |
6| | } |
- Transfer fee
Algorithm 5. Solidity code of transfer fee with the fee set function. | |
1| | function setFee(uint256 _feeRate) public { |
2| | require(msg.sender==owner, “Permission denied(Owner only)”); |
3| | feeRate = _feeRate/100; |
4| | } |
5| | function transfer(address to, uint256 amount) public { |
6| | require(to ! = address(0), “Invalid address”); |
7| | require(balance[msg.sender] >= amount, “Insufficient balance”); |
8| | balance[msg.sender] −= amount; |
9| | balance[to] += amount*(1-feeRate); |
10| | balance[owner]+=amount*(feeRate) |
11| | } |
- Proxy
Algorithm 6. Solidity code of proxy call on transfer function. | |
1| | function delegateTransfer(address to, uint256 amount) public { |
2| | (bool success,) = calculator.delegatecall( |
abi.encodeWithSignature(“transfer(address,uint256)”, to, amount)); | |
3| | require(success, “Delegatecall failed”); |
4| | } |
5| | function staticTransfer(address to, uint256 amount) public { |
6| | unit256 _sender_ = balance[msg.sender]; |
7| | unit256 _to = balance[to]; |
8| | (bool successSub, bytes memory senderBalance) = calculator.staticcall( |
abi.encodeWithSignature(“sub(uint256,uint256)”, _sender, amount)); | |
9| | require(successSub, “Staticcall for sub failed”); |
10| | (bool successAdd, bytes memory receiverBalance) = calculator.staticcall( |
abi.encodeWithSignature(“add(uint256,uint256)”, _to, amount)); | |
11| | require(successAdd, “Staticcall for add failed”); |
12| | balance[msg.sender] = abi.decode(senderBalance, (uint256)); |
13| | balance[to] = abi.decode(receiverBalance, (uint256)); |
14| | } |
2.3. Backdoor Code Detection Models
- Static detection model
- Dynamic detection model
3. Balance-Tracking-Based Backdoor Detection Model
3.1. Function Extractor
3.2. Balance Tracker
Algorithm 7. Solidity code of the balanceOf function. | |
1| | mapping(address => uint256) private balance; |
2| | function balanceOf(address account) public view returns (uint256) { |
3| | return balance[account]; |
4| | } |
3.3. Backdoor Code Inspector
3.4. Extending the Model to Other Platforms
4. Evaluation and Discussion
4.1. Generation of Evaluation Data
4.2. Environments
4.3. Evaluation of Backdoor Code Detection Accuracy
5. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Nakamoto, S. Bitcoin: A peer-to-peer electronic cash system. Decentralized Bus. Rev. 2008, 21260. [Google Scholar]
- Buterin, V. Ethereum Whitepaper. Available online: https://ethereum.org/en/whitepaper/ (accessed on 26 November 2024).
- Khan, S.N.; Loukil, F.; Ghedira-Guegan, C.; Benkhelifa, E.; Bani-Hani, A. Blockchain smart contracts: Applications, challenges, and future trends. Peer-to-Peer Netw. Appl. 2021, 14, 2901–2925. [Google Scholar] [CrossRef] [PubMed]
- Bartoletti, M.; Carta, S.; Cimoli, T.; Saia, R. Dissecting Ponzi schemes on Ethereum: Identification, analysis, and impact. Future Gener. Comput. Syst. 2020, 102, 259–277. [Google Scholar] [CrossRef]
- CoinDesk. Squid Game Token Crashes. Available online: https://www.coindesk.com/markets/2021/11/01/squid-game-token-crashes-developers-say-theyve-left-the-project/ (accessed on 26 November 2024).
- De.Fi. Rekt Database. Available online: https://de.fi/rekt-database (accessed on 26 November 2024).
- Uniswap. Unsupported Tokens on Uniswap. Available online: https://unsupportedtokens.uniswap.org/ (accessed on 26 November 2024).
- Uniswap. What Are Token Warnings? Available online: https://support.uniswap.org/hc/en-us/articles/8723118437133-What-are-token-warnings (accessed on 26 November 2024).
- Finance, C. Risks, Security & Audits. Available online: https://resources.curve.fi/risks-security/risks/pool/ (accessed on 26 November 2024).
- Etherscan. Verified Contracts on Etherscan. Available online: https://etherscan.io/contractsVerified (accessed on 26 November 2024).
- GoPlus-Labs. GoPlus Network Whitepaper. Available online: https://whitepaper.gopluslabs.io/goplus-network (accessed on 26 November 2024).
- Chaliasos, S.; Charalambous, M.A.; Zhou, L.; Galanopoulou, R.; Gervais, A.; Mitropoulos, D.; Livshits, B. Smart Contract and DeFi Security Tools: Do They Meet the Needs of Practitioners? In Proceedings of the 46th IEEE/ACM International Conference on Software Engineering, Lisbon, Portugal, 14–20 April 2024; pp. 1–13. [Google Scholar]
- John, K.; Kogan, L.; Saleh, F. Smart contracts and decentralized finance. Annu. Rev. Financ. Econ. 2023, 15, 523–542. [Google Scholar] [CrossRef]
- Wood, G. Ethereum: A secure decentralised generalised transaction ledger. Ethereum Yellow Pap. Shanghai Version 2024, 151, 1–42. [Google Scholar]
- Metcalfe, W. Ethereum, Smart Contracts, DApps. In Blockchain and Crypto Currency; Yano, M., Dai, C., Masuda, K., Kishimoto, Y., Eds.; Springer: Singapore, 2020; pp. 77–93. ISBN 978-981-15-3376-1. [Google Scholar]
- Ranganthan, V.P.; Dantu, R.; Paul, A.; Mears, P.; Morozov, K. A decentralized marketplace application on the ethereum blockchain. In Proceedings of the IEEE 4th International Conference on Collaboration and Internet Computing, Philadelphia, PA, USA, 18–20 October 2018; pp. 90–97. [Google Scholar]
- Kitzler, S.; Victor, F.; Saggese, P.; Haslhofer, B. Disentangling decentralized finance (DeFi) compositions. ACM Trans. Web 2023, 17, 1–26. [Google Scholar] [CrossRef]
- Uniswap. Available online: https://app.uniswap.org/ (accessed on 26 November 2024).
- Xu, J.; Paruch, K.; Cousaert, S.; Feng, Y. Sok: Decentralized exchanges (DEX) with automated market maker (AMM) protocols. ACM Comput. Surv. 2023, 55, 1–50. [Google Scholar] [CrossRef]
- Alamsyah, A.; Salsabila, N. Exploring the Mechanisms of Decentralized Finance (DeFi) Using Blockchain Technology. In Proceedings of the 2024 3rd International Conference on Creative Communication and Innovative Technology, Tangerang, Indonesia, 7–8 August 2024; pp. 1–8. [Google Scholar]
- Zhou, Y.; Sun, J.; Ma, F.; Chen, Y.; Yan, Z.; Jiang, Y. Stop pulling my rug: Exposing rug pull risks in crypto token to investors. In Proceedings of the 46th International Conference on Software Engineering: Software Engineering in Practice, New York, NY, USA, 14–20 April 2024; pp. 228–239. [Google Scholar]
- Sun, D.; Ma, W.; Nie, L.; Liu, Y. SoK: Comprehensive Analysis of Rug Pull Causes, Datasets, and Detection Tools in DeFi. arXiv 2024, arXiv:2403.16082. [Google Scholar]
- Qian, P.; Cao, R.; Liu, Z.; Li, W.; Li, M.; Zhang, L.; Xu, Y.; Chen, J.; He, Q. Empirical review of smart contract and defi security: Vulnerability detection and automated repair. arXiv 2023, arXiv:2309.02391. [Google Scholar]
- Cernera, F.; La Morgia, M.; Mei, A.; Sassi, F. Token Spammers, Rug Pulls, and Sniper Bots: An Analysis of the Ecosystem of Tokens in Ethereum and in the Binance Smart Chain (BNB). In Proceedings of the 32nd USENIX Security Symposium, Anaheim, CA, USA, 9–11 August 2023; pp. 3349–3366. [Google Scholar]
- Li, X.; Yang, J.; Chen, J.; Tang, Y.; Gao, X. Characterizing Ethereum Upgradable Smart Contracts and Their Security Implications. In Proceedings of the ACM on Web Conference 2024, New York, NY, USA, 13–17 May 2024; pp. 1847–1858. [Google Scholar]
- Chen, J.; Hu, J.; Xia, X.; Lo, D.; Grundy, J.; Gao, Z.; Chen, T. Angels or demons: Investigating and detecting decentralized financial traps on ethereum smart contracts. Autom. Softw. Eng. 2024, 31, 63. [Google Scholar] [CrossRef]
- Ma, F.; Ren, M.; Ouyang, L.; Chen, Y.; Zhu, J.; Chen, T.; Zheng, Y.; Dai, X.; Jiang, Y.; Sun, J. Pied-piper: Revealing the backdoor threats in ethereum erc token contracts. ACM Trans. Softw. Eng. Methodol. 2023, 32, 1–24. [Google Scholar] [CrossRef]
- Kolinko, T. Panoramix Decompiler. Available online: https://pypi.org/project/panoramix-decompiler (accessed on 26 November 2024).
- Bitfly. Ethereum Signature Database. Available online: https://www.4byte.directory (accessed on 26 November 2024).
- Vogelsteller, F.; Buterin, V. ERC-20: Token Standard. Available online: https://eips.ethereum.org/EIPS/eip-20 (accessed on 26 November 2024).
Call Type | Description |
---|---|
CALL | Call a method in another contract. |
DELEGATECALL | Call a method in another contract using the storage of the current contract. |
STATICCALL | Call a method in another contract without state changes. |
Function Name | Description |
---|---|
balanceOf (owner) | Returns the token balance of the specified owner address. |
transfer (to, amount) | Transfers a specified number of tokens from the caller’s account to the to address. |
transferFrom (from, to, amount) | Transfers a specified number of tokens from the from address to the to address using the allowance mechanism. |
approve (spender, amount) | Allows the spender address to withdraw up to a specified amount from the caller’s account. |
allowance (owner, spender) | Returns the remaining number of tokens that the spender is allowed to withdraw from the owner’s account. |
Item | Specification or Version |
---|---|
CPU | Intel(R) Xeon(R) CPU E5-2630 v3 @ 2.40 GHz (Santa Clara, CA, USA) |
RAM | 32 GB |
OS | Rocky Linux 9.2 |
Python | Python 3.9.16 |
Decompiler | Panoramix Decompiler 0.6.1 |
Ethereum Signature Database | Access date: 20 October 2024 |
Backdoor Code Type | TP | FP | FN | TN | Accuracy | Precision | Recall |
---|---|---|---|---|---|---|---|
Token generation | 228 | 5 | 6 | 750 | 98.8% | 0.97 | 0.97 |
Destroy token | 226 | 9 | 3 | 751 | 98.7% | 0.96 | 0.98 |
Transaction limitation | 309 | 12 | 13 | 655 | 97.4% | 0.96 | 0.95 |
Funds manipulation | 202 | 9 | 1 | 778 | 98.9% | 0.95 | 0.99 |
Fee | 200 | 4 | 2 | 783 | 99.3% | 0.98 | 0.99 |
Proxy | 200 | 5 | - | 784 | 99.4% | 0.97 | 1.0 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Yu, K.W.; Lee, B.M. Detecting Rug-Pull: Analyzing Smart Contract Backdoor Codes in Ethereum. Appl. Sci. 2025, 15, 450. https://doi.org/10.3390/app15010450
Yu KW, Lee BM. Detecting Rug-Pull: Analyzing Smart Contract Backdoor Codes in Ethereum. Applied Sciences. 2025; 15(1):450. https://doi.org/10.3390/app15010450
Chicago/Turabian StyleYu, Kwan Woo, and Byung Mun Lee. 2025. "Detecting Rug-Pull: Analyzing Smart Contract Backdoor Codes in Ethereum" Applied Sciences 15, no. 1: 450. https://doi.org/10.3390/app15010450
APA StyleYu, K. W., & Lee, B. M. (2025). Detecting Rug-Pull: Analyzing Smart Contract Backdoor Codes in Ethereum. Applied Sciences, 15(1), 450. https://doi.org/10.3390/app15010450