Skip to content
Smart contracts Audit finding Intermediate

The tokenURI method does not check if the NFT has been minted and returns data for the contract that may be a fake NFT

Haipls Follow with Rolezn and 0xSmartContract

Originally disclosed on Code4rena

Submitted by Haipls, also found by Rolezn and 0xSmartContract

https://github.com/code-423n4/2023-04-caviar/blob/cd8a92667bcb6657f70657183769c244d04c015c/src/Factory.sol#L161

https://github.com/code-423n4/2023-04-caviar/blob/cd8a92667bcb6657f70657183769c244d04c015c/src/PrivatePoolMetadata.sol#L17

Impact

  • By invoking the Factory.tokenURI method for a maliciously provided NFT id, the returned data may deceive potential users, as the method will return data for a non-existent NFT id that appears to be a genuine PrivatePool. This can lead to a poor user experience or financial loss for users.
  • Violation of the ERC721-Metadata part standard

Proof of Concept

Example

  1. User creates a fake contract A simple example so that the tokenURI method does not revert:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract NFT {
    function balanceOf(address) external pure returns (uint256) {
        1;
    }
}

contract NonNFT {
    address public immutable nft;

    address public constant baseToken = address(0);
    uint256 public constant virtualBaseTokenReserves = 1 ether;
    uint256 public constant virtualNftReserves = 1 ether;
    uint256 public constant feeRate = 500;

    constructor() {
        nft = address(new NFT());
    }
}
  1. User deploy the contract
  2. Now, by using tokenURI() for the deployed user’s address, one can fetch information about a non-existent NFT.

Tools Used

  • Manual review
  • Foundry

Recommended Mitigation Steps

  • Throw an error if the NFT id is invalid.

outdoteth (Caviar) confirmed and commented:

Not sure if this should be medium or not.

Alex the Entreprenerd (judge) commented:

[https://eips.ethereum.org/EIPS/eip-721#:~:text=function%20tokenURI(uint256%20_tokenId)%20external%20view%20returns%20(string)%3B](https://eips.ethereum.org/EIPS/eip-721#:~:text=function%20tokenURI(uint256%20_tokenId%29%20external%20view%20returns%20(string%29%3B)

Alex the Entreprenerd (judge) commented:

Because the functionality breaks the EIP721 spec, I agree with Medium Severity, no funds are at risk.

outdoteth (Caviar) mitigated:

Fixed in: https://github.com/outdoteth/caviar-private-pools/pull/19.

Status: Mitigation confirmed. Full details in reports from rbserver, KrisApostolov, and rvierdiiev.


The original report as published on Code4rena, by Haipls. 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.

What is known

A medium-severity smart contracts bug in Caviar Private Pools. Code4rena made it public on 18 May 2023. Found in the 2023-04-caviar audit contest (finding M-17), also found by 2 other wardens.

About Smart contracts

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Haipls

View all

7 more disclosed reports, best first.

More from Caviar Private Pools

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.