_validateDeploymentConfig function in NFTCollection.sol doesn't check all conditions
The deployment configuration validation function does not check that tokensPerMint is less than or equal to maxSupply. If tokensPerMint exceeds maxSupply, any mint attempt with amount equal to tokensPerMint will revert, wasting gas and requiring contract redeployment.
Source: https://github.com/sherlock-audit/2022-10-nftport-judging/issues/51
Found by
ElKu
Summary
Due to not thoroughly checking all conditions of the deployment config, users might not be able to mint certain amount of tokens.
Vulnerability Detail
In NFTCollection.sol, there is a function called _validateDeploymentConfig, which checks whether the deploymentConfig input to initialize function is valid.
The function checks whether the maxSupply and tokensPerMint are greater than zero. But it never checks if the tokensPerMint is less than or equal to maxSupply.
Suppose maxSupply < tokensPerMint. Then if the user calls a function which in-turn calls the _mintTokens function with an amount equal to tokensPerMint, it will revert. Even though he is technically trying to mint as per the rules. This is because the availableSupply() won't be greater than amount.
Impact
- Dissatisfaction and Frustration of the user along with loss of his gas fees.
- The contract would need redeployment as deployment config cannot be changed once its set.
Code Snippet
function _mintTokens(address to, uint256 amount) internal {
require(amount <= _deploymentConfig.tokensPerMint, "Amount too large");
require(amount <= availableSupply(), "Not enough tokens left");
_safeMint(to, amount);
}
Tool used
Manual Review, VSCode
Recommendation
Add a require statement in the _validateDeploymentConfig function:
require(config.tokensPerMint <= config.maxSupply, "Tokens per mint must be lte Maximum supply");
Discussion
hyperspacebunny
Fixed in https://github.com/nftport/evm-minting-sherlock-fixes/pull/7
rayn731
Fixed, it checks tokens per mint must be less than max supply.
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 validation function _validateDeploymentConfig does not enforce that tokensPerMint <= maxSupply.
Impact
Users may be unable to mint the allowed number of tokens, losing gas fees, and the contract may need redeployment because the configuration is immutable.
What the attacker needed
Deployment config with tokensPerMint > maxSupply
The fix
The issue was fixed by adding a check that tokensPerMint must be less than or equal to maxSupply.
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.
This is a smart contract for NFTs. When setting up the contract, you specify how many tokens can be minted in total (maxSupply) and how many a user can mint at once (tokensPerMint). The setup check forgot to ensure that the per-mint amount is not larger than the total supply. If it is, users can never mint the allowed amount because the contract runs out of tokens first, and the transaction fails, costing gas.
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.