--
ERC777 tokens have somehow gained popularity due to their enhanced functionality compared to traditional ERC20 tokens. However, it’s essential to understand potential vulnerabilities.
In this article, we’ll delve into ERC777 tokens and explore how they can be leveraged by external users to launch a Denial-of-Service (DOS) attack on a smart contract, “thanks” to their hooks and callbacks.
Prefer to watch a video? Check out this vulnerability breakdown from a READ smart contract audit contest:
ERC777 is a token standard on the Ethereum blockchain that offer features such as improved fungibility, built-in hooks, and callbacks while preserving backward compatiblity with ERC20 tokens.
These hooks enable developers to customize the token’s behavior when it interacts with smart contracts, creating opportunities for unique functionalities.
Hooks in ERC777 tokens serve as entry points for custom code execution during token transfers. They allow external smart contracts to intervene in the token transfer process, either before or after the transfer occurs. This flexibility is a double-edged sword, as it can be used for legitimate purposes but also exploited for malicious actions.
Receive hooks are at the heart of ERC777’s innovation. They are functions within a contract that get invoked when tokens are sent to it. This functionality allows both user accounts and contracts to react dynamically to incoming tokens, opening the door for some use cases:
- Atomic Purchases: ERC777 enables atomic token purchases, eliminating the need for separate “approve” and “transferFrom” transactions, simplifying complex token trades.
- Token Rejection: Contracts can now reject token receptions by reverting transactions during the hook call, providing granular control over token flows.
- Token Routing: Similar to how PaymentSplitter operates, ERC777 allows for the redirection of received tokens to other addresses, facilitating automated fund distribution.
To understand how ERC777 tokens can be weaponized for a DOS attack, let’s consider a hypothetical scenario:
- Malicious Token Receiver: An external user is supposed to receive ERC777 tokens from a contract decides to execute a DOS attack on a smart contract.
- Token Distribution: The smart contract distributes ERC777 tokens to multiple users.
- Callback Reversion: The malicious token receiver is a smart contract account that is programmed to revert the transaction, effectively blocking any further execution within the smart contract.
- The token distribution process is aborted and can’t be executed, and no user receives tokens.
- (Bonus) Gas Consumption: Reverting a transaction consumes gas, and since Ethereum operates on a gas-based system, this can lead to a waste of resources, impacting the network’s efficiency.
If you need a stronger smart contract security foundation where you will learn about all kinds of smart contract hacking techniques including ERC777 vulnerabilities, consider enrolling a comprehensive Smart Contract Hacking Course.
This course offers a structured approach with over 30 videos and 40+ exercises, including walkthrough videos, to help you master smart contract hacking.
By taking this course, you’ll build a solid foundation in smart contract security, making you well-prepared for potential opportunities as a smart contract auditor. Moreover, you’ll gain access to an exclusive closed community, where you can interact and learn from fellow students and top-notch instructors.
Upon successfully completing the course and passing the final test, you’ll receive an official Smart Contract Hacker Certificate, validating your expertise in the field.
Get a limited-time discount using this link:
https://bit.ly/sch-disoc*nt-2023
Mitigation Strategies & Conclusion
The best way to stay safe from potential problems like DOS attacks and reentrancy issues related to ERC777 tokens is to be careful about using them. These tokens come with extra features that can be risky. To protect your protocols, it’s a good idea to stick with simpler and more established tokens like ERC20. By doing this, you lower the chances of facing these security issues and make your protocol more secure and stable.