Skip to content

Complete guide and implementation for revoking EIP-7702 delegations on EVM addresses. Includes code examples, scripts, and documentation.

License

Notifications You must be signed in to change notification settings

KaiJeng613/eip-7702-revoke-delegation

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

EIP-7702 Delegation Revocation Guide

Complete guide and implementation for revoking EIP-7702 delegations on EVM addresses. Includes code examples, scripts, and comprehensive documentation.

License: MIT TypeScript Viem

πŸ“‘ Table of Contents

πŸ” Overview

This repository provides a complete implementation guide for revoking EIP-7702 delegations on any EVM address. EIP-7702 allows Externally Owned Accounts (EOAs) to temporarily behave like smart contracts by delegating their code execution to a contract. This guide shows you how to safely revoke such delegations.

πŸ€– What is EIP-7702?

EIP-7702 ("Set EOA account code for one transaction") is an Ethereum Improvement Proposal that enables EOAs to temporarily delegate their code execution to a smart contract. This provides:

  • βœ… Smart account capabilities for regular wallets
  • βœ… Batch transaction execution
  • βœ… Gasless transactions (via paymasters)
  • βœ… Enhanced security features
  • βœ… Reversible delegation (can be revoked at any time)

Key Features

  • Temporary Delegation: Only active during the transaction
  • Authorization-based: Requires explicit signature from the EOA
  • Revocable: Can be cleared by delegating to zero address
  • Backward Compatible: Works with existing Ethereum infrastructure

πŸ”„ How Revocation Works

The Revocation Mechanism

To revoke an EIP-7702 delegation, you simply delegate to the zero address (0x0000000000000000000000000000000000000000). This clears the delegation and returns your EOA to its normal state.

Step-by-Step Process

  1. Sign Authorization: Create an authorization object with the zero address as the target
  2. Send Transaction: Include the authorization in an EIP-7702 transaction
  3. Confirmation: Once mined, the delegation is cleared
// The key to revocation: delegate to zero address
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';

const authorization = await client.signAuthorization({
  contractAddress: ZERO_ADDRESS, // This revokes the delegation
});

βš™οΈ Prerequisites

Before using this repository, ensure you have:

  • Node.js (v18 or higher)
  • npm or yarn package manager
  • Private key of the EOA you want to revoke delegation from
  • RPC endpoint (e.g., Alchemy, Infura, or public RPC)
  • Basic understanding of Ethereum and smart contracts

πŸ“¦ Installation

  1. Clone the repository:
git clone https://github.com/Babs0022/eip-7702-revoke-delegation.git
cd eip-7702-revoke-delegation
  1. Install dependencies:
npm install
# or
yarn install
  1. Set up environment variables:
cp .env.example .env

πŸ”‘ Configuration

Create a .env file in the root directory with the following variables:

# Your EOA private key (DO NOT COMMIT THIS FILE)
PRIVATE_KEY=your_private_key_here

# RPC endpoint URL
RPC_URL=https://eth.llamarpc.com

# (Optional) For delegation script - contract address to delegate to
DELEGATION_CONTRACT=0x...

⚠️ Security Warning: Never commit your .env file or expose your private key!

πŸš€ Usage

Revoke Delegation

To revoke an existing EIP-7702 delegation:

npm run revoke

This script will:

  1. Load your account from the private key
  2. Sign an authorization to delegate to zero address
  3. Send the transaction to revoke the delegation
  4. Display the transaction hash and confirmation

Establish Delegation

To set up a new delegation (opposite of revocation):

npm run delegate

Note: Make sure to set DELEGATION_CONTRACT in your .env file first.

Check Current Delegation Status

npm run check-delegation

πŸ”Œ Technical Details

Authorization Structure

An EIP-7702 authorization tuple contains:

interface Authorization {
  chainId: bigint;      // Network chain ID
  address: Address;     // Contract address to delegate to (0x0 for revocation)
  nonce: bigint;        // Current nonce of the EOA
  yParity: number;      // Signature recovery bit
  r: Hex;               // Signature r value
  s: Hex;               // Signature s value
}

Transaction Flow

1. EOA signs authorization with address = 0x0
   ↓
2. Transaction includes authorizationList
   ↓
3. EVM processes authorization during transaction
   ↓
4. Delegation is cleared, EOA returns to normal state
   ↓
5. Transaction completes successfully

Code Implementation

The revocation script (scripts/revoke.ts) demonstrates:

  • βœ… Signing authorization with viem
  • βœ… Setting delegation target to zero address
  • βœ… Sending EIP-7702 transaction
  • βœ… Error handling and logging
  • βœ… Transaction confirmation

Gas Considerations

  • Revocation transactions are standard EIP-7702 transactions
  • Gas costs are similar to regular transactions
  • No additional contract interaction required
  • Estimated gas: ~50,000 - 100,000 units

πŸ”’ Security Considerations

Best Practices

  1. πŸ”‘ Private Key Security

    • Never share or commit your private key
    • Use hardware wallets when possible
    • Keep .env in .gitignore
  2. βœ… Verify Transactions

    • Always review transaction details before signing
    • Check the delegation target address
    • Verify the chain ID matches your network
  3. πŸ›‘οΈ Delegation Safety

    • Only delegate to audited contracts
    • Understand what the delegated contract can do
    • Revoke delegations when no longer needed
  4. 🌐 Network Awareness

    • Ensure you're on the correct network
    • Use testnet for experimentation
    • Mainnet delegations involve real assets

Potential Risks

  • Malicious Contracts: Delegating to unaudited contracts can be dangerous
  • Key Compromise: If your private key is stolen, attacker can control delegations
  • Transaction Reverts: Always handle transaction failures gracefully

πŸ“š Resources

Official Documentation

Implementation Examples

Tools & Libraries

Community

πŸ‘₯ Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

⚠️ Disclaimer

This software is provided "as is", without warranty of any kind. Use at your own risk. Always test on testnets before using on mainnet. The authors are not responsible for any losses or damages.

πŸš€ Quick Start

# 1. Clone and install
git clone https://github.com/Babs0022/eip-7702-revoke-delegation.git
cd eip-7702-revoke-delegation
npm install

# 2. Configure environment
cp .env.example .env
# Edit .env with your PRIVATE_KEY and RPC_URL

# 3. Revoke delegation
npm run revoke

πŸ’¬ Support

If you have questions or need help:

  • Open an Issue
  • Check the Resources section
  • Review the code examples in /scripts

Made with ❀️ for the Ethereum community

About

Complete guide and implementation for revoking EIP-7702 delegations on EVM addresses. Includes code examples, scripts, and documentation.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%