Skip to content
Business logic Audit finding Intermediate

Malicious Creator can steal from collectors upon minting with a custom NFT contract

A malicious NFT creator can deploy a custom contract whose mintCountTo function mints fewer NFTs than requested, so collectors who pay for multiple NFTs receive only one. The attacker profits from the price difference.

joestakey Follow

Originally disclosed on Code4rena

Submitted by joestakey, also found by byndooa

In the case of a fixed price sale where nftContract is a custom NFT contract that adheres to INFTDropCollectionMint, a malicious creator can set a malicious implementation of INFTDropCollectionMint.mintCountTo() that would result in collectors calling this function losing funds without receiving the expected amount of NFTs.

Proof Of Concept

Here is a Foundry test that shows a fixed price sale with a malicious NFT contract, where a collector pays for 10 NFTs while only receiving one. It can be described as follow:

  • A creator creates a malicious nftContract with mintCountTo minting only one NFT per call, regardless of the value of count
  • The creator calls NFTDropMarketFixedPriceSale.createFixedPriceSale() to create a sale for nftContract, with limit set to 15.
  • Bob is monitoring the CreateFixedPriceSale event. Upon noticing CreateFixedPriceSale(customERC721, Alice, price, limit), he calls NFTDropMarketFixedPriceSale.mintFromFixedPriceSale(customERC721, count == 10,). He pays the price of count = 10 NFTs, but because of the logic in mintCountTo, only receives one NFT.

Note that mintCountTo can be implemented in many malicious ways, this is only one example. Another implementation could simply return firstTokenId without performing any minting.

Tools Used

Foundry

Recommended Mitigation Steps

The problem here lies in the implementation of INFTDropCollectionMint(nftContract).mintCountTo(). You could add an additional check in NFTDropMarketFixedPriceSale.mintCountTo() using ERC721(nftContract).balanceOf().

+ uint256 balanceBefore = IERC721(nftContract).balanceOf(msg.sender);
207:     firstTokenId = INFTDropCollectionMint(nftContract).mintCountTo(count, msg.sender);
+ uint256 balanceAfter = IERC721(nftContract).balanceOf(msg.sender);
+ require(balanceAfter == balanceBefore + count, "minting failed")

itsmeSTYJ (warden) commented:

This assumes a custom NFT contract with a bad implementation of mintCountTo which may be a stretch but I agree that your mitigation steps should be added as a sanity check.

HardlyDifficult (Foundation) confirmed and commented:

We will be making the recommended change.

There’s not really anything we can do to completely stop malicious contracts - this is an inherit risk with NFT marketplaces. Even the recommended solution here is something a malicious contract could fake in order to bypass that requirement.

What sold us on making a change here was not malicious creators / contracts but instead potential errors in the implementation or misunderstanding of the interface requirements our marketplace expects. To prevent these errors, we are introducing the recommended change (and it only added 1,300 gas to the mint costs!)


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

The marketplace trusts the custom NFT contract's mintCountTo function to mint the exact number of tokens requested, without verifying the actual balance change.

Impact

Collectors could lose funds by paying for multiple NFTs but receiving fewer, though the report notes that a malicious contract could potentially bypass the recommended balance check.

What the attacker needed

Creator deploys malicious NFT contract; collector buys from fixed price sale

The fix

The marketplace was updated to check the collector's NFT balance before and after minting to ensure the expected number of tokens were received.

How it was found

  1. A creator deploys a malicious NFT contract where mintCountTo mints only one NFT per call regardless of the count parameter.
  2. The creator calls createFixedPriceSale to list the NFT contract with a limit of 15.
  3. A collector monitors the CreateFixedPriceSale event and calls mintFromFixedPriceSale with count set to 10.
  4. The collector pays for 10 NFTs but receives only one due to the malicious mintCountTo logic.

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.

When you buy an NFT on a marketplace, the marketplace calls the NFT contract to mint the tokens. If the creator controls that contract, they can make it mint fewer tokens than you paid for. You lose money and get less than you expected.

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 joestakey

View all

10 more disclosed reports, best first.

More from Foundation Exhibition, Scheduling & Early Access Solo Audit by Lambda

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.