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

Mapping s_tokenToAddress could be indesiredly overwritten

Summary

Function 'deployToken' in contract 'TokenFactory' sets the address for token symbol, it does not check whether already exists a token with a certain symbol when deployed a new token.

Vulnerability Details

Medium vulnerability, the overwritten token will remain hidden as the function getTokenAddressFromSymbol will now return the new token.

Impact

It could exist a overwritten token whose address would be never obtained as the mentioned function does return the new token's address.

Recommendations

The code should check if the mapping s_tokenToAddress[symbol] is already set, the solution would be:

function deployToken(string memory symbol, bytes memory contractBytecode) public onlyOwner returns (address addr) {
require(s_tokenToAddress[symbol] == address(0), "It already exists a token with this symbol");
assembly {
addr := create(0, add(contractBytecode, 0x20), mload(contractBytecode))
}
s_tokenToAddress[symbol] = addr;
emit TokenDeployed(symbol, addr);
}

Updates

Lead Judging Commences

0xnevi Lead Judge about 2 years 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.