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 EIP7702, a proposal to provide functionality similar to EIP3074 while facilitating a future transition to account abstraction.

The following material is translated, summarized, and supplemented with explanations. This article describes the original May 2024 proposal at the linked revision, not the final specification activated on Ethereum.

I have also covered various other EIPs.

For related standards, see the following articles on EIP7702.

https://mirror.xyz/0xcE77b9fCd390847627c84359fC1Bc02fC78f0e58/HaPTTeXZeXRG3K5JfXesmKet9eKTbcFUixW6IaMvt4c

Overview

This proposal introduces a transaction type with a contract_code field and signatures, turning signing accounts (which need not be tx.origin) into smart contract wallets for the duration of a transaction.

The proposal aims to provide functionality similar to EIP3074. EIP3074 introduces the AUTH and AUTHCALL opcodes, allowing EOAs to temporarily delegate control to a smart contract.

For more on EIP3074, see the following article.

[EIP3074] Delegating EOA Control to Contracts With Two New Opcodes

https://mirror.xyz/0xcE77b9fCd390847627c84359fC1Bc02fC78f0e58/HaPTTeXZeXRG3K5JfXesmKet9eKTbcFUixW6IaMvt4c

The new transaction type allows users to access smart contract functionality while continuing to use ordinary EOAs. This is expected to extend wallet capabilities and enable more advanced and flexible transactions.

Motivation

The motivation is to improve application usability and security through short-term improvements to externally owned accounts (EOAs). The proposal identifies three applications in particular.

Batching

Multiple operations from the same user can be executed in a single transaction. Examples include ERC20 approve and transfer operations. Although approve and transfer normally require separate transactions, they can be executed together in one transaction.

Gas Sponsorship

Account X pays gas fees for a transaction on behalf of account Y. Account X can also pay in ERC20 tokens instead of the native token. For example, an application operator could cover users' transaction gas fees.

Privilege De-escalation

Users can sign authorizations for subkeys and grant them limited permissions. Examples include permission to spend ERC20 tokens but not ETH, spend at most 1% of the total balance per day, or interact only with particular applications.

EIP3074 can implement all these use cases, but raises forward-compatibility concerns.

It introduces two opcodes, AUTH and AUTHCALL, which would become unnecessary in a world of end-state account abstraction. Ultimately, the expectation is that all users will use smart contract wallets (quantum computers would eventually break the ECDSA used by EOAs).

The ecosystem of invoker contracts would also develop separately from that of smart contract wallets, potentially fragmenting development efforts.

This EIP aims to address both issues while enabling all the use cases of EIP3074. In other words, it extends EOA functionality while facilitating a future transition to account abstraction.

Specification

