ERC-5189 Account abstraction based on endorsed operations (Account Abstraction via Endorsed Operations)

Draft · Accounts & wallets · created 2022-06-29

An account abstraction approach that processes smart contract wallet transactions without changing the protocol. An endorser contract pre-determines whether a transaction will properly pay its fee.

Why it is needed

A relayer (bundler) that submits transactions on behalf of a smart contract wallet has difficulty knowing in advance whether that transaction will actually pay its fee. Verifying this requires actually executing the entire transaction, and if a malicious user changes state right before execution to make the transaction fail, the bundler wastes gas for nothing. Also, since even a small change in chain state can invalidate transactions without any way to know which ones, the entire mempool must be continually re-checked. Conversely, trying to solve this by strictly standardizing the transaction format would require every already-deployed smart contract wallet to be individually upgraded, and would reduce the freedom to design new wallets. This standard tries to solve both problems at once by delegating the determination responsibility to an endorser contract built by the wallet developer.

What to implement

In depth

The Operation struct

To avoid changing the consensus layer, this standard does not introduce a new transaction type, and instead bundles AA transactions into a struct called Operation. Its main fields are entrypoint and callData, the execution target; fixedGas, a fixed gas amount paid regardless of execution; gasLimit, the minimum gas that must be forwarded at execution; feeToken, the fee token (address(0) for the native token); endorser, endorserCallData, and endorserGasLimit, which handle verification; maxFeePerGas and priorityFeePerGas, the fee cap and the bundler's share; feeScalingFactor and feeNormalizationFactor, for converting to token units; hasUntrustedContext, indicating an untrusted path; and chainId. The entrypoint is usually the wallet contract itself, but it can also be an intermediate utility that deploys the wallet first and then carries out the transaction.

The endorser and isOperationReady

An endorser is a deployed smart contract. If isOperationReady returns true for readiness, that transaction should execute correctly and the bundler should receive the stated gas fee. Even if the operation's internal intent fails, fee payment must still be guaranteed. The globalDependency returned alongside it represents dependencies on global variables such as block number and timestamp, while dependencies lists the addresses and storage slots to watch; if these values change, readiness must be re-evaluated. Endorsers are deployed on-chain, but calls to them must not be submitted on-chain; the bundler simulates them off-chain. This is only a soft guarantee, so the bundler must always simulate the execution result itself before block inclusion.

Dependencies and constraints

A Dependency entry specifies balance, code, nonce, allSlots, slots, and constraints per address. allSlots, slots, and constraints are mutually exclusive: if allSlots is true, the others must be empty arrays, and a slot listed in constraints cannot also be duplicated in slots. To reduce re-evaluation overhead, endorsers should prefer constraints over slots, and slots over allSlots, wherever possible. A Constraint means that readiness is valid only while the slot value is between minValue and maxValue, inclusive. The global dependency fields maxBlockNumber and maxBlockTimestamp set the expiration of the determination; if there is no expiration, they must be set to type(uint256).max. Not every accessed slot needs to be listed, only the ones whose change could alter readiness.

simulationSettings and State Replacement

Before simulating isOperationReady, the bundler must first call simulationSettings to obtain the replacement list and apply it. A replacement means moving the code currently at oldAddr to the newAddr location and pre-setting the specified slot values. This replacement is used only for the isOperationReady simulation and does not apply to the simulation of the operation itself. It is useful for handling operations that must be called from a specific contract address or that depend on specific storage values (for example, the EntryPoint in ERC-4337). An endorser may also propose its own address as a replacement target, in which case the bundler must use the substituted endorser address when calling isOperationReady.

Fee Calculation Method

The endorser must guarantee that the operation repays tx.origin at least the gas it used. The payment is calculated as gasUnits = op.fixedGas + Min(gasUsed, op.gasLimit), feePerGas = Min(op.maxFeePerGas, block.baseFee + op.priorityFeePerGas), expectedRepayment = (gasUnits * feePerGas * op.feeScalingFactor) / op.feeNormalizationFactor. fixedGas reflects fixed costs outside of on-chain execution, such as calldata cost, and reduces the payment accordingly if an internal call fails and execution finishes cheaper than expected, while still ensuring the bundler is compensated. If feeToken is address(0), payment is made in the native currency, in which case feeScalingFactor and feeNormalizationFactor must be 1. The actual payment amount may exceed this expected value.

Violation Detection and Endorser Blocking

Endorser violations are defined as three cases: declaring readiness but paying less than the agreed fee at execution time, declaring readiness but having the top-level call fail, and flipping readiness from true to false with no change in dependencies. If the operation fails or the payment is insufficient in the final simulation right before block inclusion, the bundler must block that endorser and discard all operations associated with the blocked endorser from the mempool. Endorsers are recommended to register by burning ETH into a registry; since slashing cannot be proven on-chain, the burned ETH remains permanently locked, and blocking remains a virtual event that mempool operators simply choose to honor.

Untrusted Context and Automatic Dependency Tracking

When an endorser cannot fully verify an operation but can infer that a particular code path is safe, it can mark that section as an untrusted context using the UntrustedStarted and UntrustedEnded events. Balances, code, nonces, and storage slots accessed within this section are automatically added as dependencies, and a table defines which dependencies to add for opcodes such as BALANCE, SLOAD, and TIMESTAMP. Only events emitted by the top-level endorser are valid, and nesting is allowed, so the bundler considers the context ended once the counts of the two events become equal. If hasUntrustedContext is false, these events are ignored. Because this can increase dependencies and cause more frequent re-evaluation, it is recommended to use it only when truly necessary.

Bundler Reception Checks and Mempool Rules

A bundler that receives an operation must check that endorserGasLimit is at most MAX_ENDORSER_GAS, that the endorser is registered, has burned at least MIN_ENDORSER_BURN, and is not blocked, that fixedGas covers the submission cost, that gasLimit is at least the cost of a CALL with value, and that the feeToken and conversion factors are acceptable. If an operation with the same dependency set and the same endorser is already in the mempool, the new operation's maxFeePerGas and priorityFeePerGas must be 12% higher to replace it. As optional rules, the number of dependencies can be limited by MAX_OPERATION_DEPENDENCIES and the number of re-evaluations by MAX_OPERATION_REEVALS. There is no limit on the number of times an operation can be executed, so it can remain in the mempool even after inclusion as long as readiness is true.

A Proposal in Draft Stage

This proposal was created on June 29, 2022, and its status is Draft. Since the content may change going forward, it is advisable to check the latest original text before implementing it.

Things to watch out for

Original ERC · ← ERCs