Closed howlbot-integration[bot] closed 2 months ago
3docSec changed the severity to QA (Quality Assurance)
3docSec marked the issue as grade-b
Hi @3docSec,
Thank You for judging this contest.
This issue has been marked as a duplicate of #36. But the issue #36 discusses of the reorg vulnerability
present in the HooksFactory.deployMarketAndHooks
function. But as you have mentioned in #36 the reorg vulnerability is not present (or at least the impact is very less) in the HooksFactory.deployMarketAndHooks
since this function is atomic.
But there is another way where markets can be deployed. That is by calling the HooksFactory.deployHooksInstance
and HooksFactory.deployMarket
functions separately. Here the HooksFactory.deployMarket
function uses an already deployed hooksInstance
and the transaction is not atomic. Hence if a reorg happens and the given hooksInstance
deployment is also included in a reorg block then the market can be deployed
with a different hooksInstance
(Since a different hooksInstance
is deployed at the same address used for market deployment due to use of create
) than expected as explained in this issue.
As a result the market will be deployed with an unexpected hook template due to reorg thus breaking the expected behavior of the market as explained in the original issue.
Let's consider the following scenario:
A user deploys HooksInstance A
and HooksInstance B
by calling the HooksFactory.deployHooksInstance
. He expects to deploy three markets, the Market A
with HooksInstance A
and Market B
with HooksInstance B
and Market C
with HooksInstance B
and triggers three different HooksFactory.deployMarket
transactions by passing in the respective HooksInstances
. Now a block reorg happens and the Market A
gets deployed with HooksInstance B
and Market B and Market C
gets deployed with HooksInstance A
contrary to the expectation of the user. As a result this breaks the intended behavior of the markets by the user (deployer).
The sponsor has acknowledged this issue and has already fixed it here.
As per the C4 Severity Categorization below:
2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.
I think this falls under Medium severity
since the the function of the protocol or its availability could be impacted
in this scenario.
Hence can you please dedupe this issue from #36 and reconsider the Medium severity for this issue.
Thank You
Interesting point @udsene.
The 2-step deployment flow you are highlighting is indeed vulnerable.
However, with the reorg scenario we still are in very unlikely territory; the fact the user calls deployHooksInstance
and immediately afterwards deployMarket
instead of deployMarketAndHooks
that is there, available to achieve both, makes it even more unlikely.
I admit there is more subjectiveness in the mix than we'd all like to, but I don't see the scenario likelihood close enough to what an even low-likelihood M would be
Lines of code
https://github.com/code-423n4/2024-08-wildcat/blob/main/src/HooksFactory.sol#L319 https://github.com/code-423n4/2024-08-wildcat/blob/main/src/HooksFactory.sol#L327 https://github.com/code-423n4/2024-08-wildcat/blob/main/src/HooksFactory.sol#L405 https://github.com/code-423n4/2024-08-wildcat/blob/main/src/HooksFactory.sol#L428-L423 https://github.com/code-423n4/2024-08-wildcat/blob/main/src/HooksFactory.sol#L440 https://github.com/code-423n4/2024-08-wildcat/blob/main/src/access/FixedTermLoanHooks.sol#L133
Vulnerability details
Proof of Concept
The
Wildcat protocol
is expected to be deployed on Layer 2 block chains such asArbitrum and Polygon
. In these layer2 blockchains theblock reorgs
are common and can happen frequently (Even in the layer 1 Ethereum also the block reorgs can happen). The following issue can occur if a block reorg happens in any of the above layer 2 blockchains on which thewildcat protocol
is deployed on.Let's consider the following scenario:
HooksFactory.deployHooksInstance
function is called byUser A
to deploy a new hook instance.hook instance
is used in theHooksFactory.deployMarket
call to deploy a new market byUser A
.HooksFactory.deployMarket
function calls the_deployMarket
function where themsg.sender
will be used as theborrower
of theWildcatMarket
. And theborrower
initialized in thehook instance
should also belong to the sameborrower
.hooks template
corresponding to thehook instance
is also set when thehook instance
was deployed. And thishook template
is used in the_marketsByHooksTemplate
mapping to push the newly deployed market into the mapping.HooksFactory._deployHooksInstance
function uses thecreate
opcode to deploy thehook instance
which is susceptible to block reorgs (since it uses the initcode and the nonce of the deployer to determine the deployment address).different deploy hooks instance
could get deployed byUser B
at the same address as the previoushook instance
deployed byUser A
. This will have a differenthook template
as well.HooksFactory.deployMarket
function will execute and this will use thehook instance
deployed byUser B
and the market deployer isUser A
. Hence theborrower of the hooks instance is User B
where as theborrower of the market
isUser A
. This will break theonlyBorrower
functionality of thehooks instance
sinceUser A
is not theborrower of the hooks instance
.hook template
used to deploy the market could also change. This will prompt theUser A
to deploy a market with an unexpectedhook template
which will break the functionality of his deployed market.break the intended functionality of the
wildcat protocol`.https://github.com/code-423n4/2024-08-wildcat/blob/main/src/HooksFactory.sol#L319 https://github.com/code-423n4/2024-08-wildcat/blob/main/src/HooksFactory.sol#L327 https://github.com/code-423n4/2024-08-wildcat/blob/main/src/HooksFactory.sol#L405 https://github.com/code-423n4/2024-08-wildcat/blob/main/src/HooksFactory.sol#L428-L423 https://github.com/code-423n4/2024-08-wildcat/blob/main/src/HooksFactory.sol#L440 https://github.com/code-423n4/2024-08-wildcat/blob/main/src/access/FixedTermLoanHooks.sol#L133
Recommended Mitigation Steps
Hence it is recommended to use the
CREATE2
opcode to deploy thehook instance
instead of theCREATE
opcode. TheCREATE2
opcode can use asalt
value which consists of themsg.sender
such that the differenthook instance addresses
will be computed for different deployers of the hook instances.Assessed type
Other