Skip to content

Commit

Permalink
Moved owner check from public to internal function in ERC721 contract…
Browse files Browse the repository at this point in the history
… - resolves issue OpenZeppelin#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 OpenZeppelin#4136.
  • Loading branch information
ViharGandhi committed Mar 28, 2023
1 parent ca82221 commit 25b649b
Showing 1 changed file with 2 additions and 1 deletion.
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

0 comments on commit 25b649b

Please sign in to comment.