Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove enumerable from ERC721 and add an ERC721Enumerable extension #2511

Merged
merged 30 commits into from
Feb 19, 2021

Conversation

Amxx
Copy link
Collaborator

@Amxx Amxx commented Feb 5, 2021

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
Copy link
Collaborator Author

Amxx commented Feb 12, 2021

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
Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

Looks good overall.

CHANGELOG.md Outdated Show resolved Hide resolved
contracts/token/ERC721/ERC721.sol Outdated Show resolved Hide resolved
contracts/token/ERC721/ERC721.sol Outdated Show resolved Hide resolved
test/token/ERC721/ERC721Enumerable.test.js Outdated Show resolved Hide resolved
test/token/ERC721/ERC721Enumerable.test.js Outdated Show resolved Hide resolved
test/token/ERC721/ERC721.behavior.js Outdated Show resolved Hide resolved
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
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);
}

Copy link
Collaborator Author

@Amxx Amxx Feb 19, 2021

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)

contracts/token/ERC721/ERC721.sol Outdated Show resolved Hide resolved
@frangio frangio force-pushed the feature/ERC721Light branch from a679d75 to c39ef2d Compare February 19, 2021 15:46
Copy link
Contributor

@frangio frangio left a comment

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