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

Overwriting the Mapping with the Symbol

Audit Findings

1. Overwriting Existing Mappings

The code assigns the deployed contract address addr to the s_tokenToAddress mapping using the symbol as the key. However, it is crucial to consider potential conflicts or unintended consequences that may arise from overwriting existing mappings in the mapping structure.

Recommendations

Based on the findings above, we recommend the following changes to the code:

  1. Implement additional logic to prevent overwriting existing mappings in the s_tokenToAddress mapping. This can be achieved by checking if the mapping for a given symbol already exists before assigning the new contract address. If a mapping already exists, appropriate actions should be taken, such as rejecting the deployment or updating the existing mapping only under certain conditions.

    Here's a snippet illustrating the recommended change:

function deployToken(string memory symbol, bytes memory contractBytecode) public onlyOwner returns (address addr) {
assembly {
addr := create(0, add(contractBytecode, 0x20), mload(contractBytecode))
}
// Check if the mapping for the given symbol already exists
require(s_tokenToAddress[symbol] == address(0), "Symbol mapping already exists");
s_tokenToAddress[symbol] = addr;
emit TokenDeployed(symbol, addr);
}

In the above code snippet, we added a require statement to validate that the mapping for the given symbol does not exist before assigning the new contract address. If the mapping already exists, the deployment will be rejected.

  1. Consider using a data structure that allows multiple contract addresses to be associated with a single symbol, if that is a requirement. This could involve using an array or a mapping that stores a list of contract addresses for each symbol, allowing for multiple contracts to be associated with the same symbol.

Conclusion

In conclusion, the concern raised regarding overwriting the mapping with the symbol is valid. We recommend implementing additional logic to prevent overwriting existing mappings and considering alternative data structures if multiple contract addresses need to be associated with a single symbol.

Updates

Lead Judging Commences

0xnevi Lead Judge almost 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.