mintFromFixedPriceSale for a custom contract can lead to users losing funds
A custom NFT contract implementing the required interface could return zero instead of reverting when all tokens are minted, causing the drop market to distribute funds without minting an NFT. A user calling the mint function after the sale ended would lose their payment and receive nothing.
NFTDropMarketFixedPriceSale.createFixedPriceSale allows creators to create a sale drop. A creator can create a drop sale for their custom NFT Contract that adheres to INFTDropCollectionMint.
INFTDropCollectionMint.mintCountTo must return the firstTokenId being minted, but it is not clear as to what should be returned upon all tokens being minted. A valid implementation could for instance return 0 if called after the last token has been minted.
But the drop market expects the call to mintCountTo to revert upon the last token being minted, meaning a user calling it afterwards would lose the ETH they sent.
Proof Of Concept
Alice creates a customERC721 contract adhering to INFTDropCollectionMint. She writes mintCountTo() so that it returns 0 if called when all the tokens have been minted.
The sale happens and collectors call mintFromFixedPriceSale until all the tokens have been minted.
Bob now calls mintFromFixedPriceSale. Because all the tokens have been minted, the call to mintCountTo does not revert but returns 0.
The function call then proceeds to distribute the funds.
Bob have lost mintCost ETH, while not receiving any NFT.
You can find this Foundry test reproducing the issue.
Note that this is not an issue of a malicious creator rugging collectors with a malicious implementation: they have implemented their contract to adhere to INFTDropCollectionMint, and the sale went as expected.
It is not unrealistic to imagine collectors monitoring CreateFixedPriceSale and calling mintFromFixedPriceSale based on it. In this case, all the mintFromFixedPriceSale processed after the last token being minted would lead to loss of funds.
Tools Used
Foundry
Recommend Mitigation Steps
You can add an additional check in NFTDropMarketFixedPriceSale.mintCountTo() using ERC721(nftContract).balanceOf().
I will argue this issue is actually different than #211, although they both come from the same function call:
In #211, the issue lies in the logic performed in INFTDropCollectionMint.mintCountTo(), more precisely the fact that a malicious implementation can perform incorrect state logic, which results in any collector calling NFTDropMarketFixedPriceSale.mintFromFixedPriceSale losing funds without receiving the expected amount of NFTs.
Here, the issue lies in the return value of INFTDropCollectionMint.mintCountTo() in an edge case - when all the tokens have been minted. There is no malicious implementation or wrong state logic: users calling NFTDropMarketFixedPriceSale.mintFromFixedPriceSale will receive the expected amount of NFTs. The problem is when the minting is done: the DropMarket expect subsequent calls to mintCountTo() to fail. While you can argue not reverting after the final token has been minted is breaking a semantic requirement, it still complies with the interface INFTDropCollectionMint. Not reverting on failure is a behavior that exists in other standards, such as some ERC20 tokens for instance, like ZRX.
To illustrate the difference between the two issues, take the NFT contract used in the PoC for this issue: users calling NFTDropMarketFixedPriceSale.mintFromFixedPriceSale will receive the expected amount of NFTs - i.e. it is not affected by the issue #211. The problem arises only upon the final token being minted.
In summary, #211 is about malicious implementations that users should be made aware of (docs or UI warnings) while this issue has to do with the fact INFTDropCollectionMint.mintCountTo() should define a stricter behavior when the last token has been minted, perhaps by adding a comment such as:
/// if the minting fails it MUST result in the transaction being reverted.
The root cause for both issues is about the “potential errors in the implementation or misunderstanding of the interface requirements”. Simply put, the ambiguity regarding the specification of mintCountTo() allows for it to be exploited. As you pointed out, #211 is exploited by malicious implementations while this issue happens even if the implementation is seemingly compliant to the interface because of the ambiguity.
It’s a tough decision because while the methods are different, the root cause and consequence (users losing funds) are the same.
I’ll side with you on this one, because the attack vectors are quite distinct. It’s similar to how I separated the strategist rug vectors for the Rubicon contest.
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.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the interface specification for mintCountTo did not require a revert when all tokens are minted, so a compliant implementation could return zero and the market would still distribute funds.
What the attacker needed
Custom NFT contract implementing the interface; all tokens already minted; user calls mint after sale ends
The fix
The market should check the buyer's NFT balance before and after minting and require the expected increase, or the interface should explicitly require a revert when minting fails.
How it was found
Alice creates a custom ERC721 contract that implements the mint interface and returns zero when all tokens are minted.
Collectors call the fixed-price mint function until all tokens are sold.
Bob calls the same mint function after the sale is complete.
The mint function returns zero instead of reverting, and the market distributes the funds.
Bob loses his payment and receives no NFT.
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.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A sale contract lets people buy NFTs from a custom collection. The collection's mint function is supposed to fail if no tokens are left, but the rules did not say that clearly. If it just returns zero instead, the sale contract still takes the buyer's money and sends it on, but the buyer gets no NFT.
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.