Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency in Custom Name and Symbol Registration Functions Leads to Unexpected Reverts #109

Open
hats-bug-reporter bot opened this issue Sep 16, 2024 · 8 comments
Labels
bug Something isn't working invalid This doesn't seem right

Comments

@hats-bug-reporter
Copy link

Github username: --
Twitter username: --
Submission hash (on-chain): 0xfbb00fba43c02e52b4e45bfd463e4bbcb2aeb9e5e90c5884d320613ea3903ab3
Severity: medium

Description:
Description
In both the registerCustomName and registerCustomSymbol functions of the NameRegistry contract, there are critical inconsistencies between the comments and the implementations.

The comments suggest that when empty strings are provided, they should default to specific values.

However, the functions attempt to validate these empty strings, which fail the isValidName and isValidSymbol checks respectively, causing the functions to revert.

For registerCustomName, the comment states:

// if name is left empty, it will default to default name "Circles-<base58(short)Name>"

For registerCustomSymbol, the comment states:

// if symbol is left empty, it will default to default symbol "CRC"

However, in both cases, empty strings lead to function reverts rather than setting default values.

@hats-bug-reporter hats-bug-reporter bot added the bug Something isn't working label Sep 16, 2024
@benjaminbollen
Copy link
Collaborator

Not even false. If empty, returns; if not empty but invalid, reverts.

@benjaminbollen
Copy link
Collaborator

but a wrong line comment wouldnt even qualify for a low issue, let alone medium

@benjaminbollen benjaminbollen added the invalid This doesn't seem right label Sep 16, 2024
@0xvivekd
Copy link

0xvivekd commented Sep 16, 2024

    function registerCustomName(address _avatar, string calldata _name) external onlyHub(1) {
        if (bytes(_name).length == 0) {
            // if name is left empty, it will default to default name "Circles-<base58(short)Name>"
            return;
        }
        if (!isValidName(_name)) {
            revert CirclesNamesInvalidName(_avatar, _name, 0);
        }
        customNames[_avatar] = _name;
    }
```javascript
function isValidName(string calldata _name) public pure returns (bool) {
    bytes memory nameBytes = bytes(_name);
    if (nameBytes.length > 32 || nameBytes.length == 0) return false; // Check length

    for (uint256 i = 0; i < nameBytes.length; i++) {
        bytes1 char = nameBytes[i];
        if (
            !(char >= 0x30 && char <= 0x39) // 0-9
                && !(char >= 0x41 && char <= 0x5A) // A-Z
                && !(char >= 0x61 && char <= 0x7A) // a-z
                && !(char == 0x20) // Space
                && !(char == 0x2D || char == 0x5F) // Hyphen (-), Underscore (_)
                && !(char == 0x2E) // Period (.)
                && !(char == 0x28 || char == 0x29) // Parentheses ( () )
                && !(char == 0x27) // Apostrophe (')
                && !(char == 0x26) // Ampersand (&)
                && !(char == 0x2B || char == 0x23) // Plus (+), Hash (#)
        ) {
            return false;
        }
    }
    return true;
}
   
    
    The isVaildName reverts if length is 0 due to the below line:
    
    ```javascript
    if (nameBytes.length > 32 || nameBytes.length == 0) return false; // Check length

@benjaminbollen
Copy link
Collaborator

right, you confirm my point. Thanks for your contribution

@0xvivekd
Copy link

Could you explain what is the intention?

Empty strings in name and symbol should be allowed or not?

@0xvivekd
Copy link

0xvivekd commented Sep 16, 2024

It returns false and reverts with CirclesInvalidString

if (!nameRegistry.isValidName(_name)) {
// Invalid group name.
// name must be ASCII alphanumeric and some special characters
revert CirclesInvalidString(_name, 0);
}
if (!nameRegistry.isValidSymbol(_symbol)) {
// Invalid group symbol.
// symbol must be ASCII alphanumeric and some special characters
revert CirclesInvalidString(_symbol, 1);
}

@0xvivekd
Copy link

I have resubmitted the issue in Issue # 110

Kindly ignore this issue

@benjaminbollen
Copy link
Collaborator

this is different from #110. Here it seems you confuse the behaviour of isValidName with registerCustomName which are two different functions.

In #110, you say a group must be allowed to have an empty name, which they they are not allowed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants