-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Use unchecked for ERC721 balance updates #3524
Conversation
Given that we want to explore batch minting in ERC721 it seems we should not merge this, as the assumption that minting happens one at a time will be invalidated. Also please include benchmarks, what kind of improvement do you see with this PR? Use of unchecked should be accompanied by comments explaining why it's safe. |
I understand that we want to experiment new minting mechanism. However, I believe that these minting mechanisms should remain ERC721 compliant, which means emitting a Transfer event for all the tokens ids. This means that, in practice, it's impossible to mint all the tokens, and the balance increment overflow is not an issue. |
For reference: https://twitter.com/optimizoor/status/1544626818996613120?t=8tV84gD3blTSsxk14EotiQ TLDR: batch minting should be limited to "not to big batches" ... which means that the limit should never be reached, even minting 10**18 token each time |
Co-authored-by: Francisco <frangio.1@gmail.com>
I believe once #3611 is merged, the requested changes will no longer be needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Co-authored-by: Francisco <frangio.1@gmail.com>
Co-authored-by: Francisco <frangio.1@gmail.com>
Following the logic in described in #3512 (comment).
_balances
are private_balances
are only increased/decreased when tokens are minted, burned, or transferredA balance cannot decrease below 0 because that would require transferring/burning more tokens out of a wallet than were transferred/minted to this wallet in the first place.
The balance cannot overflow, because that would require minting all the tokenIds, and putting them all in the same wallet (there are 2**256 tokenIds, so that would overflow by one). While this is mathematically possible, it is impossible in practice (with token being transferred/minted one at a time)
PR Checklist