Account Initialization Frontrunning

Account initialization frontrunning targets the moment a smart contract wallet is deployed: an attacker reads the mempool

SECURITY5 min readBy AlgoSys Editorial TeamPublished Apr 24, 2026Updated Nov 28, 2026
Contents

Account initialization frontrunning is a sophisticated attack vector targeting smart contract wallets and account abstraction implementations (ERC-4337, the standard that allows a wallet to be controlled programmatically rather than solely through an ordinary key). The idea is straightforward. An attacker watches the mempool (the queue of not-yet-confirmed transactions) and looks for operations that create a new contract wallet. As soon as such an operation is found, the attacker sends their own transaction and interacts with the newly created account before the legitimate owner can. The goal is usually the same: to exploit the contract's initial state or to claim certain resources before the real user gets to them.

This threat is particularly acute in ecosystems with account abstraction, where contract wallets are created programmatically. If anyone can deploy such a wallet, an attacker can either preemptively deploy a malicious contract or insert themselves into an interaction with a legitimate one. The topic does not yet receive as much coverage as high-profile DeFi exploits, but concern around it is growing as account abstraction gains popularity.

Known incidents are not always directly linked to this specific vector, but they clearly illustrate the dangers of predictable account deployment and premature interaction with a newly created wallet. The frontrunning principle itself, familiar from numerous DEX exploits and MEV (maximal extractable value, the profit a validator or bot can extract from the ordering of transactions within a block), applies here as well. An attacker sees pending transactions and inserts their own at a higher gas price to gain priority.

MECHANICS

Everything begins when a user initiates the deployment of a new contract wallet, most often through an ERC-4337 entry point or a factory contract (a template that stamps out identical wallets). The deployment transaction is sent to the network and becomes visible in the mempool, meaning it is accessible to anyone monitoring it.

Next, the attacker's bot, which is monitoring the mempool, gets involved. Having detected the pending deployment, the bot parses the transaction and predicts the address of the future wallet. Prediction is possible because the address is usually computed deterministically: from the deployer account's nonce (the nonce is a counter of sent transactions) or by another address-generation scheme that is known in advance.

Once the future address is known, the attacker crafts a transaction aimed directly at it and sends it with a higher gas price than the legitimate deployment transaction. The elevated gas virtually guarantees the attacker's transaction gets included in the block first. It executes immediately after the wallet is deployed, interacting with it in a way the owner never intended.

RED FLAGS

A few characteristic signs can raise suspicion of account initialization frontrunning. If even some of them overlap, a closer look is warranted:

  • A freshly deployed contract wallet shows unexpected state changes or token balances that appeared from nowhere, right after creation.
  • The first interaction with the new wallet comes from an address already known for opportunistic or outright malicious activity.
  • The gas price on the original deployment transaction is suspiciously high, signaling an attempt to get ahead of other network participants.
  • The wallet's constructor or initialization function contains logic that can be exploited by an immediate second transaction.
  • Mempool monitoring services record the pattern: rapid deployment immediately followed by high-gas interaction with the newly created contract.

To understand how these signs combine into a real attack, consider a simplified example.

Suppose a wallet is created through a factory and its address is derived from the deployer's nonce, which equals 42. The user sends the deployment transaction with a gas price of 30 gwei. The attacker's bot sees it in the mempool, computes the future address in advance, and immediately sends its own transaction to that address with a gas price of 60 gwei. The block builder sets the order inside the block, and through a private bundle the bot places its transaction right behind the deployment (backrunning), so they land in the block in this order:

Step Transaction Gas price What happens
1 Wallet deployment 30 gwei Contract is created at the predicted address
2 Attacker's transaction 60 gwei Immediately after creation, calls the vulnerable initialization function

Step 2 executes right on the heels of step 1, and the attacker intercepts control of the fresh wallet before the owner can act. This is an illustrative scenario, not a real trade, but it captures the essence: the entire attack rests on address predictability and open mempool access.

PROTECTION

Reducing the risk requires a combination of measures, not a single silver bullet. The baseline is secure smart contract development: thorough code audits by reputable firms that find and close vulnerabilities in initialization logic. Deterministic address-generation schemes can be used where convenient, but it is important to keep in mind that address predictability is exactly what opens the door to frontrunning.

For ERC-4337 implementations, consider bundler services (a bundler is a service that collects user operations into a batch and submits them to the network) that offer transaction-ordering guarantees, or batching mechanisms. Both approaches conceal the exact moment of account creation and narrow the window in which an attacker can intervene. It is also useful to educate users: before giving final confirmation, they should verify all transaction details on a hardware wallet, including the target address and function calls.

Another line of defense is restrictions on the factories and entry points themselves. Rate-limiting or access-control mechanisms prevent wallets from being deployed quickly and without permission. For the most critical initialization stages, a commit-reveal scheme works well: the user first commits the parameters in encrypted form in a separate transaction, and only reveals them in the next operation. This two-step approach adds delay and complicates things for the attacker, who now has nothing useful to observe in the mempool.

AFTERMATH

If frontrunning has already occurred, the first priority is immediate containment. If the compromised contract is still in the initialization phase or has limited functionality, it makes sense to pause its operations or revoke critical permissions. The contract itself should be isolated so that other attackers cannot follow the first one in.

At the same time, report the incident to security incident response teams and blockchain analytics firms. Chainalysis, Elliptic, and similar services help trace the movement of stolen assets. Record all attacker addresses and transaction hashes: they will be needed for forensic analysis and potential prosecution. Engaging law enforcement agencies that specialize in cybercrime and cryptocurrency investigations is also worth considering.

Finally, assess the chances of recovery. If recovery mechanisms were built into the contract logic in advance, use them. Theoretically, you can coordinate with node operators and validators to roll back malicious transactions, but in practice this is extremely difficult and rarely happens. For ERC-4337, work separately with bundler operators: they can identify malicious actors and, if necessary, blacklist them.

FAQ

How does account initialization frontrunning differ from ordinary DEX frontrunning?

The principle is the same: an attacker spots someone else's transaction in the mempool and races ahead of it with a higher gas price. The difference is the target. On an exchange, a bot profits from transaction ordering and price slippage. Here, it targets the moment a contract wallet is born, in order to interact with the fresh account before its owner does and exploit its initial state.

Why can an attacker know the address of a wallet that does not exist yet?

Because in many implementations the address is computed deterministically, that is, by a predictable formula. Most often it depends on the deployer account's nonce or on another scheme that is known in advance. The bot parses the pending deployment transaction, runs the same formula, and obtains the future address before the wallet has even appeared on the network.

Does simply setting a higher gas price on your own deployment transaction help?

No, and this is a common misconception. A higher gas price will only speed up your deployment; it will not prevent the attacker from setting an even higher gas price on their next operation. The problem lies in the predictability of the address and the openness of the mempool, so the solution involves concealing the creation moment (bundlers, batching) and schemes like commit-reveal, not a gas race.

What is a commit-reveal scheme and why does it make the attack harder?

It is a two-step procedure. First, the user commits the initialization parameters in a concealed form in a separate transaction, and only in the next transaction reveals them. There is nothing for the attacker to peek at in the mempool on the first step, and the added delay and extra complexity make intercepting a fresh wallet far less practical.

What signs suggest a wallet may have been attacked right after creation?

The key signals are: a freshly deployed contract shows unexpected state changes or token balances, the first interaction comes from an address with a bad reputation, and the deployment went through at a suspiciously high gas price. If a monitoring service records the pattern "rapid deployment plus immediate high-gas interaction", that is reason to investigate.

Can funds be recovered after a successful attack?

Sometimes, but it is unwise to count on it. If recovery mechanisms were built into the contract logic in advance, they can be used. Rolling back malicious transactions through coordination with node operators and validators is theoretically possible but in practice extremely difficult and rare. For ERC-4337, a more realistic option is to work with bundler operators, who can identify and blacklist malicious actors, plus engage blockchain analytics firms to trace the assets.

Put this to work in the terminal

Live charts, derivatives, on-chain and macro data, free.

Open terminal →