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

Optimized ERC721 transfers. #1539

Merged
merged 4 commits into from
Dec 11, 2018
Merged

Conversation

nventuro
Copy link
Contributor

@nventuro nventuro commented Dec 4, 2018

Credit goes to @abandeali1 for coming up with the original idea in #1031.

Because Solidity doesn't inline internal calls, it misses the opportunity to optimize consecutive SSTOREs to the same location, leading to extra gas costs in the current ERC721 implementation (where transfer is implemented as removeFrom followed by addTo). This PR adds a new function that encapsulates this behavior, implementing the optimization directly on the source code.

@nventuro nventuro added kind:improvement contracts Smart contract code. labels Dec 4, 2018
@nventuro nventuro added this to the v2.1 milestone Dec 4, 2018
@nventuro nventuro self-assigned this Dec 4, 2018
@nventuro nventuro requested a review from frangio December 4, 2018 20:30
@nventuro nventuro mentioned this pull request Dec 4, 2018
4 tasks
@nventuro
Copy link
Contributor Author

nventuro commented Dec 4, 2018

For reference, a call to transferFrom has an execution cost of 56337 gas before this PR, and 35520 gas after.

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.

Save for my Transfer comment above, the logic LGTM.

contracts/token/ERC721/ERC721Enumerable.sol Outdated Show resolved Hide resolved
contracts/token/ERC721/ERC721Enumerable.sol Outdated Show resolved Hide resolved
@nventuro
Copy link
Contributor Author

nventuro commented Dec 5, 2018

Coverage dropped since a condition of remove was only being checked in burn and not transfer: I'll add the necessary tests. Due to #1148 this may be a bit painful, we might want to prioritize working on it sometime soon (2.2.0?).

I'll check coveralls and see if we're missing a setting, since this should've been a test failure.

@frangio
Copy link
Contributor

frangio commented Dec 5, 2018

Definitely. Created a v2.2 milestone.

@nventuro
Copy link
Contributor Author

nventuro commented Dec 5, 2018

@frangio please review the new _transferFrom function. Coverage will probably remain below 100%, I'll review that once the results are in.

@nventuro
Copy link
Contributor Author

nventuro commented Dec 5, 2018

Created #1541 to track future work that could be done here (don't want to increase the scope of this PR).

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.

👍 to _transferFrom.

I have huge doubts about the new _removeTokenFromOwnerEnumeration function. See comments below.

contracts/token/ERC721/ERC721.sol Outdated Show resolved Hide resolved
contracts/token/ERC721/ERC721Enumerable.sol Show resolved Hide resolved
contracts/token/ERC721/ERC721Enumerable.sol Show resolved Hide resolved
@frangio
Copy link
Contributor

frangio commented Dec 7, 2018

There seems to be missing coverage in ERC721. https://coveralls.io/jobs/42933704/source_files/440498540

@nventuro
Copy link
Contributor Author

We should be good now - due to the original refactor _clearApprovals had a bizarre (and redundant) require that wasn't being tested, getting rid of it keeps the original public/internal API the same.

@frangio should be ready to merge now.

@frangio frangio self-requested a review December 10, 2018 15:40
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.

Nice work!

@nventuro nventuro merged commit 70e616d into OpenZeppelin:master Dec 11, 2018
@nventuro nventuro deleted the erc721-optim branch December 11, 2018 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contracts Smart contract code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants