Skip to content

Conversation

@Abidoyesimze
Copy link

Fixes the critical bug in LibERC721Enumerable.mint() where the ownerOf mapping was not being set for newly minted tokens. This caused minted tokens to be unusable - they existed in enumeration arrays but had no recorded owner, making ownerOf() queries fail and preventing any transfers.
The fix adds the single missing line s.ownerOf[_tokenId] = _to; to properly record token ownership during minting, matching the implementation in the standard LibERC721 library.
Changes Made
Bug Fix
src/token/ERC721/ERC721Enumerable/LibERC721Enumerable.sol: Added missing s.ownerOf[_tokenId] = _to assignment in mint() function (line 126)
Test Coverage Added
test/token/ERC721/ERC721Enumerable/LibERC721Enumerable.t.sol: 32 comprehensive tests for the library's internal functions (mint, burn, transfer, enumeration)
test/token/ERC721/ERC721Enumerable/ERC721EnumerableFacet.t.sol: 42 comprehensive tests for the facet's public interface
test/token/ERC721/ERC721Enumerable/harnesses/: Test harnesses to expose internal library functions for testing

Code is formatted with forge fmt
Tests are included - All new functionality has comprehensive tests
All tests pass - Run forge test and ensure everything works

Test Results
All 429 tests pass successfully:
Test Coverage Details
LibERC721Enumerable: 32 tests covering mint (with owner verification), burn, transfer, enumeration tracking, edge cases, and fuzz tests
ERC721EnumerableFacet: 42 tests covering all public functions including metadata, balance/ownership queries, enumeration, approvals, transfers, and safe transfers
The tests specifically validate the bug fix by asserting that ownerOf() returns the correct address after minting, which was the core issue.

The mint function in LibERC721Enumerable was missing the critical
s.ownerOf[_tokenId] = _to assignment, causing newly minted tokens
to have no recorded owner. This resulted in ownerOf() queries
failing and transfers being impossible.

This fix adds the missing line to properly set token ownership
during minting, matching the implementation in the standard
LibERC721 library.

Includes comprehensive test coverage:
- 32 tests for LibERC721Enumerable (mint, burn, transfer, enumeration)
- 42 tests for ERC721EnumerableFacet (all public functions)
@github-actions
Copy link

Coverage Report

Coverage

Metric Coverage Details
Lines 60% 705/1168 lines
Functions 72% 157/219 functions
Branches 43% 80/186 branches

Last updated: Fri, 31 Oct 2025 13:29:17 GMT for commit 06bd97d

@github-actions
Copy link

Gas Report

No gas usage changes detected between main and fix/erc721-enumerable-mint-owner.

All functions maintain the same gas costs. ✅

Last updated: Fri, 31 Oct 2025 13:29:34 GMT for commit 06bd97d

@adamgall
Copy link
Collaborator

Hey @Abidoyesimze , thank you for your work on this!

I'm going to close this PR without merging. My reasoning is as follows:

  1. tests: Add test for erc721 #111 is where ERC721 tests were originally created, and this is where the bug was identified. This PR has not been merged yet.
  2. Fix #159 : LibERC721Enumerable.sol now set token owner during mint to resolve missing ownership  #160 simply fixes the bug. I've decided to merge this PR.
  3. This PR (fix: set ownerOf in LibERC721Enumerable mint function #161) fixes the bug, but also reimplements the ERC721 tests from tests: Add test for erc721 #111.

Now that the bug is fixed on main, #111 can be merged (after another small tweak or two) which will get all of the ERC721 tests into main.

@adamgall adamgall closed this Oct 31, 2025
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.

2 participants