ERC-7562 - Account Abstraction Validation Scope Rules

Created 2023-09-01
Status Draft
Category ERC
Type Standards Track
Authors

Abstract

This document describes the validation rules that ERC-4337 Account Abstraction protocol participants must follow for user transactions represented as UserOperation structs, alongside the rationale for each rule. Block builders and standalone bundlers enforce these rules off-chain.

Motivation

With Account Abstraction, transaction validation, gas payment, and execution are handled by EVM code rather than hard-coded protocol rules. This provides several benefits: - Abstracting validation enables custom signature schemes, multisig configurations, and account recovery. - Abstracting gas payment facilitates onboarding via third-party payments, ERC-20 token payments, and cross-chain fee abstraction. - Abstracting execution supports batched transactions.

These capabilities are unavailable in the traditional Externally Owned Account (EOA) model.

However, preserving network decentralization requires one fundamental rule: once admitted to the mempool, a transaction must guarantee fee payment to prevent denial-of-service (DoS) attacks.

The EOA model implicitly follows this rule. A valid transaction cannot become invalid without the account paying fees. For instance, the account's balance can only be reduced by a higher-paying transaction.

This property ensures network sustainability. An attack involving a massive influx of transactions is economically prohibitive, as costs escalate with network congestion. While legitimate users can delay operations to avoid high fees, an attacker must pay increasingly exorbitant amounts to maintain the congestion.

To replicate this incentive structure in Account Abstraction systems, we propose a set of transaction validation rules. These rules only apply to the validation phase of Account Abstraction transactions, not their entire executed code path.

For the interfaces of these contract-based accounts, see ERC-4337.

This document uses the term "UserOperation" for a transaction created by a smart contract account, following ERC-4337 terminology. Notably, many of these rules can also be applicable in any other Account Abstraction framework that uses EVM code to perform transaction validation in a public mempool, and that treats validation and execution as distinct components of a transaction.

Specification

Validation Rule Types

We define two types of validation rules: network-wide rules and local rules.

A violation of any validation rule by a UserOperation results in the UserOperation being dropped from the mempool and excluded from a bundle.

A network-wide rule is a rule whose violation by a UserOperation damages the reputation of the peer bundler that sent this UserOperation into the P2P mempool. A peer bundler with critically low reputation is eventually marked as a malicious spammer peer.

A local rule is enforced according to each bundler's own local state. Because this state may differ between bundlers, there is no need for consensus on local rule violations. Thus, the bundler that sent the violating UserOperation does not suffer P2P reputation damage from its peers. Local rules are explicitly designated in the Local Rules section; every other rule in this document is a network-wide rule.

Constants

Title Value Comment
MIN_UNSTAKE_DELAY 86400 1 day, which provides a sufficient withdrawal delay to prevent most Sybil attacks
MIN_STAKE_VALUE Adjustable per chain value Recommended to be a non-trivial but not excessive amount, roughly $1000 equivalent in native tokens, sufficient to deter most Sybil attacks without being prohibitive
SAME_SENDER_MEMPOOL_COUNT 4 Maximum number of UserOperations allowed in the mempool from a single sender
SAME_UNSTAKED_ENTITY_MEMPOOL_COUNT 10 Maximum number of UserOperations in the mempool that reference the same unstaked entity
THROTTLED_ENTITY_MEMPOOL_COUNT 4 Number of UserOperations with a throttled entity that can stay in the mempool
THROTTLED_ENTITY_LIVE_BLOCKS 10 Number of blocks a UserOperation with a throttled entity can stay in the mempool
THROTTLED_ENTITY_BUNDLE_COUNT 4 Number of UserOperations with a throttled entity that can be added in a single bundle
MIN_INCLUSION_RATE_DENOMINATOR 10 A denominator of a formula for entity reputation calculation
THROTTLING_SLACK 10 Part of a reputation formula that allows entities to legitimately reject some transactions without being throttled
BAN_SLACK 50 Part of a reputation formula that allows throttled entities to reject some transactions without being throttled
BAN_OPS_SEEN_PENALTY 10000 A value to put into the opsSeen counter of an entity to declare it banned
MAX_OPS_ALLOWED_UNSTAKED_ENTITY 10000 Upper bound on opsIncluded used when calculating opsAllowed for an unstaked entity
PRE_VERIFICATION_OVERHEAD_GAS 50000 Gas used by the EntryPoint per UserOp that cannot be tracked on-chain
MAX_VERIFICATION_GAS 500000 Maximum gas verification functions may use
MAX_USEROP_SIZE 8192 Maximum size of a single packed and ABI-encoded UserOperation in bytes
MAX_CONTEXT_SIZE 2048 Maximum size of a context byte array returned by a paymaster in a single UserOperation in bytes
MAX_BUNDLE_SIZE 262144 Maximum size of an ABI-encoded bundle call to the handleOps function in bytes
MAX_BUNDLE_CONTEXT_SIZE 65536 Maximum total size of all context byte arrays returned by all paymasters in all UserOperations in a bundle in bytes
VALIDATION_GAS_SLACK 4000 An amount of gas that must be added to the estimations of verificationGasLimit and paymasterVerificationGasLimit

