Skip to content
Smart contracts Audit finding Advanced

QuestFactory is suspicious of the reorg attack

The createQuest function deploys quest contracts using create, so the address depends only on the factory's nonce. An attacker could exploit a blockchain reorganisation to deploy a quest at an address where a victim had already sent funds, potentially stealing those funds.

V_B Follow

Originally disclosed on Code4rena

Submitted by V_B

https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/QuestFactory.sol#L75 https://github.com/rabbitholegg/quest-protocol/blob/8c4c1f71221570b14a0479c216583342bd652d8d/contracts/QuestFactory.sol#L108

The createQuest function deploys a quest contract using the create, where the address derivation depends only on the QuestFactory nonce.

At the same time, some of the chains (Polygon, Optimism, Arbitrum) to which the QuestFactory will be deployed are suspicious of the reorg attack.

Here you may be convinced that the Polygon has in practice subject to reorgs. Even more, the reorg on the picture is 1.5 minutes long. So, it is quite enough to create the quest and transfer funds to that address, especially when someone uses a script, and not doing it by hand.

Optimistic rollups (Optimism/Arbitrum) are also suspect to reorgs since if someone finds a fraud the blocks will be reverted, even though the user receives a confirmation and already created a quest.

Attack Scenario

Imagine that Alice deploys a quest, and then sends funds to it. Bob sees that the network block reorg happens and calls createQuest. Thus, it creates quest with an address to which Alice sends funds. Then Alices’ transactions are executed and Alice transfers funds to Bob’s controlled quest.

Impact

If users rely on the address derivation in advance or try to deploy the wallet with the same address on different EVM chains, any funds sent to the wallet could potentially be withdrawn by anyone else. All in all, it could lead to the theft of user funds.

Recommended Mitigation Steps

Deploy the quest contract via create2 with salt that includes msg.sender and rewardTokenAddress_.

waynehoover (RabbitHole) acknowledged


The original report as published on Code4rena, by V_B. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the use of create with a nonce-based address derivation, which makes the deployed address predictable and vulnerable to reorg-based front-running.

Impact

It could lead to the theft of user funds if users rely on the address derivation in advance or deploy the same address across EVM chains.

What the attacker needed

A blockchain that experiences reorgs; victim sends funds to a predicted address; attacker can call createQuest

The fix

The quest contract should be deployed via create2 with a salt that includes msg.sender and rewardTokenAddress_.

How it was found

  1. Alice deploys a quest and sends funds to its address.
  2. A network block reorg occurs.
  3. Bob calls createQuest, creating a quest at the same address Alice funded.
  4. Alice's transactions execute, transferring her funds to Bob's quest.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When a contract creates another contract, the new contract's address is predictable from the creator's address and a counter. If the blockchain briefly rewinds (a reorg) and then replays transactions in a different order, someone else can create a contract at the same address first. Funds sent to that address could then be controlled by the attacker.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by V_B

View all

7 more disclosed reports, best first.

More from RabbitHole Quest Protocol contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.