(1/30) Account Abstraction and ERC-4337
Account abstraction is a critical upgrade required for @ethereum to become the World Computer, but achieving account abstraction requires tons of changes... until ERC-4337
A deep-dive on how account abstraction currently works on Ethereum
(2/30) Ethereum is the World Computer, a single, globally shared computing platform that exists in the space between a network of 1,000s of computers (nodes).
This globally shared computing platform is manifested with the Ethereum Virtual Machine (EVM).
x.com/LogarithmicRex/status/1592309373732151296
(3/30) Within the EVM, there are two types of entities: externally owned accounts (EOAs) and smart contract accounts.
At a high level, think of EOAs like users, smart contracts like applications and transactions as instructions.
x.com/LogarithmicRex/status/1859629927265599989
(4/30) Today, all transactions must be initiated by an EOA. While this paradigm has worked well enough up until this day, it's far from ideal.
Most importantly, the financial system of the future should not require everyday users to mange private keys and protect seed phrases.
(5/30) The goal is to achieve natively-supported account abstraction, which tears down the barrier between EOAs and smart contract accounts.
With account abstraction, smart contracts will function like EOAs and users will operate via smart contract accounts.
x.com/LogarithmicRex/status/1612587312638234626
(6/30) The major benefits of account abstraction include:
- allowing users to begin using Ethereum with empty wallets (no $ETH for gas)
- allowing users to pick different signature schemes (eg using @Apple's FaceID)
- allowing users to pay for gas with tokens (eg $USDC)
(7/30) Account abstraction is a big deal; it is (mostly) the solution to the blockchain UX problem.
Unfortunately, it can be hard to implement. Especially for Ethereum, where the necessary changes to consensus can take months/years and compete with every other pending EIP.
x.com/LogarithmicRex/status/1860124844295438691
(8/30) The biggest hurdle to supporting account abstraction with today is handling gas.
Gas is normally provided by the EOA generating the transaction. With account abstraction, the signer isn't necessarily a wallet (and therefore wont have $ETH for gas).
x.com/LogarithmicRex/status/1858932051598336322
(9/30) The endgame goal: to natively support account abstraction directly within the Ethereum protocol.
We will get there (sooner than we thought), but account abstraction is so powerful the community began asking itself: "do we need to wait for Ethereum to change?"
(10/30) 2 years ago, we found our answer - we can achieve many of the benefits of account abstraction immediately, without changing the core protocol.
ERC-4337 is this solution; account abstraction functionality built on top of an unmodified Ethereum.
eips.ethereum.org/EIPS/eip-4337
(11/30) Before we jump in to ERC-4337, let's take a look at how normal, EOA-based transactions work.
Users generate txns (including paying for gas) and send it to a node. After processing the txn, Ethereum incorporates the txn into the EVM and adds it to the blockchain.
(12/30) With ERC-4337, users are no longer generating and signing transactions - they are now generating and signing user operations (UserOps).
A UserOp is similar to a transaction with one major difference: UserOps do not include any $ETH for gas.
(13/30) ERC-4337 modifies the transaction flow by introducing two entities.
Bundler (off-chain): entity that consolidates UserOps into a transaction, providing $ETH for gas.
Entry point (on-chain): smart contract that verifies the flow and ensures bundler is refunded for gas.
(14/30) With ERC-4337, bundlers front $ETH needed to pay for gas to process the underlying UserOps.
A bundler is comfortable paying upfront because the Entry Point guarantees reimbursement for this cost, either from the user who generated the UserOp or a "paymaster."
(15/30) A paymaster is another new entity introduced by ERC-4337, particularly relevant for new users or applications that want to abstract away gas fees.
For example, @MetaMask might create a paymaster to facilitate swapping for users without $ETH (recouping gas costs via a fee).
x.com/MetaMask/status/1859679905883250886
(16/30) To expand a little further, let's imagine you have a wallet with 100 $USDC and 0 $ETH and want to swap your $USDC for $USDT.
By deploying a paymaster, Metamask can provide the $ETH the EVM requires and recoup the expense via charging an extra fee on the swap.
(17/30) Paymasters are not required under ERC-4337; the smart contract wallet can provide the $ETH needed to reimburse the bundler.
But paymasters offer incredibly powerful UX improvements. Most importantly, this paradigm gives us the option to entirely abstract away gas fees.
(18/30) ERC-4337 at a high level: users sign UserOps, bundlers create transactions, the Entry Point processes the UserOps and ensures bundlers are reimbursed for gas.
But if you can stomach slightly more technical explorations, it's worth it to dive a little deeper.
(19/30) First, look at what happens off-chain.
Users create UserOps and cryptographically sign them with whatever scheme that is defined by the smart contract wallet (typical private keys, FaceID, @Google session keys, etc).
UserOps are then sent to an alternative mempool
(20/30) This alternative mempool was created in conjunction with ERC-4337 and exists to hold UserOps before they are bundled.
Bundlers (which could be searchers, block builders or even nodes themselves) consolidate UserOps, bundles them in a txn and submits it to Ethereum.
(21/30) At this point we must pause and look at what an ERC-4337 smart contract wallet looks like.
Specifically, this smart contract must support two actions:
1) verify & pay: verifies the UserOp digital signature and authorizes gas spend
2) execute: processes the UserOp
(22/30) Let's first look at the situation where there is no paymaster.
Inside of the EVM, the Entry Point routes the UserOp to the smart contract to verify the digital signature and, assuming verification, allocate $ETH for gas.
(23/30) If and only if the smart contract verifies the signature and releases $ETH for gas, the Entry Point sends the UserOp to the execution function of the smart contract wallet.
At this point, the user's intended action is actually processed and the EVM is updated.
(24/30) Finally, the Entry Point processes all the gas refunds. This includes ensuring the bundler is made whole and for returning any unused $ETH to the user's smart contract wallet.
This completes the whole flow: the UserOp is executed and the bundler is repaid.
(25/30) Adding a paymaster adds more complexity, but the overall flow is similar.
First, the bundler submits a transaction that contain one or more UserOps. Next, the Entry Point verifies the signature via the smart contract wallet's code.
(26/30) At this point, the Entry Point turns to the paymaster. First, they ensure the paymaster has staked enough $ETH in the Entry Point smart contract.
Then, the Entry Point authorizes with operation with the paymaster smart contract.
(27/30) When the paymaster authorizes the operation, it provides the Entry Point enough $ETH to execute the UserOp. And so, the Entry Point sends the UserOp to the execution function of the smart contract wallet.
After this step, the UserOp is processed and the EVM updated.
(28/30) Finally, the Entry Point settles the gas accounting by refunding the bundler's upfront fee and returning unused gas to the paymaster.
This process concludes with call to the paymaster's post-op function (usually to finalize internal accounting in the paymaster contract).
(30/30) In summary: ERC-4337 is a system built on top of Ethereum that delivers the functionality of account abstraction without requiring any changes to Ethereum's core protocol.
The key is the addition of the bundler and Entry Point, which facilitate smart contract wallets.