If the underlying NFT is burned, getPFP may return incorrect results
The getPFP function in ProfilePicture.sol may return incorrect information if the underlying NFT is burned, because it compares the address registry's address with the NFT owner, and both can be zero. An attacker could exploit this to make getPFP return a non-zero contract address and ID for a burned NFT, potentially causing bugs in integrating projects.
ProfilePicture.getPFP will return information about the underlying NFT and when addressRegistry.getAddress(cidNFTID) ! = ERC721(nftContract).ownerOf(nftID), it will return 0.
But if the underlying NFT is burned, getPFP may return incorrect information
function getPFP(uint256 _pfpID) public view returns (address nftContract, uint256 nftID) {
if (_ownerOf[_pfpID] == address(0)) revert TokenNotMinted(_pfpID);
ProfilePictureData storage pictureData = pfp[_pfpID];
nftContract = pictureData.nftContract;
nftID = pictureData.nftID;
uint256 cidNFTID = cidNFT.getPrimaryCIDNFT(subprotocolName, _pfpID);
IAddressRegistry addressRegistry = cidNFT.addressRegistry();
if (cidNFTID == 0 || addressRegistry.getAddress(cidNFTID) != ERC721(nftContract).ownerOf(nftID)) {
nftContract = address(0);
nftID = 0; // Strictly not needed because nftContract has to be always checked, but reset nevertheless to 0
}
}
Consider the following scenario.
Alice mints a ProfilePicture NFT (pfp NFT) with the underlying NFT, and later mints a CidNFT by transferring the pfp NFT to the CidNFT contract.
Noting that alice does not call AddressRegistry.register to register the CidNFT.
Since getAddress returns 0, ProfilePicture.getPFP will also return 0.
function getAddress(uint256 _cidNFTID) external view returns (address user) {
user = ERC721(cidNFT).ownerOf(_cidNFTID);
if (_cidNFTID != cidNFTs[user]) {
// User owns CID NFT, but has not registered it
user = address(0);
}
}
Alice sends the underlying NFT to Bob, who does what Alice did before.
Bob sold the underlying NFT to Charlie and Charlie burned it for some reason, now if Alice or Bob calls ProfilePicture.getPFP(), it will return the contract address and id of the underlying NFT since getAddress() == ownerOf() == address(0).
When integrating with other projects, there may be bugs because getPFP returns an incorrect result.
Very interesting edge case, enjoyed reading it! For an ERC721 compliant NFT this is not the case, because the standard explicitly says:
/// @dev NFTs assigned to zero address are considered invalid, and queries
/// about them do throw.
Therefore, the existing ownerOf will throw.
However, in my experience there are some NFTs that do not adhere strictly to ERC721 when it comes to this. Because of that, I’ll still implement a fix for this.
The original report as published on Code4rena, by cccz. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the check does not account for the case where the underlying NFT has been burned, causing ownerOf to return address(0), which matches the address registry's return value of address(0) when the CID NFT is not registered.
Impact
When integrating with other projects, there may be bugs because getPFP returns an incorrect result.
What the attacker needed
Underlying NFT is burned; CID NFT not registered in AddressRegistry
The fix
The fix adds a check that the underlying NFT's owner is not the zero address, so getPFP returns zero if the NFT is burned.
How it was found
Alice mints a ProfilePicture NFT with an underlying NFT and mints a CidNFT by transferring the pfp NFT to the CidNFT contract, but does not register the CidNFT in AddressRegistry.
Alice sends the underlying NFT to Bob, who repeats Alice's actions.
Bob sells the underlying NFT to Charlie, who burns it.
Alice or Bob calls getPFP, which returns the contract address and ID of the underlying NFT because getAddress() and ownerOf() both return address(0).
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
This report is about a function that checks if a user owns a specific NFT before showing their profile picture. If that NFT is destroyed (burned), the check can mistakenly think it's still valid because both the owner and the registered address become zero. This could confuse other programs that rely on this function.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.