Skip to content
Business logic Audit finding Intermediate

registerTemplate() can't handle properly when ITemplate version is 0

The registerTemplate function fails to set the latest implementation when a template's version is 0, leaving latestImplementation as the zero address and causing duplicate entries in _templateNames. This can lead external contracts to believe no setup exists, resulting in repeated failed setup attempts.

bin2chen Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-10-nftport-judging/issues/80

Found by

bin2chen

Summary

Factory.sol when register one template , and template ' s version is 0, the latestImplementation[templateName] will be address(0) and add other version, "_templateNames" will duplicate

Vulnerability Detail

When version is equal 0 latestImplementation[templateName] don't set

Solidity
   function _setTemplate(
        string memory templateName,
        uint256 templateVersion,
        address implementationAddress
    ) internal {
...

        if (latestImplementation[templateName] == address(0)) { /****add other version, _templateNames will duplicate ****/
            _templateNames.push(templateName);
        }

        if (templateVersion > latestVersion[templateName]) {
            latestVersion[templateName] = templateVersion;
            latestImplementation[templateName] = implementationAddress; /****templateVersion==0 ,  don't set ****/
        }

    }

Impact

latestImplementation[templateName] and _templateNames will error. external contracts may think there is no setup, resulting in duplicate setups that keep failing

Code Snippet

https://github.com/sherlock-audit/2022-10-nftport/blob/main/evm-minting-master/contracts/Factory.sol#L415

Tool used

Manual Review

Recommendation

Solidity
    function _setTemplate(
        string memory templateName,
        uint256 templateVersion,
        address implementationAddress
    ) internal {

 -      if (templateVersion > latestVersion[templateName]) {
 +      if (templateVersion > = latestVersion[templateName]) {
            latestVersion[templateName] = templateVersion;
            latestImplementation[templateName] = implementationAddress; 
        }


Discussion

hyperspacebunny

Fixed in https://github.com/nftport/evm-minting-sherlock-fixes/pull/4

rayn731

Fixed, it prevents using version 0, only > 0 is allowed.

The original report as published on Sherlock, by bin2chen. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 condition for updating the latest implementation uses a strict greater-than comparison, so a version of 0 is never stored, leaving the implementation address as zero and causing the name to be pushed again on subsequent registrations.

Impact

External contracts may incorrectly think no template is set up, leading to duplicate setup attempts that keep failing.

What the attacker needed

Version 0 is used for a template

The fix

The issue was fixed by preventing the use of version 0, only allowing versions greater than 0.

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.

A smart contract function that registers templates has a bug: if you register a template with version number 0, it doesn't properly record the template's address. Later, when you add another version, the contract thinks the template was never registered and adds its name again, causing duplicates. This can confuse other contracts that rely on this list.

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 bin2chen

View all

139 more disclosed reports, best first.

More from NFTPort

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.