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

0xInu~ _packedOwnershipOf optimization, saving 2143 gas on transfers #433

Merged
merged 1 commit into from
Nov 15, 2022
Merged

Conversation

0xInuarashi
Copy link
Contributor

Summary:

  • mint becomes ~22 gas units cheaper
  • transfer of uninitialized tokens (using lookup trace) becomes ~21 gas units more expensive
  • transfer of initialized tokens (no lookup trace) becomes ~2143 gas units cheaper
ERC721A: 
1>Mint(a,5): 98279
2>TransferFrom(a,b,3): 107582
3>TransferFrom(a,b,1): 86054
4>TransferFrom(b,a,1): 44343
5>TransferFrom(b,a,3): 39543
6>Mint(a,50): 151064
7>TransferFrom(a,b,50): 200570
ERC721A 0xInu Optimization: 
1>Mint(a,5): 98257
2>TransferFrom(a,b,3): 107603
3>TransferFrom(a,b,1): 86075
4>TransferFrom(b,a,1): 42200
5>TransferFrom(b,a,3): 37400
6>Mint(a,50): 151042
7>TransferFrom(a,b,50): 200591

@0xInuarashi
Copy link
Contributor Author

The assumption is that, if the packed token data exists, it must already be within-bounds of < _currentIndex
Thus, if the token data exists (and in this case, it is also not burnt), we can save 1 SLOAD by skipping the _currentIndex and go straight to returning the already-initialized token data.

@Vectorized
Copy link
Collaborator

Holy shit, this is gigabrain.

contracts/ERC721A.sol Show resolved Hide resolved
@cygaar
Copy link
Collaborator

cygaar commented Nov 9, 2022

Good catch

@Vectorized Vectorized merged commit 09c0e11 into chiru-labs:main Nov 15, 2022
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.

3 participants