Skip to content

Prevent users from sending Bread tokens to the token contract address (address(this)) #34

@RonTuretzky

Description

@RonTuretzky

Problem

Currently, users can mistakenly send Bread tokensdirectly to the Bread token contract address using , which results in the tokens being lost or locked. This is a common issue in ERC20 contracts where users may not realize that sending tokens to the contract address is unsafe.

Requirements

  • Prevent users from sending Bread tokens or ETH to the Bread token contract address (i.e., using address(this)).
  • Add logic to revert or prevent such transactions.
  • Provide user feedback (via revert messages) if a transfer is attempted to the token contract address.
  • Update relevant documentation and tests.

Proposed Solution

  • Implement a check in the transfer and transferFrom functions to revert if the recipient address is address(this).
  • Implement a receive() and/or fallback() function that reverts to prevent accidental ETH transfers.

Sequence Diagram

sequenceDiagram
    participant User
    participant BreadTokenContract
    User->>BreadTokenContract: transfer(address(this), amount)
    BreadTokenContract-->>User: revert("Cannot send to token contract address")

    User->>BreadTokenContract: send ETH to address(this)
    BreadTokenContract-->>User: revert("Cannot send ETH to token contract address")
Loading

Solidity Code Snippet

// Example for ERC20 transfer and transferFrom prevention
function transfer(address to, uint256 amount) public override returns (bool) {
    require(to != address(this), "Cannot send to token contract address");
    return super.transfer(to, amount);
}

function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
    require(to != address(this), "Cannot send to token contract address");
    return super.transferFrom(from, to, amount);
}

Acceptance Criteria

  • Attempting to transfer tokens to the contract address should revert with a clear error message.
  • Documentation and tests are updated to reflect this behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions