Factory deploy reverts instead of returning address when account already exists
The Factory.deploy function reverts with CreateCollision when a wallet already exists at the deterministic address, instead of returning the existing address as ERC-4337 requires. An attacker could front-run a user's deployment to pre-create the wallet, causing the user's otherwise valid transaction to revert.
Submitted by pfapostol
Finding description
The Factory.deploy function uses create2 to deploy a wallet but reverts (CreateCollision) if address already exists.
Per ERC-4337, factories that use deterministic creation must return the account address even if the account was already created (eip-4337) so bundlers and entryPoint.getSenderAddress() can simulate/obtain the counterfactual address without failing. The current implementation breaks that invariant: calling the factory when the account already exists will revert instead of returning the existing address, which can break ERC-4337 flows (simulations, getSenderAddress, bundler logic, UX).
If the factory does use CREATE2 0xF5 or some other deterministic method to create the Account, it’s expected to return the Account address even if it had already been created.
Additionally, Sequence’s wallet implementation and README expect ERC-4337 compatibility (implements validateUserOp etc.), so factory behavior is important for integration README#erc-4337-integration
Impact
- Compatibility break with ERC-4337.
- DoS as a result of front-running. According to the contest README evidence, front-running is an important concern, but the focus is mainly on preventing an attacker from deploying a malicious contract. That is achieved by making the contract address deterministic. However, this overlooks the fact that a deterministic address allows an attacker to pre-create a wallet before the user can, causing the user’s otherwise valid transaction to revert — which may be critical for tools or contracts that manage wallets automatically.
Recommended mitigation steps
{
bytes memory code = abi.encodePacked(Wallet.creationCode, uint256(uint160(_mainModule)));
+ bytes32 initCodeHash = keccak256(code);
+ bytes32 raw = keccak256(abi.encodePacked(bytes1(0xff), address(this), _salt, initCodeHash));
+ address predicted = address(uint160(uint256(raw)));
+ // If contract already exists at predicted address, return it
+ if (predicted.code.length != 0) {
+ return predicted;
+ }
assembly {
_contract := create2(callvalue(), add(code, 32), mload(code), _salt)
}
if (_contract == address(0)) {
revert DeployFailed(_mainModule, _salt);
}
}
[PASS] test_factory_double_deploy_PoC(address,bytes32) (runs: 257, μ: 76183, ~: 76416)
Traces:
[76416] AuditPoC::test_factory_double_deploy_PoC(0x00000000000000000000000000000000000003cC, 0x0000000000000000000000000000000000000000000000000000000000000025)
├─ [64550] Factory::deploy(0x00000000000000000000000000000000000003cC, 0x0000000000000000000000000000000000000000000000000000000000000025)
│ ├─ [28742] → new <unknown>@0x1a59e6b710e25Cfd61a082a5dD7Cf32585B552dA
│ │ └─ ← [Return] 33 bytes of code
│ └─ ← [Return] 0x1a59e6b710e25Cfd61a082a5dD7Cf32585B552dA
├─ [0] VM::assertEq(33, 33, "Wallet size mismatch") [staticcall]
│ └─ ← [Return]
├─ [1257] Factory::deploy(0x00000000000000000000000000000000000003cC, 0x0000000000000000000000000000000000000000000000000000000000000025)
│ └─ ← [Return] 0x1a59e6b710e25Cfd61a082a5dD7Cf32585B552dA
├─ [0] VM::assertEq(33, 33, "Wallet size mismatch") [staticcall]
│ └─ ← [Return]
└─ ← [Return]
Proof of Concept
- Deploy
Factoryand a wallet viadeploy(_mainModule, salt)once (successful). - Call
deploy(_mainModule, salt)again with same parameters — create2 will find contract already exists, create2 returnsCreateCollisionand the function reverts withDeployFailed(_mainModule, _salt).
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.27;
import {FactoryTest} from "test/Factory.t.sol";
contract AuditPoC is FactoryTest {
function test_factory_double_deploy_PoC(address _mainModule, bytes32 _salt) public {
address result = factory.deploy(_mainModule, _salt);
assertEq(result.code.length, 33, "Wallet size mismatch");
result = factory.deploy(_mainModule, _salt);
assertEq(result.code.length, 33, "Wallet size mismatch");
}
}
[1040431107] AuditPoC::test_factory_double_deploy_PoC(0xbFEA7B873B630d3E83310E2a540C06A45764f0Db, 0xb3f3825fdd0643210f22c977e8adbde170329c48ea748299ef741cfd038c001d)
├─ [61508] Factory::deploy(0xbFEA7B873B630d3E83310E2a540C06A45764f0Db, 0xb3f3825fdd0643210f22c977e8adbde170329c48ea748299ef741cfd038c001d)
│ ├─ [28742] → new <unknown>@0x50A3E320ebE97E988a1FDa7080a5F1eFE55E7b0B
│ │ └─ ← [Return] 33 bytes of code
│ └─ ← [Return] 0x50A3E320ebE97E988a1FDa7080a5F1eFE55E7b0B
├─ [0] VM::assertEq(33, 33, "Wallet size mismatch") [staticcall]
│ └─ ← [Return]
├─ [1040360150] Factory::deploy(0xbFEA7B873B630d3E83310E2a540C06A45764f0Db, 0xb3f3825fdd0643210f22c977e8adbde170329c48ea748299ef741cfd038c001d)
│ ├─ [0] → new <unknown>@0x50A3E320ebE97E988a1FDa7080a5F1eFE55E7b0B
│ │ └─ ← [CreateCollision]
│ └─ ← [Revert] DeployFailed(0xbFEA7B873B630d3E83310E2a540C06A45764f0Db, 0xb3f3825fdd0643210f22c977e8adbde170329c48ea748299ef741cfd038c001d)
└─ ← [Revert] DeployFailed(0xbFEA7B873B630d3E83310E2a540C06A45764f0Db, 0xb3f3825fdd0643210f22c977e8adbde170329c48ea748299ef741cfd038c001d)
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
The deploy function does not check whether a contract already exists at the predicted CREATE2 address and return it; it calls create2 unconditionally, which reverts on collision.
Impact
This breaks ERC-4337 compatibility and allows a front-running attacker to pre-create a wallet, causing the user's valid transaction to revert, which may be critical for tools that manage wallets automatically.
What the attacker needed
Attacker can front-run the deployment; same main module and salt as victim
The fix
The factory should compute the predicted address and, if code already exists there, return that address instead of calling create2.
How it was found
- Deploy the Factory and a wallet via deploy with a main module and salt.
- Call deploy again with the same parameters.
- Observe the create2 collision and the DeployFailed revert.
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.
A factory is a smart contract that creates other contracts. This one uses a method that always produces the same address for the same inputs. If someone else creates the wallet first, the factory crashes instead of simply handing back the address that already exists, which breaks tools that expect it to work that way.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.