You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 preventionfunction transfer(addressto, uint256amount) publicoverridereturns (bool) {
require(to !=address(this), "Cannot send to token contract address");
returnsuper.transfer(to, amount);
}
function transferFrom(addressfrom, addressto, uint256amount) publicoverridereturns (bool) {
require(to !=address(this), "Cannot send to token contract address");
returnsuper.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.
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
address(this)).Proposed Solution
transferandtransferFromfunctions to revert if the recipient address isaddress(this).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
Acceptance Criteria