Factory::create() is vulnerable to reorg attacks
The Factory contract's create function used tx.origin as the salt for deterministic cloning, so if two users share the same tx.origin (as observed on Blast), a reorg could let one user take over the other's deployed pool. An attacker could then withdraw funds sent to the victim's predicted pool address.
Originally disclosed on Code4rena
Submitted by Bauchibred
function create(address baseToken_, address quoteToken_, uint256 lpFeeRate_, uint256 i_, uint256 k_) external returns (address clone) {
address creator = tx.origin;
bytes32 salt = _computeSalt(creator, baseToken_, quoteToken_, lpFeeRate_, i_, k_);
clone = LibClone.cloneDeterministic(address(implementation), salt);
IMagicLP(clone).init(address(baseToken_), address(quoteToken_), lpFeeRate_, address(maintainerFeeRateModel), i_, k_);
emit LogCreated(clone, baseToken_, quoteToken_, creator, lpFeeRate_, maintainerFeeRateModel, i_, k_);
_addPool(creator, baseToken_, quoteToken_, clone);
}
We can see that this function uses the create() logic and depends on the tx.origin, now Blast is suspicious of a reorg attack and protocol would be deployed on here.
Where as one can assume that the tx.origin should be different for different calls this is not really the case as going to the Blast Explorer for transactions that are currently enqueued we can see that only two addresses are rampant as the tx.origin, i.e 0x4b16E5d33D7ab3864d53aAec93c8301C1FA4a226 and 0x6e5572f31bd9385709ec61305Afc749F0fa8fae1 what this leads is the fact that another user can just wait and due to a re-org take control of the magic lp deployment, since the tx.origin in this case would be the same with original deployer’s own.
Impact
Now, if users rely on the address derivation in advance or try to deploy the magiclp with the same address, any funds/tokens sent to it could potentially be withdrawn by anyone else. All in all, it could lead to the theft of user funds.
Recommended Mitigation Steps
Try the deployment using create2 with salt that includes real msg.sender.
0xCalibur (Abracadabra) acknowledged and commented:
This was fixed during the audit. We now use the creator address as part of the salt.
https://docs.code4rena.com/roles/judges/how-to-judge-a-contest#notes-on-judging
Unless there is something uniquely novel created by combining vectors, most submissions regarding vulnerabilities that are inherent to a particular system or the Ethereum network as a whole should be considered QA. Examples of such vulnerabilities include front running, sandwich attacks, and MEV. In such events, leave a comment on the issue:
As per the c4 docs, will downgrade to QA.
Bauchibred (Warden) commented:
Hi @cccz (Judge), thanks for judging, in regards to this:
https://docs.code4rena.com/roles/judges/how-to-judge-a-contest#notes-on-judging
Unless there is something uniquely novel created by combining vectors, most submissions regarding vulnerabilities that are inherent to a particular system or the Ethereum network as a whole should be considered QA. Examples of such vulnerabilities include front running, sandwich attacks, and MEV. In such events, leave a comment on the issue:
As per the c4 docs, will downgrade to QA.
The idea of using this rule as the grounds for downgrading this issue seems to be flawed, cause considering this rule, do we now say all front running, MEV bug ideas are invalid on Code4rena? We beg to differ as context really matters for bug cases like this.
In fact a similar discussion around this bug case (very similar instance) was held a short while ago, can be seen here, and the deciding lines of the validity of the report not being a medium severity was the fact that in that instance the protocol was to be deployed on Canto, and Canto is a fork of Evmos/Ethermint, so it uses Tendermint Core BFT consensus, which provides a 1-block finality and not probabilisitic finality like other chains: https://docs.ethermint.zone/core/pending_state.html
But that’s not the case we have here, in this case protocol is to be deployed on Blast
- Blast is an optimistic rollup, just like Arbritrum, Base, Optimism, etc.
- Optimistic rollups are known for having re-org issues.
- Not all current
satisfactoryH/M issues have been fixed by the protocol, but this was not only confirmed by the protocol but also addressed in this commit, proving that this issue is of great value to them and accepted by them to be worthy a fix.Considering all the above arguments, we’d request a reassessment of this finding being validated as medium severity, thank you.
These facts raise the likelihood of this issue, will reconsider it as M:
- Blast is an optimistic rollup, just like Arbritrum, Base, Optimism, etc.
- Optimistic rollups are known for having re-org issues.
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 tx.origin instead of msg.sender in the salt computation for deterministic cloning, allowing address collisions when tx.origin is shared.
Impact
If users rely on the predicted address or deploy with the same address, any funds sent to the pool could be withdrawn by someone else, leading to theft of user funds.
What the attacker needed
Protocol deployed on a chain with reorgs (e.g., Blast); Two users share the same tx.origin; Victim sends funds to predicted pool address
The fix
The issue was fixed by including the creator address (msg.sender) in the salt.
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 a new pool, it uses a salt to determine the pool's address. The salt was based on tx.origin, which is the original wallet that started the transaction. If two different users happen to use the same wallet (or the same tx.origin) and a blockchain reorganisation (reorg) occurs, one user could end up controlling the other's pool and steal any funds sent to it.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.