ERC-7679 UserOperation builder

Draft · Accounts & wallets · created 2024-04-05

A standard that provides each smart account's distinct signature, nonce, and calldata encoding logic as an on-chain contract, so that a UserOperation for any smart account can be built without an account-specific SDK.

Why it is needed

ERC-4337 smart accounts encode signatures, nonces, and calldata differently depending on the implementation. For example, one account might use an execution function called executeFoo while another uses executeBar, so the calldata differs between the two accounts even for the same call. As a result, sending a UserOperation to a given account requires figuring out which implementation it uses and encoding values accordingly, or using an account-specific SDK. Consequently, most current DApps, wallets, and account abstraction tools are tied to a specific smart account implementation, which leads to ecosystem fragmentation and vendor lock-in and hinders smart account adoption. This standard solves the problem by placing the account-specific encoding logic into an on-chain builder contract.

What to implement

In depth

The IUserOperationBuilder interface

A smart account implementation conforming to the standard MUST provide a builder contract that implements the IUserOperationBuilder interface. The interface consists of four view functions. entryPoint returns the ERC-4337 EntryPoint address the account supports. getNonce takes the account address and a context and returns the nonce. getCallData takes an array of Execution structs (target, value, callData) and a context, and returns calldata appropriate to the account implementation; because it takes an array, executions can be batched. formatSignature takes a PackedUserOperation with everything filled in except the signature field, plus a context, and returns a correctly encoded signature. All are view functions, so the author calls them via eth_call.

The core of the authoring process is two calls to formatSignature

The author first obtains the UserOpBuilder address and context from the account owner. getNonce and getCallData are run together via multicall to obtain the nonce and calldata, and the hash of a UserOperation with arbitrary or very low gas values is signed, after which formatSignature is called to produce a UserOperation containing a dummy signature for gas estimation. Once gas estimation is complete, the gas values are replaced with the estimates, the hash is signed again, and formatSignature is called once more to obtain a fully valid UserOperation. How the remaining fields of the UserOperation are obtained is outside the scope of this document, since nonce, calldata, and signature are the three fields that depend heavily on the account implementation.

Undeployed accounts are handled via CounterfactualCall.

Builders usually need to call the account to get accurate data, but at the time the first UserOperation is sent, the account may not yet be deployed. In this case, the author MAY additionally obtain the factory and factoryData defined in ERC-4337 and look it up by deploying a CounterfactualCall contract inside eth_call. CounterfactualCall deploys the account using factory and factoryData, reverts if deployment fails, and SHOULD call UserOpBuilder and return its return value to the author if deployment succeeds. The UserOperation includes factory and factoryData. This approach was inspired by the mechanism in ERC-6492, which runs isValidSignature against an undeployed contract.

Context enables use cases such as delegation

Context is a byte array containing the data the builder needs to correctly set the nonce, call data, and signature, and is assumed to be constructed by the account owner with help from wallet software. The original text cites delegation as one example use case. The owner places a value signed over the author's public key (an authorization) into the context; the author then creates a signature with their own private key, and the builder pulls the authorization out of context and concatenates it with the author's signature. The account recovers the author's public key from the signature, verifies that this public key was approved by the authorization, and then executes. This allows the author to execute the UserOperation on behalf of the user.

Why a dummy signature is needed

A dummy signature is the signature used when the bundler estimates gas via eth_estimateUserOperationGas. A valid signature depends on the UserOperation's gas values, but those gas values are only determined after estimation finishes, creating a circular dependency; the dummy signature breaks that cycle. However, the dummy signature is not a fixed value usable by any account. It must be constructed to consume roughly the same amount of gas as a real signature, so it depends on the account's verification logic and is therefore implementation-dependent. Because the builder's formatSignature handles this formatting on the author's behalf, the author does not need to know the verification logic.

Based on EntryPoint 0.7; 0.6 requires a struct swap

This ERC is designed to be backward compatible with all ERC-4337 smart accounts based on EntryPoint 0.7. For smart accounts deployed with EntryPoint 0.6, the PackedUserOperation struct in the IUserOperationBuilder interface must be replaced with the corresponding struct from EntryPoint 0.6.

Still a Draft-stage proposal

This document was created on April 5, 2024 and is in Draft status. Its content may change or stall, so it is advisable to check the latest original text before implementing.

Things to watch out for

Original ERC · ← ERCs