Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
ERC-7679 proposes a common interface for the account-specific parts of building an ERC-4337 UserOperation. A caller can use the interface across account implementations without writing separate encoding logic for each one.
This article explains and expands on the proposal below.
I also cover other Ethereum improvement proposals.
Overview
ERC-4337 smart accounts encode signatures, nonces, and calldata in different ways. That makes it difficult for dapps, wallets, and account abstraction tools to interact with a particular account without its SDK. Vendor lock-in can make these accounts harder to adopt.
ERC-7679 proposes a standard way to expose account-specific encoding logic on-chain. A builder uses view methods to derive the right nonce and calldata and to format the signature as the account expects.
For background on ERC-4337, see the following articles.
[ERC-4337] Implementing account abstraction without changing the protocol
Motivation
Building an ERC-4337 UserOperation requires knowledge of the target account implementation because each implementation can encode its nonce, calldata, and signature differently.
Example
- One account might use an
executeFoofunction. - Another might use an
executeBarfunction.
The calldata differs even when the intended operation is the same.
What makes submitting a UserOp difficult
- Identify which smart account implementation the UserOp targets.
- Encode the signature, nonce, and calldata as that implementation expects, or use an SDK that does it for that account.
Fragmentation
Many dapps, wallets, and account abstraction tools depend on specific account implementations. That increases vendor lock-in and makes different implementations harder to use together.
Specification
UserOperation Builder
A smart account implementation that conforms to this proposal must implement the following interface.
The IUserOperationBuilder interface
struct Execution {
address target;
uint256 value;
bytes callData;
}
interface IUserOperationBuilder {
/**
* @dev Returns the ERC-4337 EntryPoint that the account implementation
* supports.
*/
function entryPoint() external view returns (address);
/**
* @dev Returns the nonce to use for the UserOp, given the context.
* @param smartAccount is the address of the UserOp sender.
* @param context is the data required for the UserOp builder to
* properly compute the requested field for the UserOp.
*/
function getNonce(
address smartAccount,
bytes calldata context
) external view returns (uint256);
/**
* @dev Returns the calldata for the UserOp, given the context and
* the executions.
* @param smartAccount is the address of the UserOp sender.
* @param executions are (destination, value, callData) tuples that
* the UserOp wants to execute. It's an array so the UserOp can
* batch executions.
* @param context is the data required for the UserOp builder to
* properly compute the requested field for the UserOp.
*/
function getCallData(
address smartAccount,
Execution[] calldata executions,
bytes calldata context
) external view returns (bytes memory);
/**
* @dev Returns a correctly encoded signature, given a UserOp that
* has been correctly filled out except for the signature field.
* @param smartAccount is the address of the UserOp sender.
* @param userOperation is the UserOp. Every field of the UserOp should
* be valid except for the signature field. The "PackedUserOperation"
* struct is as defined in ERC-4337.
* @param context is the data required for the UserOp builder to
* properly compute the requested field for the UserOp.
*/
function formatSignature(
address smartAccount,
PackedUserOperation calldata userOperation,
bytes calldata context
) external view returns (bytes memory signature);
}Execution
struct Execution {
address target;
uint256 value;
bytes callData;
}target- The address to call.
value- The amount of Ether to send.
callData- The calldata for the target function.
entryPoint
function entryPoint() external view returns (address);Returns the address of the ERC-4337 EntryPoint supported by the account implementation.
getNonce
function getNonce(
address smartAccount,
bytes calldata context
) external view returns (uint256);Returns the nonce to use for the UserOp based on the account address and context.
smartAccount- The UserOp sender's address.
context- The data the builder needs to compute the requested field.
getCallData
function getCallData(
address smartAccount,
Execution[] calldata executions,
bytes calldata context
) external view returns (bytes memory);Returns the UserOp's calldata based on the smart account, intended executions, and context.
smartAccount- The UserOp sender's address.
executions- An array of tuples containing the target address, amount to send, and calldata. The array can describe a batch.
context- The data the builder needs to compute the requested field.
formatSignature
function formatSignature(
address smartAccount,
PackedUserOperation calldata userOperation,
bytes calldata context
) external view returns (bytes memory signature);Returns a correctly formatted signature for a UserOp whose other fields are valid.
smartAccount- The UserOp sender's address.
userOperation- The UserOp. Its fields other than the signature must already be valid.
context- The data the builder needs to compute the requested field.
Using a UserOperation Builder
A caller can use the builder to assemble a UserOp as follows.
1. Obtain the builder address and context
Obtain the UserOpBuilder address and context from the account owner. The context is an opaque byte array from the caller's point of view. The builder implementation can use it to determine the correct values for individual fields.
2. Batch the view calls
Batch getNonce and getCallData into a multicall using eth_call. Pass the account address and context to getNonce. Pass the account address, context, and intended executions to getCallData.
3. Assemble the UserOp
Build a UserOp using the returned nonce and calldata. Set provisional gas values, which can be arbitrary or deliberately low. Sign the UserOp hash to obtain a dummy signature for gas estimation.
4. Call formatSignature
Use eth_call to call formatSignature with the UserOp and context. Put the formatted dummy signature in the UserOp and use it for gas estimation.
5. Update the gas values
Replace the provisional gas values with the estimates. The UserOp should now be valid apart from its signature field. Sign its hash and put the raw signature in UserOp.signature.
6. Call formatSignature again
Use eth_call to format the new signature and place the result in the UserOp.
7. Submit the completed UserOp
The UserOp is now signed and correctly formatted. Submit it to the bundler.
Other fields
The UserOp has fields beyond the nonce, calldata, and signature. How the building party obtains those fields depends on the account implementation.
Using the builder with an undeployed account
Building a UserOp before the account is deployed
Modify the workflow when the target account does not yet exist on-chain.
1. Obtain the deployment information
- In addition to the builder address and context, obtain the ERC-4337
factoryandfactoryData. factoryis the contract that deploys the account.factoryDatais the data the factory needs to deploy the account.
2. Use the CounterfactualCall contract
When calling one of the builder's view functions, use eth_call to simulate deploying a CounterfactualCall contract. The helper deploys the account within that simulation and calls the builder. The simulation does not persist the deployment on-chain.
3. Build the UserOp
Include the factory and deployment data when building the UserOp.
How CounterfactualCall works
- Deploy the account if needed.
- The dapp or wallet building the UserOp supplies the ERC-4337 factory and deployment data. The helper uses them to deploy the account for the call and reverts if deployment fails.
- Call the UserOpBuilder.
- Once the account is available, the helper calls the builder and returns the result to the building party.
Additional notes
Context
The context is a byte array containing the information the builder needs to determine the nonce, calldata, or signature encoding. The owner typically creates it using wallet software.
Delegation
An account owner may want to delegate execution to the party building a UserOp. The owner can encode a signature over that party's public key in the context. This signature is called an authorization.
- Encode the authorization.
- The owner signs the building party's public key and includes the authorization in the context.
- Supply the UserOp signature.
- The building party signs with its own private key and supplies the result in the UserOp's signature field.
- Format the signature.
- The builder takes the
authorizationfrom the context and combines it with the building party's signature. The Japanese article labels this stepgetSignature; the interface above exposesformatSignature.
- The builder takes the
- Validate the signature.
- The account recovers the building party's public key from its signature and verifies that the authorization covers that key. It executes the UserOp if validation succeeds.
Dummy signature
A bundler needs a signature when estimating the UserOp's gas through eth_estimateUserOperationGas. The final signature is unavailable at that stage because it depends on the gas values being estimated. A dummy signature breaks that dependency.
Constructing a dummy signature
A dummy signature must exercise the account's validation logic in a way that uses about as much gas as a real signature. There is therefore no single fixed dummy signature for all account implementations.
Compatibility
The proposal targets ERC-4337 accounts using EntryPoint v0.7. EntryPoint v0.6 and older versions use a different UserOperation layout, so IUserOperationBuilder would need to be adapted for those versions.
Implementation
Counterfactual Call Contract
The helper supports calls that depend on an account that has yet to be deployed. Its design draws on ERC-6492, which makes ERC-1271 isValidSignature checks possible for counterfactual contracts.
For background on ERC-6492, see the following article.
[ERC-6492] Verifying signatures for undeployed smart accounts
For background on ERC-1271, see the following article.
[ERC-1271] Verifying signatures with smart contracts
Contract
contract CounterfactualCall {
error CounterfactualDeployFailed(bytes error);
constructor(
address smartAccount,
address create2Factory,
bytes memory factoryData,
address userOpBuilder,
bytes memory userOpBuilderCalldata
) {
// スマートアカウントがデプロイされていない場合、デプロイを試みる
if (address(smartAccount).code.length == 0) {
(bool success, bytes memory ret) = create2Factory.call(factoryData);
// デプロイに失敗した場合はエラーをスロー
if (!success || address(smartAccount).code.length == 0) revert CounterfactualDeployFailed(ret);
}
// userOpBuilderを呼び出し、結果を返す
assembly {
let success := call(gas(), userOpBuilder, 0, add(userOpBuilderCalldata, 0x20), mload(userOpBuilderCalldata), 0, 0)
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
if iszero(success) {
revert(ptr, returndatasize())
}
return(ptr, returndatasize())
}
}
}How the contract works
- Check whether the smart account exists.
- If the address in
smartAccounthas no code, the constructor attempts to deploy it throughcreate2Factory. - A failed deployment triggers
CounterfactualDeployFailed.
- If the address in
- Call the builder.
- The assembly code calls
userOpBuilderwithuserOpBuilderCalldata. It returns the result on success or propagates the revert data on failure.
- The assembly code calls
Calling the helper with ethers and viem
The examples below show how the two libraries can construct a call. They retain the argument order in the source article. For the constructor shown above, the factory address and data come before the builder address and its calldata. Match the encoding to the actual helper bytecode before using either example.
ethers
const nonce = await provider.call({
data: ethers.utils.concat([
counterfactualCallBytecode,
(
new ethers.utils.AbiCoder()).encode(['address','address', 'bytes', 'address','bytes'],
[smartAccount, userOpBuilder, getNonceCallData, factory, factoryData]
)
])
});counterfactualCallBytecode- The helper's bytecode.
smartAccount- The smart account's address.
userOpBuilder- The builder's address.
getNonceCallData- The calldata for
getNonce.
- The calldata for
factory- The factory contract's address.
factoryData- The data passed to the factory.
viem
const nonce = await client.call({
data: encodeDeployData({
abi: parseAbi(['constructor(address, address, bytes, address, bytes)']),
args: [smartAccount, userOpBuilder, getNonceCalldata, factory, factoryData],
bytecode: counterfactualCallBytecode,
})
});encodeDeployData- Encodes deployment data.
parseAbi- Parses the ABI.
counterfactualCallBytecode- The helper's bytecode.
smartAccount- The smart account's address.
userOpBuilder- The builder's address.
getNonceCalldata- The calldata for
getNonce.
- The calldata for
factory- The factory contract's address.
factoryData- The data passed to the factory.
Security considerations
Dummy-signature security
A dummy signature sent for gas estimation could be intercepted. The dummy and final UserOps share a nonce, so the dummy cannot be used once the final operation consumes that nonce. Submitting the final UserOp alone does not consume it.
The proposal recommends signing the dummy UserOp with very low gas values to further reduce risk. If it is disclosed, the signature only applies to that low-gas version.
Low gas limits can cause execution to fail. Low gas fees can delay inclusion.
Citation
Derek Chiang (@derekchiang), Garvit Khatri (@plusminushalf), Fil Makarov (@filmakarov), Kristof Gazso (@kristofgazso), Derek Rein (@arein), Tomas Rocchi (@tomiir), bumblefudge (@bumblefudge), "ERC-7679: UserOperation Builder [DRAFT]," Ethereum Improvement Proposals, no. 7679, April 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7679.
Conclusion
ERC-7679 gives dapps and wallets a common way to obtain the nonce, calldata, and signature encoding an ERC-4337 account expects without using an account-specific builder SDK.
Questions are welcome by direct message.
I also publish elsewhere.



