Skip to content

Add ERC-4337 UserOperation type and encoding #27

Description

@ch4r10t33r

Title

Add ERC-4337 UserOperation type and encoding

Labels

enhancement, account-abstraction, erc-4337

Description

Implement the core UserOperation struct according to ERC-4337 specification to enable account abstraction functionality, similar to viem's implementation.

Requirements

Core Type

  • Define UserOperation struct with all ERC-4337 required fields:
    • sender: Address - Account making the operation
    • nonce: u256 - Anti-replay parameter (now using native u256!)
    • init_code: []u8 - Account creation code (for first tx)
    • call_data: []u8 - Data to pass to sender during execution
    • call_gas_limit: u256 - Gas limit for main execution call
    • verification_gas_limit: u256 - Gas for account validation
    • pre_verification_gas: u256 - Fixed gas overhead
    • max_fee_per_gas: u256 - Max fee per gas unit (EIP-1559)
    • max_priority_fee_per_gas: u256 - Max priority fee (EIP-1559)
    • paymaster_and_data: []u8 - Paymaster address and extra data
    • signature: []u8 - Signature over the userOp hash

Encoding & Hashing

  • Implement packed ABI encoding for UserOperation
  • Add getUserOpHash(op: UserOperation, entry_point: Address, chain_id: u64) Hash
  • Add packUserOp(op: UserOperation) []u8 for encoding

Helper Methods

  • init() - Create new UserOperation
  • deinit() - Free allocated memory
  • isDeployment() - Check if this deploys a new account (has init_code)

File Structure

src/account_abstraction/
  ├── user_operation.zig    # Core UserOperation type
  ├── types.zig             # AA-related types
  └── root.zig              # Module exports

References

Benefits

  • Enable gasless transactions
  • Smart contract wallet support
  • Batch operations
  • Session keys and permissions
  • Social recovery

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions