header-langage
简体中文
繁體中文
English
Tiếng Việt
Scan to Download the APP
Partnered With:

Developer Guide: Detailed account abstraction proposal EIP-4337 workflow

Read this article in 5 Minutes
This article describes how the main contract of EIP-4337 is implemented.
Original title: "EIP-4337 Detailed Workflow"
Original author: Ben Law


EIP-4337 Detailed Workflow


< p ql-global-para="true" line="oeIz" linespacing="150">This article will not introduce EIP-4337 from the beginning, but only how the main contract of 4337 is implemented. It is suitable for developers who have a certain understanding of 4337, especially wallet developers, as well as enthusiasts or researchers.


The main content is in the flowchart:



Need to read GitHub—eth-infinitism/account-abstraction at main with 4337 source code.


There are more details in 4337 Spec EIP-4337: Account Abstraction using alt mempool.   


Please note:


- This The flow chart only draws common types of transactions, Aggregator is not involved. Only after mastering the general process can it be convenient to master aggregated transactions.


- The arrows in the flowchart do not represent the call stack or input and output of the program, but only represent the sequence of occurrence of related roles, functions and events.


- In order to facilitate readers' quick understanding of the macro-architecture, some function calls and logic are omitted in the flowchart. The omitted part may be of great significance to your research questions or doubts, depending on what you want to know, so you still need to read the source code carefully when necessary.


Core Concept


Research 4337 needs to master the following core concepts:


The content of UserOperation EntryPoint implements Wallet, implements Paymaster, implements the execution process and error handling of the verification phase, the execution phase, and the payment process and calculation of Gas


UserOperation


A A pseudo-transaction object whose content is similar to transaction is submitted to the node through the new RPC method < code>eth_sendUserOperation.


The meanings of the fields in UO are mostly obvious, and only a few easily misunderstood ones are selected for analysis:


sender, here refers to the wallet to be interacted with, not any other concept such as msg.sender or tx.origin verificationGasLimit, gasLimitcallGasLimit when verifying a transaction, gasLimitpreVerificationGas when executing a transaction , to compensate the uncalculated gas cost (such as the calldata cost of submitting the transaction) when the bundler calls < code> handleOps ().


Prefund


This is not a field in UO, but calculated by the above three gas parameters. Represents the total cost that this UO paid up front to < code>EntryPoint during the < strong> validation phase. Although Prefund is paid in the verification stage, it includes the cost of preVerificationGas, verification and execution. No further gas payments will be made to < code>EntryPoint afterwards.



See< < code>_getRequiredPrefund in code>EntryPoint.


EntryPoint


EntryPoint is the core entry point for all functions. Each project deploys its own EntryPoint by itself. Bundler, Wallet and Paymaster all need to work around EntryPoint.


Bundler implements two functions in EntryPoint


Verify UOs off-chain, and eliminate UOs that do not meet the requirements and have problems. The off-chain verification is to prevent DoS, and the second is to prevent the bundler from losing gas on the chain.

Package the compliant UO and submit it to the chain.


Wallet and EntryPoint


Pay gas fee to EntryPoint

only Respond to the message from EntryPoint

Execute the specific transaction content from EntryPoint

Note that EntryPoint is not a factory of Wallet. The official pictures are easy to cause this kind of misunderstanding, but the official realization is not the case.


Paymaster and EntryPoint


Pay gas fee to EntryPoint

only Respond to the message from EntryPoint

Confirm to EntryPoint your willingness to serve a certain UO

Stake in EntryPoint to become a paymaster


We can see that both Wallet and Paymaster may pay Gas to EntryPoint. The gas balance will be stored in the < code> deposits mapping.


Note that although deposits literally means recharge, it is not necessarily an action that needs to be completed manually in advance. It can also calculate how much gas is missing and recharge automatically when each UO occurs.


Finally, if the actualGasCost of all operations is less than the prefund,  EntryPoint will refund the excess amount to your deposit.   



Attention ,  validationActualCost & callActualCost  is just a mark for explanation, not a real variable. They are accumulated by gasPrice().   


Wallet


Delegates The wallet that the user ends up using. Developers are required to implement at least the following two custom methods:


signature verification : You can use any cryptographic means to implement signature verification, for example, implement NIST P-256's ECDSA for use with Apple's Security Enclave. If there is no special requirement, Ethereum's ECDSA can be used directly.


Transaction processing: EntryPoint uses < code> address (sender).call (callData) to call specific transaction functions in the wallet. Then call needs to have at least one executable function, such as transferEther(), callAnotherContrat(), etc.


Developers also need to implement the wallet factory by themselves. When creating a wallet, The factory will be called by the < code > SenderCreator contract. New wallets should use the < code> CREATE2 method to ensure the certainty of generating addresses.


Paymaster


Paymaster can pay gas for users, so it can be realized:


Free transactions: user incentives, allowing users to use wallets for free 

gasless transactions: do not pay gas directly with ether, And use other tokens or nft, etc.

And other similar sponsorship transaction functions


Paymaster requires developers to implement:


validatePaymasterUserOp (): Due to the openness of paymaster, the validation logic needs to be completely defined by the developer. After verification, it may be necessary to implement a function similar to < code>payPrefund () in < code>wallet.


_postOp: This method must be overridden, otherwise it will be reverted. This method can define what needs to be done after the paymaster sponsors the transaction. If ether is paid for the user during verification, the user is required to pay the equivalent ERC-20 here.   


Original link


Welcome to join the official BlockBeats community:

Telegram Subscription Group: https://t.me/theblockbeats

Telegram Discussion Group: https://t.me/BlockBeats_App

Official Twitter Account: https://twitter.com/BlockBeatsAsia

举报 Correction/Report
Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit