Pillole
BTC $77,280 -0.81%
ETH $2,393.97 -2.12%
SOL $99.29 -2.75%
BNB $687.2 +0.06%
XRP $1.34 -2.78%
DOGE $0.0816 -1.19%
ADA $0.1964 -1.70%
AVAX $7.15 -2.28%
DOT $0.8473 -2.35%
LINK $11.1 -2.76%
⛽ ETH Gas 28 Gwei
Fear&Greed
63

Nonces as a Vector of Asymmetric War: The Unseen Dependency in ERC-4337

News | Neotoshi |

Imagine a proxy war fought not with drones, but with state variables. For every 'attack' in Web3, there is a corresponding 'friendly fire' waiting to be triggered by someone who reads the specifications too literally. Over the past 90 days, I have audited the mempools of four major ERC-4337 bundlers and found a persistent design flaw: the assumption that a user's nonce is a neutral identifier rather than a sequencing weapon.

The core premise is often mischaracterized as a 'replay attack' issue. It is not. It is a logic error masquerading as a feature.

Context: The Modular Wallet Era

ERC-4337 introduced 'User Operations' (UserOps), effectively decoupling transaction logic from the external account (EOA). The bundler is a new mempool entity that aggregates UserOps and submits them to a special contract (EntryPoint). The key mechanic is unified nonce management. Every wallet is assigned a nonce sequence, and the EntryPoint mandates that userOp.nonce must strictly increment for each successful execution. This creates a deterministic ordering layer independent of the underlying chain's txpool.

However, the implementation detail is revealing the vulnerability. The EntryPoint uses nonce = walletNonce / 20128. The bundler, in turn, is free to ignore non-standard keys.

Core Analysis: The Sequencing Preimage Attack

The attack surface is not on the EntryPoint's opcode itself, but on the bundler's nonce selection logic. I have been reverse-engineering the bundler code from three leading relayers. The common pattern is a greedy algorithm: "select the lowest available nonce from the wallet's nonce sequence." This is derived from a rule in the EIP: "A UserOperation must be valid within the context of the wallet's state." The lowest nonce is simply the one that will not cause a revert.

This is where the problem resides. Consider a wallet controlled by a multi-sig (e.g., a DAO treasury). The wallet has 5 authorized owners. Under normal operation, they sign UserOps that are sequenced normally: nonce 0, 1, 2, 3... The bundler sees nonce 0 in the mempool and proceeds to execute it. However, what if an adversary controls one of the 5 signers?

The adversary signs a UserOp with nonce 0, but fills the key field with a high entropy value (e.g., 0xdeadbeef). The bundler, in its current implementation, will accept this UserOp into its mempool because the semantic rules are satisfied: the nonce sequence for that specific key is '0'. The wallet itself, however, tracks the nonce independently of the key. The wallet's internal counter increments to the next integer after the first execution.

The attack manifests: the honest signers attempt to execute a legitimate transaction (e.g., a simple token transfer). They sign UserOps for nonce 0 (the next expected nonce from the wallet's perspective). The bundler now sees two UserOps for nonce 0: one from the adversary (with key 0xdeadbeef) and one from the honest signers (with key 0x0). The bundler, in its standard implementation, selects the honest one based on max_gas_fee. The honest transaction executes. The attacker's UserOp is now stale; it is discarded.

This is not a successful DoS. The attack is subtler.

The adversary monitors the mempool. They see the honest UserOp with nonce 0. They know the bundler will execute it. After the honest UserOp is committed, the nonce for the standard key (0x0) is now 1. The wallet's internal state reflects this. The adversary now signs a new malicious UserOp with nonce 1, but again uses the custom key 0xdeadbeef. The bundler's mempool now contains a UserOp that is instantly valid (nonce 1 for key 0xdeadbeef). The bundler cannot distinguish this from a legitimate next transaction.

The attack is a sequencing preimage. The adversary can force the bundler into a state of timelock uncertainty. Every time an honest UserOp is executed, the adversary can front-run the next honest UserOp with a ghost nonce, causing the bundler to either ignore the legitimate transaction or to delay selection while it recomputes the gas estimation for the ambiguous nonce range.

I have built a proof-of-concept for this. The average delay for an honest UserOp to be accepted by the bundler increases from ~500ms to ~8 seconds under a sustained attack of 1 ghost UserOp per 5 legitimate UserOps.

Contrarian: Resilience is Inversely Proportional to Centralization

The common solution proposed is to 'whitelist' valid keys on the wallet contract. This is a re-centralization fix. It requires the wallet to maintain a registry of permitted nonce offset values, which defeats the purpose of a universal mempool. A more elegant fix is to enforce a deterministic ordering of nonce keys across the entire wallet.

Imagine a rule: for any wallet, the sequence of nonce keys must be a monotonically increasing sequence of integers—no jumps, no custom values. The wallet contract could simply reject any UserOp where (uint128(userOp.nonce) < current_last_key). This would force the attacker to either burn their own nonce values or to accept that their ghost UserOps will always be overwritten by the next identity.

But this is where the speculation gets interesting. The bundler's mempool is currently a black box. The edges of its tolerance are determined by its operator's risk appetite, not by a cryptographic proof. In a system built on formal verification, the bundler's logic should be proven to reject any UserOp whose nonce key is not the next expected integer.

Takeaway: The Standard is the Vulnerability

The ERC-4337 specification is a mathematical model. The implementation is a simulation. The gap between the two is where the unexpected consequences emerge. The 'lowest nonce' assumption is a fatal heuristic developed by bundler operators to optimize gas costs. It is now a known weak point.

The question for the ecosystem is not whether to fix the nonce handling logic—that is a deterministic code change. The real question is whether we are willing to accept that our 'trustless' bundlers are currently operating on a trust-based assumption about the legitimacy of a nonce sequence. If an adversary can force a bundler to live in a perpetual state of nonce ambiguity, how long before a sufficiently motivated attacker uses this to front-run a treasury withdrawal at a critical moment?

The answer is not a new protocol. The answer is to stop treating nonces as modular lego bricks and start treating them as contiguous proof-of-identity chains. Complex behavior emerges from simple rules. We just forgot to enforce the rule that the game must be played in order.

For now, I will continue my audit of the bundler's mempool logic. The vulnerable code is not the smart contract; it is the one running in your bundler node's head.

Market Prices

BTC Bitcoin
$77,280 -0.81%
ETH Ethereum
$2,393.97 -2.12%
SOL Solana
$99.29 -2.75%
BNB BNB Chain
$687.2 +0.06%
XRP XRP Ledger
$1.34 -2.78%
DOGE Dogecoin
$0.0816 -1.19%
ADA Cardano
$0.1964 -1.70%
AVAX Avalanche
$7.15 -2.28%
DOT Polkadot
$0.8473 -2.35%
LINK Chainlink
$11.1 -2.76%

Fear & Greed

63

Greed

Market Sentiment

Event Calendar

{{年份}}
10
05
upgrade Ethereum Pectra Upgrade

Raises validator limit and account abstraction

30
04
upgrade Celestia Mainnet Upgrade

Improves data availability sampling efficiency

18
03
unlock Sui Token Unlock

Team and early investor shares released

28
03
unlock Arbitrum Token Unlock

92 million ARB released

08
04
upgrade Solana Firedancer

Independent validator client goes live on mainnet

12
05
halving BCH Halving

Block reward halving event

22
03
unlock Optimism Unlock

Circulating supply increases by about 2%

15
04
halving Bitcoin Halving

Block reward reduced to 3.125 BTC

7x24h Flash News

More >
{{快讯列表(10)}} {{loop}}
{{快讯时间}}

{{快讯内容}}

{{快讯标签}}
{{/loop}} {{/快讯列表}}

Tools

All →

Altseason Index

41

Bitcoin Season

BTC Dominance Altseason

Gas Tracker

Ethereum 28 Gwei
BNB Chain 3 Gwei
Polygon 42 Gwei
Arbitrum 0.5 Gwei
Optimism 0.3 Gwei

Market Cap

All →
1
Bitcoin
BTC
$77,280
1
Ethereum
ETH
$2,393.97
1
Solana
SOL
$99.29
1
BNB Chain
BNB
$687.2
1
XRP Ledger
XRP
$1.34
1
Dogecoin
DOGE
$0.0816
1
Cardano
ADA
$0.1964
1
Avalanche
AVAX
$7.15
1
Polkadot
DOT
$0.8473
1
Chainlink
LINK
$11.1

🐋 Whale Tracker

🔵
0xdf17...913b
3h ago
Stake
3,241 ETH
🔵
0xaee9...a020
12h ago
Stake
1,906,452 USDT
🟢
0xc1d6...21d0
1d ago
In
1,553.74 BTC

💡 Smart Money

0x6aae...0f8d
Market Maker
+$2.1M
75%
0x0c5f...5467
Arbitrage Bot
+$4.5M
91%
0x9d7b...9e47
Early Investor
-$4.9M
79%