$ show eth-infinitism/account-abstraction
This repository is the canonical reference implementation of ERC-4337 (Ethereum Account Abstraction) by the standard's authors. It provides a singleton EntryPoint contract that coordinates validation, execution, and gas accounting for UserOperations. The codebase includes abstract base contracts for accounts and paymasters, production-grade sample accounts (SimpleAccount, Simple7702Account), libraries for packed UserOperation hashing and EIP-7702 support, and extensive test and simulation infrastructure. It is deployed on Ethereum mainnet and supports paymasters, signature aggregators, counterfactual deployment via CREATE2, and EIP-7702 delegated code. The architecture is modular: core logic is separated into libraries (UserOperationLib, Helpers, Exec, Eip7702Support) and abstract contracts (BaseAccount, BasePaymaster, StakeManager, NonceManager) that can be reused in custom implementations. Gas optimization is a key focus, with patterns like transient storage, packed storage, and a custom nonReentrant guard. While the repo is tightly coupled to the EntryPoint's design, individual libraries and base contracts are reusable in any ERC-4337 integration.
The LLM identified 4 files worth highlighting for reuse:
A library for packing, unpacking, and hashing PackedUserOperation structures. It defines the EIP-712 typehash, computes userOpHash, and provides methods to unpack gas limits and paymaster fields from packed bytes32. Includes a custom paymaster signature suffix mechanism (magic bytes 0x22e325a297439656) that allows off-chain signing without altering the userOp hash. Uses assembly for memory pointer management and keccak256 hashing. Extracting this library into a separate package would be trivial; it has no internal dependencies and is the standard way to work with ERC-4337 UserOperations.
A library that detects EIP-7702 init code by checking for a specific prefix (0x7702) and extracts the delegated account address from the code prefix (0xef0100). Provides functions to determine if init code is EIP-7702 style and to get the initCode hash override for simulation. This is a novel pattern for handling EOA delegation as part of account abstraction. Can be reused in any project that needs to process EIP-7702 authorization signatures.
A utility library for packing and parsing validation data (authorizer, validUntil, validAfter) used in ERC-4337's validateUserOp return value. It provides _packValidationData, _parseValidationData, SIG_VALIDATION_FAILED, and SIG_VALIDATION_SUCCESS constants. Also includes calldataKeccak (efficient keccak of calldata using assembly) and a min function. These small, well-tested functions are used across the EntryPoint and can be extracted for any ERC-4337 implementation.
A minimal library for executing low-level calls (call, staticcall, delegatecall) that propagate revert data. It uses assembly to capture the return data and conditionally revert or return it. This is a reusable pattern for any contract that needs to execute arbitrary calls safely, and is used by BaseAccount and Paymaster contracts. It is dependency-free and demonstrates proper handling of gas forwarding and return data.