- UserOperation Struct: Decouple transaction execution from ECDSA private keys using pseudo-transaction objects processed in an alt-mempool.
- EntryPoint Contract: Act as the global singleton singleton orchestrator verifying and executing bundled operations atomically.
- Paymaster Gas Sponsorship: Enable dApps to sponsor gas fees or accept ERC-20 tokens (USDC, DAI) for transaction settlement.
- WebAuthn & Passkeys: Authenticate smart contract transactions using secure hardware enclaves (TouchID, FaceID) via P-256 RIP-7212 precompiles.
1. EOA Limitations & The ERC-4337 Account Abstraction Paradigm
Externally Owned Accounts (EOAs) tightly couple identity and transaction signing: an ECDSA private key over the secp256k1 curve directly dictates account ownership. If a private key is lost or leaked, account recovery is impossible. Furthermore, EOAs cannot batch multiple calls atomically or sponsor gas fees without complex off-chain meta-transaction relayers.
ERC-4337 introduces Account Abstraction without modifying the underlying Ethereum consensus layer. Users construct high-level UserOperation structs containing target callData, verification gas limits, and signature payloads, which are broadcast to dedicated Alt-Mempools monitored by specialized nodes called Bundlers.
// Solidity: ERC-4337 UserOperation Memory Struct
struct UserOperation {
address sender;
uint256 nonce;
bytes initCode;
bytes callData;
uint256 callGasLimit;
uint256 verificationGasLimit;
uint256 preVerificationGas;
uint256 maxFeePerGas;
uint256 maxPriorityFeePerGas;
bytes paymasterAndData;
bytes signature;
}
2. EntryPoint Singleton & Bundler Execution Loop
Bundlers collect UserOperations from the alt-mempool, simulate their execution locally to filter invalid nonces and gas exhaustion vectors, and bundle valid operations into a single standard Ethereum transaction submitted to the canonical EntryPoint singleton contract (such as 0x0000000071727De22E5E9d8BAf0edAc6f37da032).
The EntryPoint contract executes a strictly divided two-phase loop: Phase 1 (Verification Loop) calls validateUserOp() on each Smart Contract Account (and validatePaymasterUserOp() on paymasters), and Phase 2 (Execution Loop) executes user callData while calculating exact gas refunds for the bundler.
// Solidity: Smart Account Validation Hook
function validateUserOp(
UserOperation calldata userOp,
bytes32 userOpHash,
uint256 missingAccountFunds
) external returns (uint256 validationData) {
require(msg.sender == ENTRY_POINT, "Caller must be EntryPoint");
// Verify ECDSA or Passkey signature against stored owner
bytes32 hash = userOpHash.toEthSignedMessageHash();
if (owner != hash.recover(userOp.signature)) {
return SIG_VALIDATION_FAILED;
}
// Pay EntryPoint required pre-funding balance if needed
if (missingAccountFunds > 0) {
(bool success, ) = payable(msg.sender).call{value: missingAccountFunds}("");
(success);
}
return 0; // Success
}
3. Paymaster Gas Sponsorship & ERC-20 Fee Settlement
Paymasters are smart contracts that sponsor gas on behalf of users or allow users to pay gas in ERC-20 stablecoins. When paymasterAndData is present in a UserOperation, the EntryPoint queries the paymaster during Phase 1 verification to lock collateral.
During Phase 2 post-execution, the EntryPoint invokes postOp() on the Paymaster, passing the exact gas consumed so the paymaster can deduct the equivalent USDC or DAI balance from the user account.
// Solidity: TokenPaymaster Post-Operation Settlement
function postOp(PostOpMode mode, bytes calldata context, uint256 actualGasCost) external override {
require(msg.sender == address(entryPoint), "Only EntryPoint");
(address sender, address token, uint256 tokenPerWei) = abi.decode(context, (address, address, uint256));
uint256 tokenAmount = actualGasCost * tokenPerWei;
IERC20(token).transferFrom(sender, address(this), tokenAmount);
}
4. Hardware Enclave Authentication: WebAuthn & RIP-7212 (P-256)
The pinnacle of smart wallet user experience is eliminating seed phrases entirely by signing transactions via WebAuthn and Passkeys (TouchID, FaceID, YubiKey). Because Apple Secure Enclave and Android Keystore produce signatures over the secp256r1 (P-256) curve rather than Ethereum secp256k1, verifying P-256 in EVM bytecode originally cost > 300k gas.
With the adoption of RIP-7212 precompiled contracts (at address 0x0100) across Layer 2 rollups, P-256 signature verification cost drops to 3,450 gas, enabling native biometric hardware authentication for on-chain accounts.
// Solidity: RIP-7212 secp256r1 Precompile Invocation
function verifyP256Signature(bytes32 messageHash, uint256 r, uint256 s, uint256 qx, uint256 qy) internal view returns (bool) {
bytes memory input = abi.encode(messageHash, r, s, qx, qy);
(bool success, bytes memory output) = address(0x0100).staticcall(input);
return success && abi.decode(output, (uint256)) == 1;
}
Frequently Asked Questions (FAQ)
How does ERC-4337 prevent DOS attacks on Bundlers?
Bundlers run strict simulation rules: during validateUserOp(), accounts are forbidden from accessing mutable storage outside their own account namespace or reading environment opcodes (TIMESTAMP, BLOCKNUMBER), guaranteeing that an approved transaction cannot be invalidated before on-chain execution.
Can ERC-4337 smart wallets batch approve and swap in one transaction?
Yes. Because smart accounts execute arbitrary callData arrays inside executeBatch(), users can combine ERC-20 approve() and DEX swap() in a single atomic transaction without waiting for intermediate confirmations.
What is the purpose of RIP-7212?
RIP-7212 standardizes an EVM precompiled contract for the secp256r1 (P-256) elliptic curve, lowering the verification gas cost of mobile hardware biometric Passkeys (FaceID/TouchID) from 300,000 gas to ~3,450 gas.
Utility Security Tools Related to this Article:
Gunakan JWT Decoder & Inspector dan UUID Generator untuk membantu alur kerja konfigurasi keamanan Anda secara privasi di browser.