ERC-7562 · Review · ERC · 2023-09-01
ERC-7562: Account Abstraction Validation Scope Rules
The rules ERC-4337 bundlers apply to a UserOperation's validation code (banned opcodes, storage limits, staking and reputation) so a shared mempool cannot be flooded with operations that never pay.
What problem does it solve?
With a normal EOA transaction, validity is cheap to check and stable: signature, nonce, balance. Once a transaction is in the mempool, it cannot become invalid without the sender paying for something. That property is what keeps a public mempool safe from spam.
With account abstraction (ERC-4337), validation is arbitrary EVM code in the account, factory and paymaster. That code could read the timestamp, someone else's storage or the block number, so a UserOperation that simulated fine could fail at inclusion. An attacker could then fill bundlers' mempools with thousands of operations that are invalidated together, all for free.
ERC-7562 defines what validation code may do so that, once accepted into the mempool, a UserOperation will either pay or be cheaply attributed to a misbehaving party.
How it works
The rules apply only to the validation phase (account deployment, validateUserOp, paymaster validation), never to execution.
- Opcode rules: environment-reading opcodes are banned, including
ORIGIN,GASPRICE,BLOCKHASH,COINBASE,TIMESTAMP,NUMBER,PREVRANDAO,GASLIMIT,BASEFEE,SELFDESTRUCTand mostCREATEuses.GASis allowed only right before a*CALL.CREATE2is allowed once, to deploy the sender. Calls with value are banned except to the EntryPoint. Transient storage is treated like normal storage. - Storage rules: an account may always touch its own storage, and storage "associated" with it in other contracts (slots keyed by its address, as in token balances). Staked factories and paymasters get extra access.
- Code rules: the code hash of anything touched must not change between validations.
- Staking and reputation: factories, paymasters and aggregators can lock a stake (minimum unstake delay of one day). Bundlers track
opsSeenvsopsIncludedper entity; entities that cause too many failures becomeTHROTTLEDand thenBANNED. - Mempool rules: bundlers re-check operations received from peers; a peer that sends operations failing even against the block they were validated on is marked a spammer.
- Limits on operation size, paymaster context size and verification gas; alt-mempools may opt into looser rules; and rules for EIP-7702 authorizations (at most one per
UserOperation).
Rules are labelled (for example OP-011, STO-021) so bundler errors can cite them.
Sample code
A validation function that follows the rules, versus one that breaks them:
// OK: reads only the account's own storage and uses a signature
function validateUserOp(PackedUserOperation calldata op, bytes32 hash, uint256 missingFunds)
external returns (uint256)
{
require(msg.sender == entryPoint, "not EP");
if (ECDSA.recover(hash, op.signature) != owner) return 1; // SIG_VALIDATION_FAILED
if (missingFunds > 0) {
(bool ok, ) = payable(msg.sender).call{value: missingFunds}(""); // value call to EntryPoint is allowed
ok;
}
return 0;
}
// REJECTED by bundlers: TIMESTAMP is banned (OP-011)
function validateUserOpBad(PackedUserOperation calldata, bytes32, uint256) external returns (uint256) {
require(block.timestamp % 2 == 0, "only even seconds");
return 0;
}
Time windows should instead be expressed through the validUntil / validAfter fields packed into the return value, which the EntryPoint checks.
Things to know
- Status is Review. Constants and rule numbers have changed over time; check the version your bundler implements.
- These are off-chain, bundler-enforced rules. A
UserOperationthat breaks them is not invalid on-chain; public bundlers simply will not accept it into the shared mempool. - The stake value (
MIN_STAKE_VALUE) is set per chain rather than fixed by the spec. - Paymasters and factories that need wider storage access usually must be staked.
- The spec references EIP-7623 calldata pricing and the EIP-7951 secp256r1 precompile, which is on the allowed precompile list.