OpenZeppelin / OpenZeppelin/openzeppelin-contracts

ERC20 contract loses tokens sent to the contract's own address

Open
#3,157 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Solidity
Stars
27.2k
Forks
12.4k
Avg merge
2d 19h
Merged PRs (30d)
33

Description

🧐 Motivation
Many people lose their ERC20 tokens by mistakenly sending their tokens back to the token contract address (presumably to redeem their tokens). However, there is no way to recover those tokens.
https://np.reddit.com/r/ethereum/comments/sfz4kw/did_i_just_lose_half_a_million_dollars_by_sending/

📝 Details
ERC20 implementation should reject such transfers.
For example, we may add a require statement to the _transfer function in ERC20.sol.

    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal virtual {
        ...
        require(recipient != address(this), "ERC20: transfer to the token contract address");
        ...
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with contracts/token/ERC20/ERC20.sol and inspect the _transfer function and its surrounding behavior. Confirm how transfers to the token contract address are currently handled, then verify that the completed change rejects that destination without affecting other ERC20 transfers.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity
Domain
blockchain, security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.