The proposal defines four parameters: FORK_BLKNUM, TX_TYPE, MAGIC, and PER_CONTRACT__BASE_COST`. Their specific values were still to be determined (TBD) at the time of the proposal.

  • FORK_BLKNUM

    • The block number at which the changes introduced by this EIP take effect.
    • The new transaction type becomes available from this block onward.
    • Its value is determined by the EIP implementation schedule and Ethereum's consensus process.
  • TX_TYPE

    • The number identifying the new transaction type.
    • Ethereum assigns unique numbers to transaction types.
    • For example, ordinary transactions are represented by 0x00, and access-list transactions introduced by EIP2930 use 0x01.
    • The new transaction type receives a number not yet in use.
  • MAGIC

    • A constant used when verifying signatures over contract_code.
    • It is combined with contract_code to compute the message hash for signing.
    • This makes the purpose of the signature explicit and prevents confusion with signatures intended for other purposes.
    • Its value is determined with collision resistance and compatibility with other constants in mind.
  • PER_CONTRACT_CODE_BASE_COST

    • The base cost charged for each contract_code.
    • This cost applies uniformly regardless of the size of contract_code.
    • Its value is determined by balancing network resource consumption against the cost of executing contract_code.

From FORK_BLOCK_NUMBER onward, a new transaction conforming to EIP2718 is introduced. The TransactionType of this transaction is the value specified by TX_TYPE.

For more on EIP2718, see the following article.

[EIP2718] Extending Ethereum Transactions

The new transaction's TransactionPayload uses the following RLP (Recursive Length Prefix) encoding.

text
rlp([chain_id, nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, destination, data, access_list, [[contract_code, y_parity, r, s], ...], signature_y_parity, signature_r, signature_s])

The new transaction type uses RLP (Recursive Length Prefix) to encode a data structure called TransactionPayload.

The components of TransactionPayload are described below.

  • chain_id
    • The chain ID of the Ethereum network on which the transaction executes.
    • This prevents confusion between transactions on different networks.
  • nonce
    • The number of transactions previously sent from the transaction sender's account.
    • This prevents duplicate execution of transactions.
  • max_priority_fee_per_gas
    • The maximum additional gas fee paid to a block producer to increase transaction priority.
    • This allows transaction confirmation speed to be adjusted.
  • max_fee_per_gas
    • The maximum gas price permitted for transaction execution.
    • It is based on the dynamic fee mechanism introduced by EIP1559.
  • gas_limit
    • The maximum amount of gas available for executing the transaction.
    • This limits transaction execution costs.
  • destination
    • The destination address of the transaction.
    • It can be the address of a smart contract called by the transaction or the EOA receiving a payment.
  • data
    • Arbitrary data included in the transaction.
    • It is used for smart contract function calls or message transmission.
  • access_list
    • A list of storage keys and addresses accessed by the transaction.
    • It is based on the access-list feature introduced by EIP2930.
  • [[contract_code, y_parity, r, s], ...]
    • A list of signed contract_code entries.
    • Each contract_code is code for temporarily turning an EOA into a smart contract.
    • y_parity, r, and s are the components of the signature over contract_code.
  • signature_y_parity, signature_r, signature_s
    • The sender's signature over the entire transaction.
    • These fields authenticate the transaction and ensure its integrity.

These components are RLP-encoded into a single TransactionPayload. RLP converts the data structure into a unique byte sequence for efficient transmission and processing across the network.

Using this TransactionPayload, the new transaction type temporarily gives EOAs smart contract functionality, enabling atomic execution of multiple operations and transaction submission on behalf of other accounts.

RLP (Recursive Length Prefix) is a serialization method for encoding arbitrarily nested binary data structures. Ethereum uses it extensively to serialize data structures such as transactions and blocks.

RLP encoding has the following main characteristics.

  • It supports two data types: byte arrays (binary data) and lists (arrays containing other elements).
  • Length information is prefixed to the data so boundaries can be identified during decoding.
  • Recursive structures are supported, allowing lists to contain other lists.

RLP encoding follows these rules.

Byte Arrays

If the length is one byte and the byte is in the range 0x00 to 0x7f, the byte itself is its RLP encoding. If the length is at most 55 bytes, prefix the byte array with 0x80 plus its length. If the length exceeds 55 bytes, prefix it with 0xb7 plus the byte length of the length value, followed by the byte representation of the length and the byte array itself.

Lists

If the total encoded length of the list is at most 55 bytes, prefix the concatenated RLP encodings of its elements with 0xc0 plus that total length. If the total encoded length exceeds 55 bytes, prefix the list with 0xf7 plus the byte length of the total length value, followed by the byte representation of that length and the concatenated RLP encodings of the elements.

Encoding data according to these rules converts complex data structures into unique byte sequences. The original data structure can also be recovered unambiguously from the encoded data.

Because RLP is a simple and efficient serialization method, it has been adopted by Ethereum and other blockchain projects.

The intrinsic cost of this transaction is inherited from EIP2930.

For more on EIP2930, see the following article.

[EIP2930] Introducing a New Transaction Type With Access Lists

Specifically, the cost is 21000 + 16 * non-zero calldata bytes + 4 * zero calldata bytes + 1900 * access list storage key count + 2400 * access list address count. An additional cost of 16 * non-zero calldata bytes + 4 * zero calldata bytes applies to each contract_code, plus PER_CONTRACT__BASE_COSTmultiplied by the length of thecontract_code` array.

