Skip to content
Business logic Audit finding Intermediate

Users will be able to purchase fewer NFTs than the project had anticipated

The fuse function in the Namespace contract incorrectly passes a font class of 0 to the character-to-Unicode conversion, causing all font classes to produce the same name. As a result, users cannot mint names with different font classes because the name is already registered.

volodya Follow with m9800, Emmanuel and 6 others

Originally disclosed on Code4rena

Submitted by volodya, also found by m9800, Emmanuel, IgorZuk, dec3ntraliz3d, igingu, adriro, Rappie, and descharre

Users will be able to purchase fewer NFTs than the project had anticipated. The project had expected that users would be able to purchase a range of variations using both text and emoji characters. However, in reality, users will only be able to purchase a range of variations using emoji characters.

For example, the list of characters available for users to choose from is as follows

For instance, if a user chooses to mint an NFT namespace using font class 2 and the single letter 𝒶, then theoretically all other users should be able to mint font class 0 using the first emoji in the list, font class 1 using the single letter “a,” font class 3 using the single letter 𝓪, and so on, the first letter on every class will be. However, in reality, they will not be able to do so.

I consider this to be a critical issue because the project may not be able to sell as many NFTs as expected, potentially resulting in a loss of funds.

Here is an how nft name and their svg will look like from what I described above. As you can see emoji replaced letters in the name.

This is a function that creates namespace out of tray.

canto-namespace-protocol/src/Namespace.sol#L110
    function fuse(CharacterData[] calldata _characterList) external {
        uint256 numCharacters = _characterList.length;
        if (numCharacters > 13 || numCharacters == 0) revert InvalidNumberOfCharacters(numCharacters);
        uint256 fusingCosts = 2**(13 - numCharacters) * 1e18;
        SafeTransferLib.safeTransferFrom(note, msg.sender, revenueAddress, fusingCosts);
        uint256 namespaceIDToMint = ++nextNamespaceIDToMint;
        Tray.TileData[] storage nftToMintCharacters = nftCharacters[namespaceIDToMint];
        bytes memory bName = new bytes(numCharacters * 33); // Used to convert into a string. Can be 33 times longer than the string at most (longest zalgo characters is 33 bytes)
        uint256 numBytes;
        // Extract unique trays for burning them later on
        uint256 numUniqueTrays;
        uint256[] memory uniqueTrays = new uint256[](_characterList.length);
        for (uint256 i; i < numCharacters; ++i) {
            bool isLastTrayEntry = true;
            uint256 trayID = _characterList[i].trayID;
            uint8 tileOffset = _characterList[i].tileOffset;
            // Check for duplicate characters in the provided list. 1/2 * n^2 loop iterations, but n is bounded to 13 and we do not perform any storage operations
            for (uint256 j = i + 1; j < numCharacters; ++j) {
                if (_characterList[j].trayID == trayID) {
                    isLastTrayEntry = false;
                    if (_characterList[j].tileOffset == tileOffset) revert FusingDuplicateCharactersNotAllowed();
                }
            }
            Tray.TileData memory tileData = tray.getTile(trayID, tileOffset); // Will revert if tileOffset is too high
            uint8 characterModifier = tileData.characterModifier;

            if (tileData.fontClass != 0 && _characterList[i].skinToneModifier != 0) {
                revert CannotFuseCharacterWithSkinTone();
            }

            if (tileData.fontClass == 0) {
                // Emoji
                characterModifier = _characterList[i].skinToneModifier;
            }
            bytes memory charAsBytes = Utils.characterToUnicodeBytes(0, tileData.characterIndex, characterModifier);
...

canto-namespace-protocol/src/Namespace.sol#L110

There is a bug in this line of code where a character is retrieved from tile data. Instead of passing tileData.fontClass, we are passing 0.

            bytes memory charAsBytes = Utils.characterToUnicodeBytes(0, tileData.characterIndex, characterModifier);

Due to this bug, the names for all four different font classes will be the same. As a result, they will point to an existing namespace, and later, there will be a check for the existence of that name (token) using NameAlreadyRegistered.

        string memory nameToRegister = string(bName);
        uint256 currentRegisteredID = nameToToken[nameToRegister];
        if (currentRegisteredID != 0) revert NameAlreadyRegistered(currentRegisteredID);

Proof of Concept

Here is the test that you can run

    function testFailMintSameCharacterIndex() public {
        address user = user1;
        note.mint(user, 10000e18);
        endPrelaunchAndBuyOne(user);

        uint256[] memory trayIds = buyTray(user, 3);
        vm.startPrank(user);
        note.approve(address(ns), type(uint256).max);
        Namespace.CharacterData[] memory list = new Namespace.CharacterData[](
            1
        );
//      fuse tile with fontClass=8,characterIndex=1
        list[0] = Namespace.CharacterData(trayIds[1], 4, 0);
        Tray.TileData memory tileData = tray.getTile(trayIds[1], 4);
        console.log(tileData.characterIndex);//1
        console.log(tileData.fontClass);//8
        ns.fuse(list);

//      fuse tile with fontClass=4,characterIndex=1
        list[0] = Namespace.CharacterData(trayIds[2], 3, 0);
        tileData = tray.getTile(trayIds[2], 3);
        console.log(tileData.characterIndex);//1
        console.log(tileData.fontClass);//4
        vm.expectRevert(
            abi.encodeWithSelector(Namespace.NameAlreadyRegistered.selector, 1)
        );
        ns.fuse(list);
    }

Tools Used

Manual review, forge tests

Recommended Mitigation Steps

Pass font class instead of 0

-            bytes memory charAsBytes = Utils.characterToUnicodeBytes(0, tileData.characterIndex, characterModifier);
+            bytes memory charAsBytes = Utils.characterToUnicodeBytes(tileData.fontClass, tileData.characterIndex, characterModifier);

OpenCoreCH (Canto Identity) confirmed and commented:

Agree, leftover from earlier, will be changed.


The original report as published on Code4rena, by volodya. 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 code passes a hardcoded 0 instead of the actual font class when converting a character to its Unicode representation.

Impact

Users will only be able to purchase a limited range of variations using emoji characters, potentially reducing NFT sales and causing a loss of funds.

What the attacker needed

A user must have a tray with characters; the user must attempt to fuse characters with different…

The fix

The code was fixed by passing the actual font class instead of 0.

How it was found

  1. Buy a tray and fuse a character with a non-zero font class.
  2. Attempt to fuse another character with a different font class but the same character index.
  3. The transaction reverts with NameAlreadyRegistered because the generated name is identical.

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 bug where a function that creates a username from characters always uses the same font style, ignoring the actual font style chosen. So if someone tries to create a name with a different font, the system thinks it's the same name and rejects it, meaning fewer unique names can be sold.

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 volodya

View all

11 more disclosed reports, best first.

More from Canto Identity Subprotocols contest

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.