Browse Source

Implicitly clear ERC721 approval on burn (#3538)

EthanOK 3 years ago
parent
commit
96163c87e3
3 changed files with 2 additions and 5 deletions
  1. 1 0
      CHANGELOG.md
  2. 1 1
      contracts/token/ERC721/ERC721.sol
  3. 0 4
      test/token/ERC721/ERC721.behavior.js

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@
  * `GovernorCompatibilityBravo`: remove unused `using` statements ([#3506](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3506))
  * `ERC20`: optimize `_transfer`, `_mint` and `_burn` by using `unchecked` arithmetic when possible. ([#3513](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3513))
  * `ERC721`: optimize transfers by making approval clearing implicit instead of emitting an event. ([#3481](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3481))
+ * `ERC721`: optimize burn by making approval clearing implicit instead of emitting an event. ([#3538](https://github.com/OpenZeppelin/openzeppelin-contracts/pull/3538))
 
 ### Compatibility Note
 

+ 1 - 1
contracts/token/ERC721/ERC721.sol

@@ -306,7 +306,7 @@ contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
         _beforeTokenTransfer(owner, address(0), tokenId);
 
         // Clear approvals
-        _approve(address(0), tokenId);
+        delete _tokenApprovals[tokenId];
 
         _balances[owner] -= 1;
         delete _owners[tokenId];

+ 0 - 4
test/token/ERC721/ERC721.behavior.js

@@ -693,10 +693,6 @@ function shouldBehaveLikeERC721 (errorPrefix, owner, newOwner, approved, another
           expectEvent(this.receipt, 'Transfer', { from: owner, to: ZERO_ADDRESS, tokenId: firstTokenId });
         });
 
-        it('emits an Approval event', function () {
-          expectEvent(this.receipt, 'Approval', { owner, approved: ZERO_ADDRESS, tokenId: firstTokenId });
-        });
-
         it('deletes the token', async function () {
           expect(await this.token.balanceOf(owner)).to.be.bignumber.equal('1');
           await expectRevert(