Skip to content

Remove enumerable from ERC721 and add an ERC721Enumerable extension#2511

Merged
frangio merged 30 commits into
OpenZeppelin:masterfrom
Amxx:feature/ERC721Light
Feb 19, 2021
Merged

Remove enumerable from ERC721 and add an ERC721Enumerable extension#2511
frangio merged 30 commits into
OpenZeppelin:masterfrom
Amxx:feature/ERC721Light

Conversation

@Amxx

@Amxx Amxx commented Feb 5, 2021

Copy link
Copy Markdown
Collaborator

EnumerableSet and EnumerableMap heavily rely on sstore & sload, which are very expensive operations. At the same time, the Enumerable aspect can be tracked offchain using tools like thegraph.

Developer should have the choice between having this enumerable functionality (and pay the gas price), or drop it if onchain access to these information is sufficient.

PR Checklist

  • Tests
  • Documentation
  • Changelog entry

@Amxx Amxx force-pushed the feature/ERC721Light branch from 311b3bc to 0383c05 Compare February 5, 2021 14:23
@Amxx

Amxx commented Feb 12, 2021

Copy link
Copy Markdown
Collaborator Author

Average gas usage given by eth-gas-reporter

Version mint transferFrom burn
master:erc721 156250 94901 49499
this:erc721 59397 53281 25981
this:erc721enumerable 134981 63952 41720

@Amxx Amxx marked this pull request as ready for review February 17, 2021 17:56

@frangio frangio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall.

Comment thread CHANGELOG.md Outdated
Comment thread contracts/token/ERC721/ERC721.sol Outdated
Comment thread contracts/token/ERC721/ERC721.sol Outdated
Comment thread test/token/ERC721/ERC721Enumerable.test.js Outdated
Comment thread test/token/ERC721/ERC721Enumerable.test.js Outdated
Comment thread test/token/ERC721/ERC721.behavior.js Outdated
Comment on lines +70 to +79
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a little clearer.

Suggested change
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
}
if (to != from) {
_removeTokenFromOwnerEnumeration(from, tokenId);
_addTokenToOwnerEnumeration(to, tokenId);
}

@Amxx Amxx Feb 19, 2021

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would not work:

  • _removeTokenFromOwnerEnumeration(from, tokenId); must not be called if from == address(0)
  • _addTokenToOwnerEnumeration(to, tokenId); must not be called if to == address(0)

Comment thread contracts/token/ERC721/ERC721.sol Outdated
@frangio frangio force-pushed the feature/ERC721Light branch from a679d75 to c39ef2d Compare February 19, 2021 15:46

@frangio frangio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants