Skip to main content

Try it Live

Run Authorization examples in the interactive playground
Conceptual Guide - For API reference and method documentation, see Authorization API.
EIP-7702 authorizations enable Externally Owned Accounts (EOAs) to temporarily delegate code execution to smart contracts. This guide teaches authorization fundamentals using Tevm.

What is EIP-7702 Authorization?

An authorization is a signed message allowing an EOA to temporarily set its code pointer to a smart contract’s code for a single transaction. After the transaction, the EOA reverts to its normal state. Key Characteristics:
  • Temporary - Delegation lasts only one transaction
  • Signed - EOA owner must explicitly sign authorization
  • Per-transaction - Included in transaction’s authorization list
  • Non-invasive - EOA retains original balance, nonce, storage

Why EIP-7702 Exists

The Account Abstraction Problem

Traditional EOAs have limitations:
  • Can’t batch operations (need multiple transactions)
  • Can’t sponsor gas (user always pays)
  • Can’t implement custom validation logic
  • Can’t recover if keys are lost
Contract wallets solve these but require:
  • Migrating funds to new contract address
  • Losing original EOA identity
  • CREATE2 deployment complexity
EIP-7702 enables account abstraction without migration - your EOA gains smart contract capabilities on demand.

Use Cases

  1. Sponsored Transactions - Relayer pays gas, user signs authorization
  2. Batch Operations - Multiple token approvals, swaps, transfers in one transaction
  3. Social Recovery - Guardian-based recovery without moving funds
  4. Session Keys - Temporary signing keys for games, dApps
  5. Custom Validation - Multi-sig, time locks, spending limits

Authorization Structure

An authorization contains 6 fields:

Field Details

chainId - Prevents cross-chain replay attacks. Authorization signed for mainnet (1) is invalid on Optimism (10). address - The smart contract that will execute in your EOA’s context. Choose trusted contracts only. nonce - Your EOA’s current nonce. Prevents replaying old authorizations. yParity, r, s - secp256k1 signature components proving you authorized this delegation.

Delegation Mechanics

Before Authorization

During Transaction with Authorization

Execution Context:
  • Calls to EOA address execute delegated contract’s code
  • msg.sender in delegated contract is the transaction sender
  • address(this) is the EOA address
  • Contract reads/writes its own storage (NOT EOA’s storage)

After Transaction

Delegation is removed. EOA returns to normal state.

Authorization Lifecycle

1. Create Unsigned Authorization

Define what to delegate and where:

2. Sign Authorization

EOA owner signs with their private key:
What Happens:
  1. RLP-encodes [chainId, address, nonce]
  2. Prepends EIP-7702 magic byte (0x05)
  3. Keccak256 hashes the result
  4. Signs hash with secp256k1
  5. Returns authorization with signature fields

3. Include in Transaction

Authorization list is added to EIP-7702 transaction:

4. Processing at Execution

When transaction executes:
  1. Validate - Check signature, nonce, chain ID
  2. Recover Authority - Extract EOA address from signature
  3. Set Code Delegation - Point authority’s code to delegated address
  4. Deduct Gas - Charge authorization processing costs
  5. Execute Transaction - Run transaction with delegated code active
  6. Revert Delegation - Remove code pointer after transaction

Complete Example: Sponsored Transaction

User wants to swap tokens but has no ETH for gas. Relayer sponsors the transaction.

Step 1: User Creates Authorization

Step 2: Relayer Builds Transaction

Step 3: Execution Flow

Step 4: Verify Authority

Relayer can verify who authorized the delegation:

Security Considerations

What Can Be Delegated

Safe to delegate:
  • Code execution logic
  • Transaction batching
  • Gas payment
  • Custom validation rules
Cannot be delegated:
  • Private keys (always remain with EOA owner)
  • Existing ETH balance (stays in EOA)
  • Existing storage (remains unchanged)
  • Permanent account state

Authority vs Sender

Understand the difference:
Authority - EOA that signed authorization (owns assets) Sender - Address that sent transaction (pays gas)

Signature Validation

Always validate before processing:

Nonce Management

Nonces prevent replay attacks:

Chain ID Validation

Prevent cross-chain replay:

Delegated Contract Trust

Only delegate to trusted contracts:
Why this matters: Delegated contract executes with full access to authority’s assets for that transaction.

Gas Implications

Authorization Processing Costs

Each authorization costs gas to process:

Multiple Authorizations

Transaction can include multiple authorizations:

Gas Optimization Tips

  1. Reuse existing contracts - Avoid empty account cost (25k gas)
  2. Minimize authorization count - Each costs 12.5k gas minimum
  3. Batch operations - Use one authorization for multiple actions
  4. Cache validation - Don’t validate same authorization multiple times

Visual Flow Diagrams

Authorization Creation Flow

Transaction Execution Flow

Signing Hash Calculation

Understanding how the signing hash is computed:
Process:
  1. RLP Encode - [chainId, address, nonce]
  2. Prepend Magic Byte - 0x05 || rlpEncoded
  3. Keccak256 Hash
  4. Result - 32-byte signing hash
This hash is what gets signed with secp256k1 to produce (yParity, r, s).

Authority Recovery

Extract the EOA address that signed an authorization:
How it works:
  1. Recalculate signing hash from (chainId, address, nonce)
  2. Use ecrecover with (hash, yParity, r, s) to extract public key
  3. Hash public key with keccak256 and take last 20 bytes
  4. Result is the EOA address (authority)

Batch Processing

Process multiple authorizations efficiently:

Comparison: Traditional vs EIP-7702

Scenario: User Wants to Swap 3 Tokens

Traditional EOA:
EIP-7702:
Benefits:
  • Fewer transactions (1 vs 4)
  • Better UX (no gas for user)
  • Atomic execution (all or nothing)
  • Lower total gas cost

Resources

Specifications

Next Steps