Validation Rules

Definitions

  1. Validation Phase: There are up to three on-chain frames during the validation phase:

    1. sender deployment frame (once per account)
    2. sender validation (required)
    3. paymaster validation frame (optional)
  2. Execution Phase: There are up to two on-chain frames during the execution phase:

  3. sender execution frame (required)
  4. paymaster post-transaction frame (optional)

The validation rules only apply during the validation phase. Once a UserOperation is validated, it is guaranteed to pay. There are no restrictions on execution, neither on the account's callData nor on the paymaster's postOp.

  1. Entity: A contract that is explicitly specified by the UserOperation. Entities include the factory, paymaster, aggregator, and staked account, as discussed in the Entity-specific Rules section below. Each validation frame is attributed to a single entity. Entity contracts must have code deployed on-chain.
  2. Canonical Mempool: The rules defined in this document apply to the main mempool shared by all bundlers on the network.
  3. Staked Entity: An entity that has a locked stake of at least MIN_STAKE_VALUE and an unstake delay of at least MIN_UNSTAKE_DELAY.
  4. Associated storage: A storage slot of any smart contract is considered to be "associated" with address A if:
    1. The slot value is A
    2. The slot value was calculated as keccak(A||x)+n, where x is a bytes32 value, and n is a value in the range 0..128
  5. Using an address: Accessing the code of a given address in any way. This can be done by executing *CALL or EXTCODE* opcodes for a given address.
  6. Spammer: A P2P peer bundler that attempts a DoS attack on the mempool by sending other peers a large number of invalid UserOperations. Bundlers MUST detect and disconnect from such peers, as described in the Mempool Validation Rules section.

Reputation Definitions

  1. opsSeen: A per-entity counter of how many times a unique valid UserOperation referencing this entity was received by this bundler. This includes UserOperations received via incoming RPC calls or through a P2P mempool protocol.

  2. opsIncluded: A per-entity counter of how many times a unique valid UserOperation referencing this entity appeared in an actual included UserOperation. Calculation of this value is based on UserOperationEvents and is only counted for UserOperations that were previously counted as opsSeen by this bundler.

  3. Refresh rate: Both of the above values are updated every hour as value = value * 23 // 24. Effectively, the value is reduced to 1% after 4 days.
  4. inclusionRate: Ratio of opsIncluded to opsSeen.

Reputation Calculation

We define a value max_seen = opsSeen // MIN_INCLUSION_RATE_DENOMINATOR.

The reputation state of each entity is determined as follows:

  1. BANNED: max_seen > opsIncluded + BAN_SLACK
  2. THROTTLED: max_seen > opsIncluded + THROTTLING_SLACK
  3. OK: otherwise

New entities start with an OK reputation.

The reputation refresh rate limits a malicious paymaster to processing at most BAN_SLACK * MIN_INCLUSION_RATE_DENOMINATOR / 24 non-paying UserOperations per hour. This affects only the P2P network, not the blockchain.

Running the Validation Rules

  1. A block builder or a bundler should perform a full validation once before accepting a UserOperation into its mempool, and again before including it in a bundle/block.
  2. The bundler should trace the validation phase of the UserOperation and apply all the rules defined in this document.
  3. A bundler should also perform a full validation of the entire bundle before submission.
  4. The validation rules prevent an unstaked entity from altering its behavior between simulation and execution of the UserOperation. However, a malicious staked entity can detect that it is running as part of a bundle validation and cause a revert. Thus, a third tracing simulation of the entire bundle should be performed before submission.
  5. Any failed UserOperation must be dropped from the bundle.
  6. The bundler should update the reputation of the staked entity that violated the rules, considering it THROTTLED/BANNED as described in the General Reputation Rules section below.

Mempool Validation Rules

  1. A UserOperation is broadcast over the P2P protocol with the following information:
    1. The UserOperation itself.
    2. The blockhash this UserOperation was originally verified against.
  2. Once a UserOperation is received from another bundler, it should be verified locally by the receiving bundler.
  3. A received UserOperation may fail one of several static checks, such as an invalid format, values below the minimum, or an outdated blockhash. In this case, the bundler should drop this particular UserOperation but keep the connection.
  4. The bundler should check the UserOperation against the nonces of last-included bundles and silently drop UserOperations with a nonce that was recently included. This invalidation is likely attributable to a network race condition and should not cause a reputation change.
  5. If a received UserOperation fails against the current block:
    1. Retry the validation against the block the UserOperation was originally verified against.
    2. If it succeeds, silently drop the UserOperation and keep the connection.
    3. If it fails, mark the sender as a "spammer": disconnect from that peer and block it permanently.

Opcode Rules

Contract Creation

Code Rules

Storage Rules

Storage access using the SLOAD, SSTORE, TLOAD, and TSTORE instructions is limited within each phase as follows:

Local Rules

