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
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
- The Factory.tokenURI and PrivatePoolMetadata.tokenURI methods lack any requirements stating that the provided NFT id must be created. We can also see that in the standard implementation by OpenZeppelin, this check is present:
- Throws if
_tokenIdis not a valid NFT
Example
- User creates a fake contract
A simple example so that the
tokenURImethod 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());
}
}
- User deploy the contract
- 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.
Fixed in: https://github.com/outdoteth/caviar-private-pools/pull/19.
Status: Mitigation confirmed. Full details in reports from rbserver, KrisApostolov, and rvierdiiev.
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.