The intrinsic cost of the new transaction type is calculated from the following components.

  • Base cost
    • 21000
  • Number of nonzero calldata bytes
    • 16 gas × number of nonzero calldata bytes
  • Number of zero calldata bytes
    • 4 gas × number of zero calldata bytes
  • Number of storage keys in the access list
    • 1900 gas × number of storage keys
  • Number of addresses in the access list
    • 2400 gas × number of addresses
  • Nonzero calldata bytes in each contract_code
    • 16 gas × number of nonzero calldata bytes × number of contract_code entries
  • Zero calldata bytes in each contract_code
    • 4 gas × number of zero calldata bytes × number of contract_code entries
  • Additional cost based on the length of the contract_code array
    • PER_CONTRACT__BASE_COST× length of thecontract_code` array

The sum of these costs determines the intrinsic gas required for the new transaction type.

This formula determines gas costs dynamically according to the transaction size and access-list contents. The additional cost based on the number and size of contract_code entries means gas usage increases with transaction complexity.

At the start of transaction execution, the following steps are performed for each [contract_code, y_parity, r, s] tuple.

  1. Identify the signer
    • Compute the Keccak hash of the concatenation of MAGIC and contract_code.
    • Verify the ECDSA signature using this hash and y_parity, r, and s.
    • If the signature is valid, recover the signer's address (signer).
  2. Verify the signer's contract code
    • Confirm that the contract code currently set at the signer's address is empty.
    • This ensures that the signer's account is an externally owned account (EOA).
  3. Update the signer's contract code
    • Set the contract code at the signer's address to the code specified by contract_code.
    • This temporarily turns the signer's account into a smart contract account.

When transaction execution finishes, each signer's contract code is reset to empty. The temporarily installed smart contract code is removed, and the signer's account returns to being an EOA.

Importantly, the signer of contract_code may differ from the account that actually submits the transaction (tx.origin). This allows one account to execute a transaction on behalf of another.

These steps temporarily give EOAs smart contract functionality. They enable advanced use cases such as atomic execution of multiple operations and submitting transactions on behalf of other accounts. Because the account returns to being an EOA at the end of the transaction, its state is managed accordingly.

The new transaction type is designed to extend EOA capabilities in the short term while preparing for a future transition to account abstraction. It enables the use cases targeted by EIP3074, including atomic execution of multiple operations, transactions on behalf of other accounts, and subkeys with restricted permissions.

Additional Details

This section describes how the new transaction type can accommodate EIP3074 use cases and remain compatible with future account abstraction.

Adapting the EIP3074 workflow to the new design is relatively straightforward. To implement AUTH and AUTHCALL functionality using the new transaction type, the user's wallet contract code must be designed accordingly.

The wallet contract code contains two functions: verify and execute.

The verify Function

verify replaces the AUTH functionality of EIP3074. This function grants permissions to the caller's address (msg.sender). Specifically, it uses TSTORE (transient storage) to store data such as authorized[msg.sender, ...] = True. This records that the caller's address is authorized to perform certain operations.

The execute Function

execute replaces the AUTHCALL functionality of EIP3074. It first uses TLOAD (transient storage reads) to check authorized[msg.sender, ...]. If the caller's address is authorized, the operations in execute are performed. Otherwise, execution is denied.

These functions reproduce EIP3074 AUTH and AUTHCALL functionality using the new transaction type.

The user's wallet contract code can also use a DELEGATECALL forwarder to save gas. DELEGATECALL executes another contract's code in the context of the calling contract. This avoids code duplication and reduces gas costs.

Adapting the EIP-3074 workflow to the new transaction type is therefore relatively straightforward. Implementing verify and execute in wallet contract code and managing permissions with TSTORE and TLOAD provides equivalent functionality.

Regarding forward compatibility with future account abstraction, this EIP is designed to be highly compatible with end-state account abstraction without depending on ERC4337 or RIP7560.

For more on ERC4337, see the following article.

[ERC4337] Implementing Account Abstraction Without Protocol Changes https://mirror.xyz/0xcE77b9fCd390847627c84359fC1Bc02fC78f0e58/HaPTTeXZeXRG3K5JfXesmKet9eKTbcFUixW6IaMvt4c

Specific considerations include the following.

The contract code users sign could literally be existing ERC4337 wallet code. This allows existing wallet implementations to be reused.

The code paths used, meaning sequences of instructions selected according to particular conditions, are expected to remain relevant under future account abstraction.

Account abstraction is the concept of eliminating the distinction between EOAs and contract accounts and representing all accounts through smart contracts. In the future, all Ethereum accounts may be replaced by smart contract wallets.

The proposal is designed so that code paths used by the new transaction type remain applicable in an account system based entirely on smart contract wallets. The logic introduced by these changes may therefore remain useful after account abstraction is achieved.

For example, functions such as verify and execute are general mechanisms for authorization and execution control, and smart contract wallets are likely to need similar functionality. Transient storage operations such as TSTORE and TLOAD may also remain useful after account abstraction.

The proposed code paths are designed with future account abstraction in mind and are expected to remain compatible after migration. This allows Ethereum's account system to evolve gradually while easing the transition for developers and users.

It would be problematic if EOA-based and AA-based systems had completely different, incompatible codebases. Developers would need separate tools and libraries for each system, making development inefficient.

This proposal considers compatibility with future AA systems when introducing the new transaction type. Specifically, it incorporates mechanisms likely to remain useful in AA systems, including functions such as verify and execute and transient storage operations such as TSTORE and TLOAD.

EOA-based and AA-based systems can therefore share part of the same code ecosystem. Developers can use the same tools and libraries to build smart contracts supporting both systems.

Not every workflow will transition seamlessly, however. Some workflows will require adjustments to integrate fully with AA systems. Because AA systems use smart contract-based accounts throughout, some situations will require logic different from that of EOA-based systems.

Such workflows are expected to represent a relatively small subset. Most workflows should migrate smoothly from EOA-based systems to AA-based systems by using the mechanisms introduced here.

If new opcodes (EVM instructions) relying on EOA-specific functionality were added with the new transaction type, those opcodes would become useless in a post-EOA world.

That would make a smooth transition to a post-EOA world difficult. Further opcode changes might be required after introducing the new transaction type. To avoid such issues, this proposal introduces new functionality within the capabilities of the existing Ethereum Virtual Machine (EVM). It adopts general-purpose mechanisms applicable to smart contract-based accounts rather than relying on EOA-specific features. For example, functions such as verify and execute and transient storage operations such as TSTORE and TLOAD are likely to remain useful in both EOA-based and smart contract-based systems.

EOAs can temporarily turn themselves into contracts and be included in ERC4337 bundles, retaining compatibility with the existing EntryPoint. This enables smooth integration with the account abstraction framework. If this were implemented, EIP5003 could be realized simply by adding a flag preventing contract code from being cleared at the end of a transaction.

The proposal provides the functionality of EIP3074 while preparing for a future transition to account abstraction. It makes use of existing workflows while retaining compatibility with the smart contract wallet ecosystem. This is expected to promote the gradual evolution of Ethereum's account model.

Compatibility

This EIP proposes breaking the rule that an account's balance can only decrease through transactions originating from that account. This affects mempool design and other EIPs, such as inclusion lists. However, these issues also apply to other proposals offering similar functionality, including EIP3074.

Breaking the Rule

Under Ethereum's account model at the time of the proposal, an account's balance could decrease only through transactions originating from that account. This EIP allows one account to execute a transaction on behalf of another account. For example, if account A executes a transaction on behalf of account B, B's balance may decrease through a transaction in which B is not directly involved. This breaks the rule that an account's balance can decrease only through transactions originating from that account.

Impact on the Mempool

The mempool temporarily stores transactions received by block producers until they are included in a block. Existing mempool designs assume the rule concerning account balances. Introducing this EIP means account balances may change unexpectedly, complicating mempool management. Mempool designs may need to be revised to handle transaction dependencies and executability appropriately.

Impact on Other EIPs

Inclusion lists are described here as mechanisms for specifying whether an account accepts transactions from another account. Existing inclusion-list designs assume the rule concerning account balances. With this EIP, an account not included in a list may execute a transaction on behalf of another account and change its balance. Inclusion-list designs may therefore also require reconsideration.

Common Issues With Other Proposals

Other proposals allowing transactions on behalf of accounts, including EIP3074, face similar issues. These proposals break the rule concerning account balances, so their impact on mempools and inclusion lists is unavoidable. Addressing these issues requires coordination across the Ethereum protocol.

Security

Like EIP3074, this EIP raises security considerations, particularly concerning which contract_code a user's wallet signs.

Similarities to EIP3074

EIP3074 introduces two new opcodes, AUTH and AUTHCALL, to temporarily delegate control of an EOA to a contract. This EIP aims to provide similar functionality through a new transaction type. Both proposals therefore share security considerations.

Signing contract_code

Under this proposal, a user's wallet signs contract_code to associate that code with the user's account. contract_code is the code executed when the user's account temporarily becomes a smart contract. Signing contract_code therefore authorizes that code to control the user's account.

Risks of Malicious contract_code

If a user signs malicious contract_code, the code may perform unauthorized operations on the user's account. For example, malicious contract_code could steal user funds or execute unauthorized transactions. Wallets should therefore understand contract_code thoroughly and sign only code obtained from trusted sources.

Verifying contract_code

Wallets must verify contract_code thoroughly before signing it. Verification should analyze the behavior of contract_code in detail and identify potential security risks. Wallets should also ensure that appropriate restrictions limit contract_code to the user's intended purposes.

Importance of Trusted Sources

Wallets should obtain contract_code from trusted sources. Trusted sources include smart contract libraries and tools that have been audited and are widely recognized by the community. contract_code from unknown or poorly regarded sources may pose greater security risks and should be avoided.

Under this EIP, a user's wallet authorizes code to control the account by signing contract_code. It is therefore essential for wallets to understand the contents of contract_code and sign only code from trusted sources.

Conclusion

This article covered EIP7702, a proposal to provide functionality similar to EIP3074 while facilitating a future transition to account abstraction. I hope you found it useful.

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

Twitter @cardene777

I also share information on other platforms, so feel free to explore them.

https://chaldene.net/