Submitted by MiloTruck, also found by nonseodion, Robert, LokiThe5th, 0xCiphky, Madalad, and ZdravkoHr
In LibStoredInitCode.sol, the create2WithStoredInitCode() function, which is used to deploy contracts with the CREATE2 opcode, is as shown:
LibStoredInitCode.sol#L106-L117
The create2 opcode returns address(0) if contract deployment reverted. However, as seen from above,  create2WithStoredInitCode() does not check if the deployment address is address(0).
This is an issue as deployMarket() will not revert when deployment of the WildcatMarket contract fails:
WildcatMarketController.sol#L354-L357
Therefore, if the origination fee is enabled for the protocol, users that call deployMarket() will pay the origination fee even if the market was not deployed.
Additionally, the market address will be registered in the WildcatArchController contract and added to _addControlledMarkets. This will cause both sets to become inaccurate if deployment failed as market would be an address that has no code.
This also leads to more problems if a user attempts to call deployMarket() with the same asset, namePrefix and symbolPrefix. Since the market address has already been registered, registerMarket() will revert when called for a second time:
WildcatArchController.sol#L192-L195
As such, if a user calls deployMarket() and market deployment fails, they cannot call deployMarket() with the same set of parameters ever again.
Note that it is possible for market deployment to fail, as seen in the constructor of WildcatMarketBase:
WildcatMarketBase.sol#L79-L99
For example, the protocol could have configured protocolFeeBips or feeRecipient incorrectly. Alternatively, asset could be an invalid address, or an ERC20 token that does not have the name(), symbol() or decimal() function.
Since deployMarket() does not revert when creation of the WildcatMarket contract fails, users will pay the origination fee for failed deployments, causing a loss of funds.
Additionally, deployMarket() will not be callable for the same asset, namePrefix and symbolPrefix, thus a user can never deploy a market with these parameters.
The following test demonstrates how deployMarket() does not revert even if deployment of the WildcatMarket contract failed, and how it reverts when attempting to deploy the same market with valid parameters afterward:
In create2WithStoredInitCode(), consider checking if the deployment address is address(0), and reverting if so:
LibStoredInitCode.sol#L106-L117
Library
laurenceday (Wildcat) commented:
laurenceday (Wildcat) confirmed
