-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
5300 Gas Cost for Unnecessary Delete in ERC721Token.sol #977
Comments
Thanks for the report @mudgen. Can you please make a pull request making sure that the removeFrom is fully tested to ensure that the behaviour is preserved? |
@ElOpio I don't have sufficient incentive/motivation to make a pull request and test this further. I tested it for myself and that is enough for me. I mentioned it to OpenZepplin to help out. |
Alright, thanks @mudgen. We'll take a look when our backlog is smaller, or when somebody else jumps to it. |
I would love to work on this @ElOpio. Starting on it |
In the removeTokenFrom function
ownedTokens[_from][lastTokenIndex]
is set to 0 twice instead of once. The main reason this is not good beside redundant is because it costs gas. From my tests this unneeded redundancy costs 5300 gas.Here is the code I am talking about:
The first line obviously sets ownedTokens[_from][lastTokenIndex] to 0. Reducing the length of the array also sets ownedTokens[_from][lastTokenIndex] to 0.
So it makes sense to get rid of this line:
ownedTokens[_from][lastTokenIndex] = 0;
.The text was updated successfully, but these errors were encountered: