Ankita.eth
GithubContact
  • About Ankita
  • experience
    • TECHNOLOGIES
    • Frontend
      • Javascript
      • React
      • NextJS
      • HTML & CSS
      • UI Libraries & Frameworks
        • Tailwind CSS
        • Comprehensive Guide to UI Libraries and Frameworks
    • Backend
      • Node.js
      • Express.js
    • Database
      • Mongodb, Mongoose
      • PostgresSQl
      • MySQL
    • Packege Mangers
      • NPM-Node Packege Manager
      • Yarn
      • Yarn 2 (Berry)
      • PNPM
      • BUN
      • Commands cheatsheet
    • API Providers
      • Alchemy
      • Telegram Bot
      • CoinMarket
      • Thirdweb
      • Infura
      • Moralis
    • DevOps/Infrastructure
      • Docker
      • Kubernetes
      • CI/CD
      • Docker Swam
    • Protocols
      • ERCs & EIPs
        • ERC-20
        • ERC-721
        • ERC-1155
        • ERC-4337
        • ERC-6551
        • ERC-777
        • ERC-3643
        • EIP-7702
        • ERC-7715
        • ERC-7739
        • EIP-6780
        • EIP-5792
        • ERC-4626
        • EIP-1559
        • ERC-404
        • ERC-3643
        • ERC-223
    • Web3 Toolkits
      • Foundry
      • Hardhat
      • RemixIDE
    • Messaging/Caching
      • Kafka
      • Redis
      • Sendgrid
    • Blockchain
      • Solana
      • Ethereum
      • Polygon & Zero knowldge Proof
      • Bitcoin
      • Solidity
    • Deployment Platforms
      • AWS
      • Vercel
      • Heroku, Render
      • Domain setup
  • SDKs
    • Google Cloud SDK
    • AWS SDK
    • Firebase SDK
  • EOF EVM Object Format
  • Articles
    • Medium Articles
    • 🌐 My Work
  • 📞 Get in Touch
Powered by GitBook
On this page
  • 📜 EIP-5792: Wallet Contract Interface
  • 🏗️ Architecture
  • 🧠 Core Concepts
  • 🚶 User Flow
  • 💻 Implementation Details
  • 🔑 Key Features

Was this helpful?

  1. experience
  2. Protocols
  3. ERCs & EIPs

EIP-5792

PreviousEIP-6780NextERC-4626

Last updated 8 months ago

Was this helpful?

📜 EIP-5792: Wallet Contract Interface

EIP-5792 introduces a standard interface for wallet contracts in the Ethereum ecosystem. This page provides a comprehensive overview of its architecture, core concepts, user flow, and implementation details.

🏗️ Architecture

The EIP-5792 standard defines a set of interfaces and functionalities for wallet contracts. Here's a high-level overview of the architecture:

🧠 Core Concepts

1. Wallet Contract 👛

A smart contract that implements the EIP-5792 interface, allowing it to act as a programmable wallet with advanced features.

2. Signature Validation ✅

The ability to verify signatures, enabling secure transaction authorization.

3. Transaction Execution 🚀

Methods for executing single and batch transactions, providing flexibility in wallet operations.

4. Nonce Management 🔢

A mechanism to prevent replay attacks and ensure transaction uniqueness.

🚶 User Flow

Here's a typical user flow for interacting with an EIP-5792 wallet contract:

💻 Implementation Details

Wallet Contract Interface

interface IERC5792 {
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
    function executeCall(address to, uint256 value, bytes memory data) external payable returns (bytes memory);
    function executeBatch(address[] memory to, uint256[] memory value, bytes[] memory data) external payable returns (bytes[] memory);
    function nonce() external view returns (uint256);
}

Example Implementation

Here's a basic implementation of an ERC-5792 Wallet Contract:

pragma solidity ^0.8.0;

import "./IERC5792.sol";

contract ERC5792Wallet is IERC5792 {
    address public owner;
    uint256 private _nonce;

    constructor(address _owner) {
        owner = _owner;
    }

    function isValidSignature(bytes32 hash, bytes memory signature) external view override returns (bytes4 magicValue) {
        if (recoverSigner(hash, signature) == owner) {
            return 0x1626ba7e; // EIP-1271 magic value
        }
        return 0xffffffff;
    }

    function executeCall(address to, uint256 value, bytes memory data) external payable override returns (bytes memory) {
        require(msg.sender == owner, "Not authorized");
        _nonce++;
        (bool success, bytes memory result) = to.call{value: value}(data);
        require(success, "Call failed");
        return result;
    }

    function executeBatch(address[] memory to, uint256[] memory value, bytes[] memory data) external payable override returns (bytes[] memory) {
        require(msg.sender == owner, "Not authorized");
        require(to.length == value.length && to.length == data.length, "Array length mismatch");
        _nonce++;
        bytes[] memory results = new bytes[](to.length);
        for (uint256 i = 0; i < to.length; i++) {
            (bool success, bytes memory result) = to[i].call{value: value[i]}(data[i]);
            require(success, "Call failed");
            results[i] = result;
        }
        return results;
    }

    function nonce() external view override returns (uint256) {
        return _nonce;
    }

    function recoverSigner(bytes32 hash, bytes memory signature) internal pure returns (address) {
        require(signature.length == 65, "Invalid signature length");
        bytes32 r;
        bytes32 s;
        uint8 v;
        assembly {
            r := mload(add(signature, 32))
            s := mload(add(signature, 64))
            v := byte(0, mload(add(signature, 96)))
        }
        if (v < 27) v += 27;
        require(v == 27 || v == 28, "Invalid signature 'v' value");
        return ecrecover(hash, v, r, s);
    }
}

🔑 Key Features

  • 🔐 Secure signature validation for transaction authorization

  • 🚀 Flexible execution of single and batch transactions

  • 🔢 Nonce management to prevent replay attacks

  • 🔌 Interoperability with existing Ethereum infrastructure

  • 🧩 Extensibility for custom wallet implementations

EIP-5792 provides a robust framework for creating standardized wallet contracts, enabling developers to build sophisticated and secure wallet solutions. This standard paves the way for more user-friendly and feature-rich blockchain applications while maintaining high levels of security and flexibility.