Beginner FriendlyFoundryBridge
100 EXP
View results
Submission Details
Severity: medium
Invalid

TokenFactory.sol - create - `create` returned address should be checked leading to faulty deployment unchecked

Summary

*   Author:
*   We are missing some zero address checks/input validation intentionally to save gas.

Saving cost shouldn't involve potential errors.

Vulnerability Details

This test show how to reproduce a failing contract creation

function testAddTokenFix3() public {
vm.prank(owner);
vm.expectRevert(bytes4(keccak256("TokenFactory__AddressShouldBeReturned()")));
tokenFactory.deployToken("TEST", "-lol");

Impact

if the contractBytecode is incorrect the function will succeed, the user could think that the contract is deployed (his script can keep running) and will potentially cost him much more gas than just reverting right away

Tools Used

forge test

Recommendations

Throw an error if the create method fail and address is 0

+ error TokenFactory__AddressShouldBeReturned();
function deployToken(string memory symbol, bytes memory contractBytecode) public onlyOwner returns (address addr) {
assembly {
addr := create(0, add(contractBytecode, 0x20), mload(contractBytecode))
}
+ if(addr == address(0)) revert TokenFactory__AddressShouldBeReturned();
s_tokenToAddress[symbol] = addr;
emit TokenDeployed(symbol, addr);
}
Updates

Lead Judging Commences

0xnevi Lead Judge
almost 2 years ago
0xnevi Lead Judge almost 2 years ago
Submission Judgement Published
Invalidated
Reason: Known issue

Support

FAQs

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