Repository navigation
feat: skip zero writes when minting token id 0 - #324
Draft
fulldecent wants to merge 1 commit into
Draft
fulldecent wants to merge 1 commit into
fulldecent wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new zero-ID branches lack regression tests for minting, burning, re-minting, and transfers, leaving supply, enumeration, and index bookkeeping unverified.
1 open issue
What changed in this PR
This draft PR reduces zero-value storage writes in NFTokenEnumerable while preserving global and owner token indexing.
Changes:
- Uses value-less
push()for token ID 0 in global and owner arrays. - Captures the global index before insertion and skips writing
idToIndexwhen that index is zero. - Keeps owner-index writes unconditional, using the owner array’s length before insertion.
| File | Description |
|---|---|
src/contracts/tokens/nf-token-enumerable.sol |
Optimizes zero-ID insertion and index writes in minting and owner assignment. |
Review effort: Balanced
fulldecent
force-pushed
the
enumerable-zero-mint
branch
from
November 15, 2026 14:28
3a2a3ef to
70fb781
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Draft only. This is not for merge.
On top of 2.8.0, token id 0 uses
push()with no value, andidToIndexis not written when the new index is 0. The owner index is still always written.Gas is from one run on Solidity 0.8.38 and the Osaka EVM. The first table has the optimizer off, which is this repository's setting. The second table enables the optimizer for 200 runs.
mint(0)mint(1)mint(0)after another tokenmint(0)mint(1)mint(0)after another tokenWith the optimizer on, the next nonzero mint in this pull request costs 353 gas more than 2.8.0. The other three mints are cheaper.
This uses the trick: