Beginner FriendlyFoundryBridge
100 EXP
View results
Submission Details
Severity: low
Valid

Risk of Non-Unique Asset Identification in `TokenFactory.sol`

Vulnerability Details

The identified vulnerability is in the TokenFactory contract, specifically in the handling of asset uniqueness. The contract currently uses the token symbol as the key determinant for identifying and registering tokens. However, token symbols are not guaranteed to be unique across different tokens or collections. Two distinct tokens can have identical symbols, leading to potential conflicts and misidentification in the system.

This issue is exacerbated in the context of TokenFactory.sol, where the mapping s_tokenToAddress could associate multiple different tokens with the same symbol, leading to unpredictable behavior and potential for errors.

contract TokenFactory is Ownable {
mapping(string => address) private s_tokenToAddress;
...
function deployToken(string memory symbol, bytes memory contractBytecode) public onlyOwner returns (address addr) {
...
s_tokenToAddress[symbol] = addr;
...
}
...
}

Impact

The impact of this vulnerability can be significant. If two different tokens with the same symbol are deployed through the TokenFactory, it could lead to confusion and errors in token management. Operations intending to interact with one token might inadvertently affect another, potentially causing misallocation of assets, incorrect token balances, and other operational discrepancies.

Recommendations

To mitigate this risk, it is recommended to use a more reliable and unique identifier for tokens. The most suitable candidate for this unique identifier is the token's contract address. Contract addresses are inherently unique on the Ethereum blockchain, ensuring that each token deployed through the TokenFactory is distinctly identifiable.

  1. Modify the Identifier: Change the mapping in TokenFactory from using token symbols to using token contract addresses as keys.

  2. Update Deployment Logic: Ensure that the token's address, rather than its symbol, is used for all identification and registration purposes within the contract.

contract TokenFactory is Ownable {
mapping(address => string) private s_addressToSymbol;
function deployToken(string memory symbol, bytes memory contractBytecode) public onlyOwner returns (address addr) {
...
// Deploy the token and get its address
addr = ...; // Token deployment logic
s_addressToSymbol[addr] = symbol;
...
}
function getTokenSymbol(address tokenAddress) public view returns (string memory symbol) {
return s_addressToSymbol[tokenAddress];
}
}

This approach ensures that each token registered in the TokenFactory is uniquely identifiable by its address, eliminating the risk of symbol-based conflicts and enhancing the robustness of the token management system.

Updates

Lead Judging Commences

0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

deployToken: non-unique symbol for tokens

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.