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.

This article examines ERC7521, a proposal for standardized intents for smart contract wallets that lets users authorize both existing and future intent structures when signing.

This article translates, summarizes, and expands on the specification below.

As of October 15, 2023, ERC7521 was at the Draft stage.

Overview

The proposal introduces a generalized entry point contract that can accommodate new intent standards. Previously, smart contract wallets needed frequent upgrades to support new standards. Under this approach, one entry point contract handles signature validation and delegates the definition and low-level processing of intent data to other contracts selected by the user when signing an intent.

These signed messages are called UserIntent objects. They are shared through various mempool strategies so that maximal extractable value (MEV) searchers can discover and combine them with their own UserIntent objects.

MEV searchers construct an object called an IntentSolution, package it into a transaction, and make a handleIntents call to a designated contract. The transaction then travels through ordinary MEV channels until it is included in a block.

Intents

Intent standards establish rules for expressing the intended actions or operations on a blockchain or within a smart contract. They specify the information and parameters that users must provide to perform particular tasks in blockchain-based applications and platforms.

For example, an intent standard for a cryptocurrency transaction might define the following information.

  1. Transfer amount
    • Specifies how much cryptocurrency the user wants to transfer.
  2. Recipient address
    • Specifies the cryptocurrency address of the recipient.
  3. Transaction fee
    • Specifies the fee associated with processing the transaction.

These details establish the purpose of the transaction and provide smart contracts and blockchain nodes with the information needed to process it correctly.

Standardizing the method and format for expressing these details helps maintain compatibility between applications and platforms. Intent standards make desired blockchain operations explicit and facilitate interaction between different systems.

Motivation

See also ERC4337: Account Abstraction Using an Entry Point Contract.

For more information about ERC4337, see the following articles.

https://mirror.xyz/0xcE77b9fCd390847627c84359fC1Bc02fC78f0e58/-qoixMc413uT4FFM61uhXYUiL05Hw-wahq9hV_JtjJs

[ERC4337] How account abstraction works without protocol changes

ERC7521 builds on the entry point contract concept to provide future smart contract wallets with a flexible interface for supporting new intent standards. Its main objectives are as follows.

Enabling intents for users

Allow users to specify desired actions or intents through their smart contract wallets. This gives users control over the actions their wallets execute.

Decentralization

Allow any MEV searcher to participate in resolving signed intents, avoiding centralized control of the process and enabling cooperation among many participants.

Defining custom intent standards

Allow developers of new intent standards to add their own standards so that users can select them when signing. This enables customized intents.

Compatibility with future intent standards

Define an intent standard interface that exposes information about the current execution context, allowing it to accommodate future standards.

Minimizing gas costs

Integrate some essential intent-processing logic into the entry point contract to optimize gas efficiency for common use cases.

Improving the user experience

Allow users to adopt new intent standards without upgrading their smart contract wallets, making complex combinations of intents easier to use.

The proposal aims to streamline the management of intents in smart contract wallets and on the blockchain while improving flexibility and convenience for users and developers.

Specification

The following fields describe the intent information that a user wants to provide through a smart contract wallet.

Field Type Description
standard bytes32 Identifier of the intent standard.
sender address Address of the wallet performing the operation.
nonce uint256 Replay-protection parameter.
timestamp uint256 Time validity parameter.
intentData bytes[] Data defined by the intent standard, split into segments for execution.
signature bytes Data passed to the wallet along with the nonce during validation.

Each field specifies information about an intent or its execution, allowing users to express a particular intent through their wallets.

The intentData parameter is an array of arbitrary byte strings defined by the intent standard. Each element is called an intent segment.

Users submit their UserIntent objects to a mempool strategy appropriate for the intent standard. Specialized MEV searchers discover these intents, determine how they can be combined with others, including their own, and construct an ABI-encoded IntentSolution struct.

Users submit UserIntent objects containing intent data to the relevant protocol. MEV searchers discover and combine them into an encoded IntentSolution.

This enables interactions between smart contracts and protocols and allows different intents to be executed together.

Field Type Description
timestamp uint256 Time at which the intents are intended to be evaluated.
intents UserIntent[] List of intents to execute.
order uint256[] Execution order of the included intents.

A solver then constructs a solution transaction containing the IntentSolution object and submits it to the published global entry point contract in one handleIntents call.

Solver

A solver is an algorithm or program designed to solve a particular problem. Solvers generally analyze a problem and seek an optimal solution. They are used in mathematics, computer science, engineering, artificial intelligence, operations research, and other fields.

