Skip to content

Implement smart contract wallet interface for Account Abstraction #29

Description

@ch4r10t33r

Title

Implement smart contract wallet interface for Account Abstraction

Labels

enhancement, account-abstraction, wallet, smart-account

Description

Add interfaces and utilities for interacting with ERC-4337 smart contract accounts (wallets), enabling advanced wallet functionality beyond EOAs.

Requirements

SmartAccount Interface

  • Define SmartAccount trait/interface:
    • getAddress() Address - Get deployed account address
    • getNonce(?key: u256) u256 - Get current nonce for key
    • signUserOperation(userOp: UserOperation) []u8 - Sign UserOp
    • encodeExecute(to: Address, value: u256, data: []u8) []u8 - Encode call
    • encodeBatchExecute(calls: []Call) []u8 - Encode batch calls
    • getInitCode() []u8 - Get account deployment code
    • isDeployed() bool - Check if account is deployed

SimpleAccount Implementation

  • Implement SimpleAccount (ERC-4337 reference implementation):
    • Based on official SimpleAccount.sol
    • Single owner validation
    • Execute and executeBatch support
    • EIP-712 UserOperation signing

Account Factory Support

  • Add AccountFactory interface:
    • getAccountAddress(owner: Address, salt: u256) Address - Predict address
    • createAccount(owner: Address, salt: u256) Address - Deploy account
    • getInitCode(owner: Address, salt: u256) []u8 - Get init code

Utilities

  • Helper functions:
    • txToUserOp(tx: Transaction, account: SmartAccount) UserOperation - Convert tx
    • signUserOperationHash(hash: Hash, signer: Wallet) []u8
    • validateUserOpSignature(userOp: UserOperation, account: SmartAccount) bool

Common Account Types Support

  • Framework for custom account implementations:
    • Multi-sig accounts
    • Session key accounts
    • Social recovery accounts
    • Modular accounts (ERC-6900)

File Structure

src/account_abstraction/
  ├── account.zig              # SmartAccount interface
  ├── simple_account.zig       # SimpleAccount implementation
  ├── factory.zig              # Account factory utilities
  └── utils.zig                # Helper functions

Example Usage

// Create a simple account
const factory = try SimpleAccountFactory.init(allocator, factory_address);
const account = try factory.createAccount(owner_wallet, 0);

// Use the account
const userOp = try account.execute(
    recipient_address,
    @as(u256, 1_000_000_000_000_000_000), // 1 ETH
    &[_]u8{}, // empty data
);

const signed_userOp = try account.signUserOperation(userOp);
const hash = try bundler.sendUserOperation(signed_userOp, entry_point);

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions