In an ERC721 token, the tokenURI function is expected to return the metadata URI for a valid token. The standard practice is to first verify that the token exists, reverting with an appropriate error if it does not. Many implementations, including OpenZeppelin’s, use _exists or rely on ownerOf (which reverts on non‑existent tokens) to perform this check.
In the Snowman contract, the tokenURI function attempts to validate existence by checking whether ownerOf(tokenId) == address(0). However, the OpenZeppelin ownerOf implementation does not return address(0) for non‑existent tokens; it reverts immediately. As a result, the condition ownerOf(tokenId) == address(0) can never evaluate to true, and the subsequent revert statement is unreachable.
Likelihood:
The condition will never be satisfied in any execution path, because ownerOf always reverts for non‑existent tokens.
The dead code is permanently included in the deployed bytecode, regardless of how the function is used.
Impact:
Increased deployment cost – The superfluous code consumes gas when the contract is deployed.
No impact on runtime behaviour – The function still correctly reverts via ownerOf, but the custom error is never thrown.
The following Foundry test demonstrates that calling tokenURI with a non‑existent token ID reverts with the default OpenZeppelin error (ERC721NonexistentToken), not the custom one. This proves the custom revert path is never taken.
Remove the unreachable code. If preserving the custom error message is desired, replace the check with the internal _exists function (inherited from ERC721).
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.