Examples include the following.

  • Optimization
    • Finding solutions such as optimal resource allocation or minimizing costs.
  • Puzzles
    • Solving logic problems, including Sudoku, crossword puzzles, and knapsack problems.
  • Games
    • Choosing AI strategies in board games such as chess and Go, as well as video games.
  • Financial modeling
    • Supporting risk analysis, portfolio optimization, and pricing models.
  • Simulation
    • Supporting simulation-based research and forecasting, including physical simulations, traffic models, and weather prediction.

The word solver can refer to a particular program or algorithm depending on context. Solvers are widely used to tackle complex problems efficiently and identify suitable solutions.

The core interface of the global entry point contract is as follows.

javascript
function handleIntents
    (IntentSolution calldata solution)
    external;

function simulateHandleIntents
    (IntentSolution calldata solution, address target, bytes calldata targetCallData)
    external;

function simulateValidation
    (UserIntent calldata intent)
    external;

function registerIntentStandard
    (IIntentStandard intentStandard)
    external returns (bytes32);

function verifyExecutingIntentForStandard
    (IIntentStandard intentStandard)
    external returns (bool);

error ValidationResult
    (bool sigFailed, uint48 validAfter, uint48 validUntil);

error ExecutionResult
    (bool success, bool targetSuccess, bytes targetResult);

The core interface required for an intent standard is shown below.

javascript
function validateUserIntent
    (UserIntent calldata intent)
    external;

function executeUserIntent
    (IntentSolution calldata solution, uint256 executionIndex, uint256 segmentIndex, bytes memory context)
    external returns (bytes memory);

function isIntentStandardForEntryPoint
    (IEntryPoint entryPoint)
    external returns (bool);

The wallet requires the following core interface.

javascript
function validateUserIntent
    (UserIntent calldata intent, bytes32 intentHash)
    external returns (uint256);

function generalizedIntentDelegateCall
    (bytes memory data)
    external returns (bool);

Required entry point contract functionality

The entry point's handleIntents function must execute two loops: a validation loop and an execution loop.

During the validation loop, the handleIntents call must perform the following steps for each UserIntent.

  1. Validate the timestamp of the IntentSolution.
    • Check that it equals block.timestamp or falls within the permitted earlier time range.
  2. Call the wallet's validateUserIntent function with the UserIntent and its intent hash.
    • The wallet must verify the intent signature.
    • If the call fails, handleIntents must at least skip execution of that intent and may revert the entire call.
  3. Call validateUserIntent on the intent standard specified by the UserIntent.
    • Pass the UserIntent and check that its intentData can be parsed in the format expected by the standard.
    • If the call fails, handleIntents must at least skip that intent and may revert the entire call.

