ERC 7702
EIP-7702 is a proposal aimed at enhancing Ethereum's account abstraction by allowing Externally Owned Accounts (EOAs) to temporarily function as smart contract accounts. This capability enables EOAs to have both code and storage, unlocking features such as transaction batching, gas sponsorship, and delegated actions.
How It Works
EIP-7702 introduces a new transaction type called the "set code transaction," which allows an EOA to temporarily adopt the code of an existing smart contract. The EOA owner signs an authorization that specifies the desired contract code, and this authorization can be submitted by anyone as part of the new transaction type. The code remains valid until replaced by another authorization, and the authorization can be chain-specific or applicable across multiple chains.
A sample transaction payload in EIP-7702 is structured as follows:
In this structure, the contract_code
is added to the signing address before the transaction begins and removed after it ends. This allows the EOA to temporarily adopt the functionality of the specified contract code during the transaction's execution.
Use Cases
Transaction Batching: EOAs can bundle multiple operations into a single transaction, reducing costs and improving efficiency.
Gas Sponsorship: Third parties can sponsor gas fees for EOAs, enabling users to interact with the blockchain without holding Ether.
Delegated Actions: EOAs can grant limited permissions to other addresses to act on their behalf, facilitating more flexible account management.
Architecture Diagram
While a specific architecture diagram is not provided in the sources, the following conceptual diagram illustrates the process:
Coding Example
Below is a simplified example demonstrating how an EOA can temporarily adopt smart contract functionality using EIP-7702. In this scenario, the EOA sets its code to a simple contract that allows it to execute a specific function during the transaction.
Define the Smart Contract Code
Sign the Authorization
The EOA owner signs an authorization that specifies the contract code (TemporaryContract
) to be adopted during the transaction.
Submit the Set Code Transaction
The signed authorization is submitted as part of the set code transaction, temporarily assigning the TemporaryContract
code to the EOA.
Execute the Desired Action
With the TemporaryContract
code assigned, the EOA can now call the executeAction
function within the same transaction.
This process allows the EOA to temporarily function as a smart contract, enabling more complex interactions within a single transaction.
Security Considerations
Implementing EIP-7702 requires careful attention to security, particularly in the following areas:
Secure Delegation: Delegated contracts should implement replay protection mechanisms, such as nonces, to prevent unauthorized reuse of signatures.
Transaction Propagation: Allowing EOAs to behave as smart contracts introduces challenges in transaction propagation. Clients should be designed to handle scenarios where multiple transactions from the same EOA may become invalidated due to changes in delegation.
Storage Management: Changing an account's delegation is a security-critical operation. Developers must ensure that storage layouts are managed carefully to avoid accidental collisions during migrations from one delegate contract to another.
For a comprehensive overview of security considerations, refer to the EIP-7702 proposal.
EIP-7702 represents a significant advancement in Ethereum's account abstraction efforts, providing EOAs with enhanced capabilities to interact with the blockchain more flexibly and efficiently.
Last updated
Was this helpful?