Description
-
Smart contracts should validate input parameters to prevent unexpected behavior with extreme values.
-
The BidBeastsNFTMarketplace::listNFT() function accepts extremely large values for minPrice and buyNowPrice without reasonable upper bounds validation.
require(BBERC721.ownerOf(tokenId) == msg.sender, "Not the owner");
require(_minPrice >= S_MIN_NFT_PRICE, "Min price too low");
if (_buyNowPrice > 0) {
@> require(_minPrice <= _buyNowPrice, "Min price cannot exceed buy now price");
}
Risk
Likelihood:
Impact:
Proof of Concept
function test_LOW_ExtremeValueValidation() public {
vm.prank(OWNER);
uint256 tokenId = nft.mint(ALICE);
vm.startPrank(ALICE);
nft.approve(address(market), tokenId);
market.listNFT(tokenId, type(uint256).max - 1000, type(uint256).max);
vm.stopPrank();
BidBeastsNFTMarket.Listing memory listing = market.getListing(tokenId);
assertEq(
listing.minPrice,
type(uint256).max - 1000,
"Should accept extreme min price"
);
}
Recommended Mitigation
+ uint256 constant public MAX_NFT_PRICE = 1000000 ether; // Reasonable maximum
function listNFT(uint256 tokenId, uint256 _minPrice, uint256 _buyNowPrice) external {
require(BBERC721.ownerOf(tokenId) == msg.sender, "Not the owner");
require(_minPrice >= S_MIN_NFT_PRICE, "Min price too low");
+ require(_minPrice <= MAX_NFT_PRICE, "Min price too high");
if (_buyNowPrice > 0) {
require(_minPrice <= _buyNowPrice, "Min price cannot exceed buy now price");
+ require(_buyNowPrice <= MAX_NFT_PRICE, "Buy now price too high");
}