During the execution loop, handleIntents must perform the following steps for every segment of each UserIntent's intentData byte-string array.

  1. Call executeUserIntent on the standard specified by the UserIntent.
    • The call includes the entire IntentSolution, the current execution index (how many times the function has previously been called during the solution's execution for any standard or intent), the segment index within the intentData array, and context data.
    • The function returns arbitrary bytes that must be retained for that intent.
    • Pass those bytes into the next executeUserIntent call for the same intent.
  2. The intent standard decides how to parse each intentData segment and use the context data that persists during intent execution.

The segments of an individual UserIntent must always execute in their original intentData order. However, the order in which segments from different UserIntent objects execute can be specified using the IntentSolution's order parameter.

For example, an order array of [1,1,0,1] executes the second intent twice (its first and second segments), then executes the first intent (its first segment), and then executes the second intent a third time (its third segment).

If no order is specified or some segments remain unprocessed after the order array has been exhausted, the default order is used. The default order repeatedly loops from the first intent to the last until every segment of every intent has executed.

If the order array directs the entry point to execute an intent whose segments have all been processed, that executeUserIntent call is skipped and execution continues.

Before accepting a UserIntent, solvers must use an RPC method to call the entry point's simulateValidation function locally. This verifies the signature and data format.

Registering a new entry point intent standard

The entry point's registerIntentStandard function provides a process for registering new intent standard contracts without permission.

During registration, the entry point checks that the contract being registered is appropriate. It calls isIntentStandardForEntryPoint on the intent standard contract, supplying the entry point address.

The intent standard contract can verify that address and return true or false. If it returns true, the entry point registers the intent standard and assigns a unique standard ID. This ID is specific to the intent standard contract, entry point contract, and chain ID.

Extension: A default intent standard

This extension adds support for a default intent standard to the entry point logic, allowing solvers to execute basic operations in a gas-efficient way.

The default standard is registered with its own standard ID when the entry point is created. Its validateUserIntent and executeUserIntent functions are provided within the entry point's code, reducing external calls.

Under this standard, intentData is used as calldata for the intent sender. Solvers can therefore perform a list of basic operations from their own wallets more efficiently.

Using the default intent standard can optimize wallet operations and reduce transaction gas costs.

Intent standard behavior during execution

An intent standard's executeUserIntent function is designed to be flexible and general-purpose, supporting various future use cases.

It has broad access to data, including the complete IntentSolution, so it can implement logic that may become useful in the future.

Each intent standard contract is expected to parse the UserIntent's intentData and use it to verify the constraints associated with that standard or carry out the relevant actions.

It can also use the context data returned at the end of executeUserIntent. The entry point retains that context and passes it as a parameter the next time executeUserIntent is called for the same intent.

This lets the standard inspect other intents and retain data across segment executions within the solution.

One possible use case is a standard that monitors state changes while an intent is being executed, releases certain tokens, and expects to receive other tokens in return.

Intent standards are flexible enough to support many different kinds of intent execution and provide several ways to customize their behavior.

Smart contract wallet behavior during intent execution

A smart contract wallet is not expected to perform additional operations directly at the entry point's request during intent execution. However, an intent standard may require the wallet to perform certain actions.

In that case, the wallet uses its generalizedIntentDelegateCall function. Given specified calldata, the function performs a delegatecall to the calling intent standard contract.

A delegatecall executes another contract's code in the context of the calling wallet, including its storage. The original article described this as the external contract's context; the EVM uses the caller's context instead.

Before executing the delegatecall, the wallet must ensure that the entry point is trusted and verify two conditions.

  1. The msg.sender of the wallet's generalizedIntentDelegateCall function is the intent standard contract whose executeUserIntent function the entry point is currently calling.
  2. The wallet itself is the sender of the UserIntent for which the entry point is currently calling executeUserIntent.

If both conditions are satisfied, the wallet can execute the delegatecall and perform the specified action. This allows intent standards to perform additional operations through smart contract wallets.

Intent validation

The process for validating a UserIntent is as follows.

  1. The solver makes a local call to simulateValidation(intent) on the entry point.
    • This simulates and validates the intent without submitting a transaction.
  2. On successful simulation, simulateValidation reports a ValidationResult.
    • The solver examines this result to determine whether the intent passes validation, including the signature and validity period.
    • The successful simulation result is encoded as a custom error; it does not mean that every possible intent passes validation.
  3. The solver also observes the execution trace.
    • This means examining how the function executes without submitting an actual transaction.
    • The solver checks that the trace does not contain prohibited opcodes.
    • If a prohibited opcode executes, the solver rejects the intent.

The process allows the solver to validate the intent through the entry point before accepting it.

The entry point reports the validation result through the simulation interface, and the solver traces execution to check that the validation rules have been followed.

Prohibited opcodes

Certain opcodes are prohibited at an execution depth greater than 2. The restrictions apply when executing wallets, intent standards, or other contracts called by them.

The prohibited opcodes are as follows.

  • GASPRICE
  • GASLIMIT
  • DIFFICULTY
  • TIMESTAMP
  • BASEFEE
  • BLOCKHASH
  • NUMBER
  • SELFBALANCE
  • BALANCE
  • ORIGIN
  • GAS

The GAS opcode is permitted only when immediately followed by CALL, DELEGATECALL, CALLCODE, or STATICCALL.

These opcodes are restricted during validation and simulation, not actual execution. Their outputs can differ between simulation and on-chain execution. Calls that rely on them during validation may therefore behave differently when executed later on-chain.

At depths greater than 2, certain opcodes are prohibited during validation simulation but remain unrestricted during actual execution because their results can differ between the two contexts.

The GAS opcode is exceptionally allowed when immediately followed by CALL, DELEGATECALL, CALLCODE, or STATICCALL.

Simulation

Simulating the execution of an IntentSolution follows these steps.

  1. The solver makes a local call to simulateHandleIntents(solution) on the entry point.
    • The function is called without committing a transaction, simulating operations that would take place on the blockchain.
  2. On successful completion of the simulation, simulateHandleIntents reports an ExecutionResult custom error.
    • The solver examines the result to determine whether the IntentSolution executes successfully.
    • Other errors or a failed execution result can indicate problems with the solution.
  3. The solver can optionally provide targetCallData.
    • At the end of the simulation, the entry point uses this calldata to call the specified target contract.
    • This call is performed for final analysis, and its result is returned through the ExecutionResult error.
    • It allows the solver to simulate the solution's behavior and inspect the final result before executing it on-chain.

Simulating and validating an IntentSolution before submitting it to the blockchain improves the ability to identify errors and other problems before an actual transaction is sent.

Additional considerations

A major challenge for generalized intent standards is adapting to evolving intents. Users need to express their intentions without continually upgrading their smart contract wallets.

Under the proposal, wallets are expected to provide validateUserIntent. The function receives an intent and verifies its signature. The trusted entry point uses this function for signature validation before forwarding processing to the intent standard contract specified in the intent.

The reproduced interface takes a UserIntent and its hash; the original explanation uses the term UserOperation here, which belongs to the related account abstraction architecture.

Wallets are also expected to provide generalizedIntentDelegateCall. When an intent standard requests actions, the wallet can call verifyExecutingIntentForStandard on the entry point to verify the execution context before performing those actions.

This entry point-based approach separates validation from intent execution and avoids requiring continual wallet upgrades merely to support the latest intent structures.

In an alternative design, developers of new intent standards would need to persuade wallet software developers to support their standards. Here, users select the core definition of the intent when signing, providing greater flexibility.

Solvers

Solvers fulfill users' intents while also pursuing their own MEV. They help users carry out desired actions and transactions and perform the necessary on-chain operations, such as submitting transactions and paying gas fees.

Solvers seek to execute users' intents in an effective way while extracting MEV. They act as on-chain transaction originators, sending transactions and paying associated gas fees on behalf of ordinary users.

Solvers use gossip networks and solution algorithms to determine how to process intents. Each standard may define its own relevant gossip network and algorithms, which solvers use to find appropriate solutions.

Solvers fulfill user intents while pursuing their own MEV. They carry out on-chain processing and help execute the operations that users intend.

Upgrading the entry point

Wallets are recommended to operate as DELEGATECALL forwarding contracts. This can improve gas efficiency and enable wallet upgrades.

The entry point address is expected to be hardcoded in the wallet implementation for efficient gas usage.

When a new entry point is introduced, whether to add features, improve gas efficiency, or fix important security bugs, users can replace the wallet's implementation address with a new implementation pointing to the new entry point.

This can be performed through a self-call, allowing users to upgrade their own wallets.

During the upgrade process, intent standard contracts may also need to be redeployed for and registered with the new entry point. This allows the wallet and its associated standards to follow the same upgrade process.

Upgrading the entry point is a mechanism for improving wallet gas efficiency and flexibility. When a new entry point is needed, users can upgrade their wallets to implementations that reference it, and related intent standards may also need to be updated.

Upgrading intent standards

Intent standards are not hardcoded into wallets, so users do not need to take special actions to adopt newly registered intent standards. They only need to sign an intent using the new standard.

Because intent standards are not fixed in the wallet code, users do not need to perform additional upgrade steps to use new standards. They can adopt a standard simply by signing an intent that specifies it.

Backward compatibility

The ERC does not change Ethereum's consensus layer and therefore introduces no protocol-level backward compatibility issues.

However, integrating it with existing smart contract wallets presents some challenges. If a wallet already supports ERC4337, implementing validateUserIntent is similar to implementing validateUserOp, but users must upgrade their wallets.

This ERC does not change the fundamental operation of Ethereum. Nevertheless, integrating it with existing smart contract wallets, including those that already support ERC4337, requires a wallet upgrade to implement validateUserIntent and adopt the new functionality.

Reference implementation

The reference implementation is available in the following GitHub repository.

Security considerations

The entry point contract acts as a central point of trust for all wallets supporting ERC7521, so it requires rigorous auditing and formal verification.

The architecture substantially reduces the logic individual wallets need to implement, potentially reducing the overall auditing and formal verification burden across the ecosystem.

Wallets principally need to verify validateUserIntent and its signature-checking and nonce-incrementing logic, and use verifyExecutingIntentForStandard on the entry point to validate calls to generalizedIntentDelegateCall.

However, the concentration of security risk in the entry point makes it essential to verify that the contract is robust.

Verification includes the following primary requirement, excluding additional requirements for protecting solvers and intent-standard infrastructure.

  1. Protection against arbitrary hijacking
    • The entry point may return true from verifyExecutingIntentForStandard only if it has successfully verified a UserIntent's signature and is currently calling executeUserIntent on the standard specified in a UserIntent whose sender matches msg.sender.

Intent standard contracts that users interact with also require rigorous auditing and formal verification.

Citation

Stephen Monn (@pixelcircuits), Bikem Bengisu (@supiket), "ERC-7521: General Intents for Smart Contract Wallets [DRAFT]," Ethereum Improvement Proposals, no. 7521, September 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7521.

Conclusion

This article examined ERC7521, which proposes standardized intents for smart contract wallets and enables users to authorize existing and future intent structures when signing.

If you have questions, feel free to contact me on Twitter.

Twitter @cardene777