Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook deployment is vulnerable to reorg situations #36

Open
howlbot-integration bot opened this issue Sep 20, 2024 · 5 comments
Open

Hook deployment is vulnerable to reorg situations #36

howlbot-integration bot opened this issue Sep 20, 2024 · 5 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue grade-b primary issue Highest quality submission among a set of duplicates Q-19 QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_40_group AI based duplicate group recommendation sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons sufficient quality report This report is of sufficient quality

Comments

@howlbot-integration
Copy link

Lines of code

https://github.com/code-423n4/2024-08-wildcat/blob/fe746cc0fbedc4447a981a50e6ba4c95f98b9fe1/src/HooksFactory.sol#L317-L319

Vulnerability details

Impact

Hook deployment is not protected from reorg situations, even though protocol plans on deployment to chains that are very vulnerable to block reorgs. This will cause markets to be deployed with the wrong hooks, messing up users' potential hook configurations.

Proof of Concept

The protocol plans to deploy on Ethereum, Base, Arbitrum, Polygon. Re-orgs can happen in all EVM chains. Not super common on Ethereum, but still happens. The same also occurs on Poylgon, which has experienced large re-orgs in the past. and on Optimistic and Arbitrum rollups.

_deployHooksInstance uses the ordinary "create" to deploy the hooks,

      let initCodeSizeWithArgs := add(add(initCodeSize, 0x60), constructorArgsSize)
      // Deploy the contract with the initcode
      hooksInstance := create(0, initCodePointer, initCodeSizeWithArgs)

therefore during multiple hook/market deployments through the deployMarketAndHooks and deployMarket functions, a reorg situation will lead to a "swap" of address instances, in which the reorganization of chain blocks will lead to a different address instance being attached to another hook, other than the one it would have gotten in case of a normal deployment. In short, hook deployment A gets address instance B, rather than address instance A that it would have gotten in case of a normal deployment.
in case of multiple deployments with the deployMarketAndHooks function will cause the wrong hooksinstance to be attached to the wrong markets, which could tamper with various expected market configurations and lead to unexpected behaviour. Also, if the deployer uses the initially derived address and sends funds to the address, the switch in address instance will make the funds open to the other deployment, leading to loss of funds.

Tools Used

Manual code review

Recommended Mitigation Steps

Recommend using CREATE2 instead which uses salt that contains msg.sender to deploy hooks instead.

Assessed type

Other

@howlbot-integration howlbot-integration bot added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value 🤖_40_group AI based duplicate group recommendation bug Something isn't working primary issue Highest quality submission among a set of duplicates sufficient quality report This report is of sufficient quality labels Sep 20, 2024
howlbot-integration bot added a commit that referenced this issue Sep 20, 2024
@d1ll0n
Copy link

d1ll0n commented Oct 2, 2024

It's vanishingly unlikely this would happen in practice, but you're right that this could possibly be an issue.

@d1ll0n d1ll0n added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label Oct 2, 2024
@3docSec
Copy link

3docSec commented Oct 4, 2024

in case of multiple deployments with the deployMarketAndHooks function will cause the wrong hooksinstance to be attached to the wrong markets

I don't think this is correct. The function deployMarketAndHooks is atomic: it creates a hook instance, and a market instance with the created address.

If user A and B both call deployMarketAndHooks and a reorg changes the order A, B into B, A, you'll still have a consistent result, where the market configured by user A has the very same hooks user A they wanted, just a different address, but market and hooks will be linked consistently.

What is at risk is in my opinion only when the user then transfers funds to the hooks immediately afterwards. I do not understand under which circumstances one (the borrower even) may want to transfer funds to the hooks contract, I find the described "loss of funds" impact not realistic.

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Oct 4, 2024
@c4-judge
Copy link
Contributor

c4-judge commented Oct 4, 2024

3docSec changed the severity to QA (Quality Assurance)

@c4-judge
Copy link
Contributor

c4-judge commented Oct 4, 2024

3docSec marked the issue as grade-b

@laurenceday
Copy link

Fixed by wildcat-finance/v2-protocol@1a52863

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue grade-b primary issue Highest quality submission among a set of duplicates Q-19 QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_40_group AI based duplicate group recommendation sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

5 participants