Skip to content
Business logic Audit finding Intermediate

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.

cccz Follow

Originally disclosed on Code4rena

Submitted by cccz

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.

  1. 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);
        }
    }
  1. Alice sends the underlying NFT to Bob, who does what Alice did before.
  2. 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.

Proof of Concept

https://github.com/code-423n4/2023-03-canto-identity/blob/077372297fc419ea7688ab62cc3fd4e8f4e24e66/canto-pfp-protocol/src/ProfilePicture.sol#L94-L105 https://github.com/code-423n4/2023-03-canto-identity/blob/077372297fc419ea7688ab62cc3fd4e8f4e24e66/canto-identity-protocol/src/AddressRegistry.sol#L86-L92

Recommended Mitigation Steps

Change to

    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)) {
+       if (cidNFTID == 0 || ERC721(nftContract).ownerOf(nftID) == 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
        }
    }

OpenCoreCH (Canto Identity) confirmed and commented:

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.

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

  1. 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.
  2. Alice sends the underlying NFT to Bob, who repeats Alice's actions.
  3. Bob sells the underlying NFT to Charlie, who burns it.
  4. 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.

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.

More by cccz

View all

104 more disclosed reports, best first.

More from Canto Identity Subprotocols contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.