A comprehensive implementation of Account Abstraction (AA) on both Ethereum and zkSync Era, built with Foundry. This project demonstrates how to create, deploy, and interact with smart contract accounts that can execute transactions without requiring users to manage private keys directly.
- Ethereum Account Abstraction: Implementation using EIP-4337 (Account Abstraction) with PackedUserOperation
- zkSync Era Account Abstraction: Native zkSync AA implementation using type 113 transactions
- Minimal Account Contracts: Lightweight, gas-efficient smart contract accounts
- Comprehensive Testing: Full test coverage for both Ethereum and zkSync implementations
- Deployment Scripts: Automated deployment and interaction scripts
- Foundry Integration: Built with Foundry for development, testing, and deployment
βββ src/
β βββ ethereum/ # Ethereum AA implementation
β β βββ MinimalAccount.sol
β βββ zksync/ # zkSync Era AA implementation
β βββ ZkMinimalAccount.sol
βββ script/ # Deployment and interaction scripts
β βββ DeployMinimal.s.sol
β βββ HelperConfig.s.sol
β βββ SendPackedUserOp.s.sol
βββ test/ # Test files
β βββ ethereum/ # Ethereum AA tests
β βββ zksync/ # zkSync AA tests
βββ lib/ # Dependencies
βββ foundry.toml # Foundry configuration
The MinimalAccount contract implements the standard EIP-4337 Account Abstraction pattern:
- EntryPoint Integration: Works with the standard EntryPoint contract
- UserOperation Validation: Validates signed user operations
- Gas Management: Handles gas limits and fees
- Signature Verification: ECDSA signature validation for transaction authorization
The ZkMinimalAccount contract implements zkSync's native AA system:
- Type 113 Transactions: Uses zkSync's custom transaction type
- Bootloader Integration: Works with zkSync's bootloader system
- Nonce Management: Handles transaction nonces through system contracts
- Gas Optimization: Leverages zkSync's gas-efficient execution model
- Foundry (latest version)
- Node.js 18+ (for some dependencies)
- Access to Ethereum and zkSync RPC endpoints
# Install Foundry dependencies
make install
# Or manually:
forge install eth-infinitism/account-abstraction@v0.7.0
forge install openzeppelin/openzeppelin-contracts@v5.0.2
forge install cyfrin/foundry-era-contracts@0.0.3
forge install cyfrin/foundry-devops@0.3.0Create a .env file with your configuration:
# Network RPC URLs
ARBITRUM_RPC_URL=your_arbitrum_rpc_url
ZKSYNC_RPC_URL=your_zksync_rpc_url
# Private keys (for deployment and testing)
devKey=your_private_keyforge build# Run all tests
forge test
# Run Ethereum-specific tests
forge test --match-contract MinimalAccountTest
# Run zkSync-specific tests
forge test --match-contract ZkMinimalAccountTest --zksync --system-mode=true# Deploy the MinimalAccount contract
make deploy-arb
# Send a user operation
make send-arb# Deploy MinimalAccount
forge script script/DeployMinimal.s.sol --rpc-url $ARBITRUM_RPC_URL --account devKey --broadcast --verify
# Send UserOperation
forge script script/SendPackedUserOp.s.sol --rpc-url $ARBITRUM_RPC_URL --account devKey --broadcast// Generate a user operation for USDC approval
bytes memory functionData = abi.encodeWithSelector(
IERC20.approve.selector,
approver,
amount
);
bytes memory executeCalldata = abi.encodeWithSelector(
MinimalAccount.execute.selector,
usdcAddress,
0,
functionData
);
PackedUserOperation memory userOp = generateSignedUserOperation(
executeCalldata,
config,
minimalAccountAddress
);// Execute a transaction through the account
minimalAccount.execute(
destination, // Target contract
value, // ETH value to send
functionData // Function call data
);The project includes comprehensive tests covering:
- Account Creation: Contract deployment and initialization
- Transaction Execution: Direct and user operation-based execution
- Access Control: Owner and EntryPoint authorization
- Signature Validation: ECDSA signature verification
- Gas Management: Gas limit and fee handling
- Error Handling: Proper revert conditions
# Test account execution
forge test --match-test testOwnerCanExecutesCommands
# Test signature recovery
forge test --match-test testRecoverSignedOp
# Test zkSync validation
forge test --match-test testZkValidateTransaction --zksync --system-mode=trueThe foundry.toml includes:
- Remappings: Library imports and dependencies
- System Mode: Required for zkSync testing
- IR Mode: Optimized compilation
- Formatting: Code style configuration
HelperConfig.s.sol manages network-specific settings:
- RPC endpoints
- Contract addresses (EntryPoint, USDC, etc.)
- Gas parameters
- Account configurations
Account Abstraction allows users to:
- Use smart contracts as their primary accounts
- Execute transactions without managing private keys
- Implement custom transaction validation logic
- Use paymasters for gas fee management
User operations are the core of EIP-4337:
- Sender: The account address
- Nonce: Transaction ordering
- CallData: The actual transaction data
- Signature: Authorization proof
- Gas Parameters: Fee and limit management
zkSync Era provides:
- Native AA Support: Built-in account abstraction
- Gas Efficiency: Optimized execution model
- System Contracts: Pre-deployed infrastructure
- Type 113 Transactions: Custom transaction format
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
This project is licensed under the MIT License.
- eth-infinitism for EIP-4337 implementation
- OpenZeppelin for secure contract libraries
- zkSync Era for zkSync integration
- Foundry for the development framework
For questions and support:
- Open an issue on GitHub
- Check the test files for usage examples
- Review the contract documentation
Note: This is a learning project. Do not use in production without thorough auditing and testing.
MinimalAccount: 0x5B17b78e34954A760D293655bAF440C817080C3E AA transaction: 0x4cfa87c0ff80203bb5d06f847703ddf114af944383feedbfc2b59ad0dd9314e0