Local storage rules protect the bundler against denial of service at the time of bundling. They do not affect mempool propagation and cannot cause a bundler to be marked as a "spammer". * [STO-040] A UserOperation may not use a factory, paymaster, or aggregator address that is used as an "account" in another UserOperation in the mempool. This means that paymaster, factory, or aggregator contracts cannot practically be an "account" contract as well. * [STO-041] A UserOperation may not use associated storage of either its account or a staked entity, in a contract that is a "sender" of another UserOperation in the mempool.

General Reputation Rules

The following reputation rules apply to all staked entities and to unstaked paymasters. All rules apply to all of these entities unless specified otherwise.

Staked Entities Reputation Rules

Entity-specific Rules

Staked Factory Creation Rules

Unstaked Entities Reputation Rules

Alt-mempools Rules

An alternate mempool is an agreed-upon rule that bundlers may opt into, in addition to the canonical mempool. The alt-mempool "topic" is a unique identifier. By convention, this is the IPFS hash of the document that describes the specifics of this alt mempool, written in clear text and a YAML file.

Alt-mempool Reputation

Alt-mempools are served by the same bundlers participating in the canonical mempool, but change the rules and may introduce denial-of-service attack vectors. To prevent them from taking the canonical mempool or other alt-mempools down with them, a reputation is managed for each. An alt-mempool that causes too many invalidations gets throttled. This limits the scope of the attack and lets the bundler continue doing its work for other mempools.

Authorizations

Limitations

The validation rules attempt to guarantee a degree of isolation between individual UserOperations' validations. In order to prevent hitting the memory expansion limitations that the Ethereum EVM imposes when creating a bundle, UserOperations must meet the following limitations:

Rationale

All transactions initiated by EOAs have an implicit validation phase where balance, nonce, and signature are checked against the current state of the Ethereum blockchain. Once a node has validated the transaction, only another transaction by the same EOA can modify the Ethereum state in a way that invalidates the first transaction.

With Account Abstraction, however, validation can also include arbitrary EVM code and rely on storage, which means that unrelated UserOperations or transactions may invalidate each other.

If not addressed, this would make maintaining a mempool of valid UserOperations and producing valid bundles computationally infeasible and susceptible to DoS attacks.

This document describes a set of validation rules that, if applied by a bundler before accepting a UserOperation into the mempool, prevent such attacks.

The high-level goal

The purpose of this specification is to define a consensus between nodes, whether bundlers or block builders, when processing incoming UserOperations from an external source. This external source is either an end-user node submitting via the ERC-7769 RPC, or another node in the P2P network.

The protocol detects "spam" — large bursts of UserOperations that cannot be included on-chain and thus cannot pay fees. The network is protected by throttling requests from such spammer nodes.

All network nodes must share the same definition of "spam". If some nodes propagate UserOperations that others consider spam, the forgiving nodes risk being marked as spammers, potentially fracturing the network.

The processing flow of a UserOperation

The need for a second validation before submitting a block

A standard Ethereum transaction can be invalidated if replaced by another transaction with the same nonce. The replacement transaction must pay a higher gas price, satisfying the rule that mempool inclusion requires payment. With contract-based accounts, a UserOperation's validity may depend on mutable state. Other transactions can invalidate a previously valid UserOperation, necessitating a second validation before block inclusion.

Rationale for limiting opcodes

Rationale for limiting storage access

Rationale for requiring a stake

We want to allow globally-used contracts, such as paymasters, factories, and aggregators, to use storage not associated with the account, but still prevent them from spamming the mempool. If a contract causes too many UserOperations to fail in their second validation after succeeding in their first, we can throttle its use in the mempool.

Requiring a stake prevents Sybil attacks by making it economically unviable to spawn numerous malicious paymasters to sustain a spam attack.

The validation rules allow nodes to detect and throttle contracts responsible for spam. The stake prevents the rapid recreation of these malicious entities. Because the stake serves only for off-chain detection, it is never slashed; however, the required lock-up period significantly increases the capital cost of an attack.

Definition of the mass invalidation attack

A series of actions constitutes a mass invalidation attack if a large number of UserOperations—having passed initial validation and propagated through the mempool—subsequently become invalid and ineligible for block inclusion.

There are three ways to execute such an attack:

  1. Submitting UserOperations that pass initial validation but fail the second validation during bundle creation.
  2. Submitting UserOperations that are valid in isolation but become invalid when bundled together.
  3. Front-running valid UserOperations with an economically viable state change that invalidates them.

To prevent these attacks, the validation code is sandboxed. It is isolated from other UserOperations, external storage changes, and environmental information like the current block timestamp.

What is not considered a mass invalidation attack

A UserOperation that fails initial validation without entering the mempool is not considered an attack. Nodes are expected to implement standard security measures, throttling requests based on API keys, IP addresses, or P2P peer scoring, to prevent spam.

Furthermore, if invalidating N UserOperations costs an attacker N * X (where X is sufficiently large), the attack is not considered economically viable.

Security Considerations

This document describes the security considerations that bundlers must take to protect themselves, and the entire mempool network, from denial-of-service attacks.

Copyright

Copyright and related rights waived via CC0.