-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
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
transferandtransferFromfunctions to revert if the recipient address isaddress(this). - Implement a
receive()and/orfallback()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")
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
Labels
No labels