Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Moved owner check from public to internal function in ERC721 contract…
… - resolves issue #4136

Updated ERC721._approve function to include a check for the owner before approval is granted. This ensures that the owner is not accidentally approved and prevents unnecessary sload calls. Moved the check from the public ERC721.approve function to the internal ERC721._approve function. Resolves issue #4136.
  • Loading branch information
ViharGandhi committed Mar 28, 2023
commit 25b649baf535c7d92690b917ffeea11af2eff6ab
3 changes: 2 additions & 1 deletion contracts/token/ERC721/ERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");


require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
Expand Down Expand Up @@ -364,6 +364,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
* Emits an {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
require(to != owner, "ERC721: approval to current owner");
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
Expand Down