Dror Tirosh
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- slideOptions: transition: slide title: PeepAnEIP 4337 Presentation type: slide --- [toc] ## ERC-4337 ## *Account Abstraction* ### *via Alternative Mempool* <div style="text-align: right"> One Year Later... </div> &nbsp; &nbsp; Yoav Weiss, Dror Tirosh, Shahaf Nacson https://github.com/eth-infinitism/account-abstraction --- ### What’s new? - Account changes - Extend Paymaster - Support Signature Aggregation - Relaxed Storage Rules - Staking, Reputations for all Entities - RPC API - Extras: spec-test, ref. impl, sdk Note: account: time-range (session keys) pm: support token paymaster agg: for rollups RPC: simulation, estimation Extras: For standarized bundler compatibility --- ### Key challenges - Why is it so Complicated - EOA is secured by signature, nonce, gas fees. - An existing Tx in mempool can't be invalidated - AA UserOperation is validated by EVM code, and **can** be invalidated before paying. - **Our goal:** make invalidations expensive.DoS attack on the mempool should cost. A lot. - Putting **`n`** UserOps into the mempool should cost **`O(n)`** --- ### UserOperation ```solidity struct UserOperation { address sender; uint256 nonce; bytes initCode; bytes callData; uint256 callGasLimit; uint256 verificationGasLimit; uint256 preVerificationGas; uint256 maxFeePerGas; uint256 maxPriorityFeePerGas; bytes paymasterAndData; bytes signature; } ``` --- ### Submit UserOperation to bundler ```plantuml @startuml autonumber participant User as user #lightgreen participant Bundler as node #lightgreen participant "EntryPoint\ncontract" as ep participant "Account\ncontract" as wallet user->user: create, sign UserOp 'node<--]: UserOp from memooool user->node++ #lightgreen: eth_sendUserOp node->ep++ #gold: traceCall:\nsimulateValidation ep->wallet++ #blue: <font color=blue> validateUserOp return send fee deactivate ep node->node: validate storage access node-->: add to mempool hide footbox ``` Note: explain all entities --- ### Submit UserOperation to bundler with factory ```plantuml @startuml autonumber participant User as user #lightgreen participant Bundler as node #lightgreen participant "EntryPoint\ncontract" as ep participant "Factory\ncontract" as fact participant "Account\ncontract" as wallet user->user: create, sign UserOp 'node<--]: UserOp from memooool user->node++ #lightgreen: eth_sendUserOp node->ep++ #gold: traceCall:\nsimulateValidation ep->fact++ #gray: create (initCode) fact->o wallet: create return account ep->wallet++ #blue: <font color=blue> validateUserOp return send fee deactivate ep node->node: validate storage access node-->: add to mempool hide footbox ``` --- ### Submit UserOperation to bundler with paymaster ```plantuml @startuml autonumber participant User as user #lightgreen participant Bundler as node #lightgreen participant "EntryPoint\ncontract" as ep participant "Account\ncontract" as wallet participant "Paymaster\ncontract" as pm user->user: create, sign UserOp 'node<--]: UserOp from memooool user->node++ #lightgreen: eth_sendUserOp node->ep++ #gold: traceCall:\nsimulateValidation ep->wallet++ #blue: <font color=blue> validateUserOp deactivate wallet ep->pm++ #gray: validatePaymasterUserOp deactivate pm deactivate ep node->node: validate storage access node-->: add to mempool hide footbox ``` --- ### Submit UserOperation to bundler ```plantuml @startuml autonumber participant User as user #lightgreen participant Bundler as node #lightgreen participant "EntryPoint\ncontract" as ep participant "Factory\ncontract" as fact participant "Account\ncontract" as wallet participant "Paymaster\ncontract" as pm user->user: create, sign UserOp 'node<--]: UserOp from memooool user->node++ #lightgreen: eth_sendUserOp node->ep++ #gold: traceCall:\nsimulateValidation ep->fact++ #gray: <font color=gray> create (initCode) fact->o wallet: <font color=gray>create return <font color=gray>account ep->wallet++ #blue: <font color=blue> validateUserOp return send fee (if no paymaster) ep->pm++ #gray: <font color=gray> validatePaymasterUserOp deactivate pm deactivate ep node->node: validate storage access node-->: add to mempool hide footbox ``` --- ### Creating HandleOps Transaction ```plantuml @startuml autonumber participant Bundler as node #lightgreen participant "EntryPoint\ncontract" as ep participant "Account\ncontract" as wallet activate node #lightgreen group <font color=green> Off-chain: pick UserOps from mempool node->ep++ #gold: traceCall:\nsimulateValidation ep->wallet++ #blue: validateUserOp deactivate wallet deactivate ep node->node: validate storage access note over node: add to bundle end group create transaction node->ep++ #blue: handleOps(bundle) group loop all UserOps for validation ep->wallet++ #blue: account.validateUserOp deactivate wallet end group loop all UserOps for execution ep->wallet++ #blue: account.call(callData) deactivate wallet end return pay collected fees end deactivate node hide footbox ``` --- ### Account API ```solidity function validateUserOp(UserOperation userOp, bytes32 userOpHash, uint256 missingAccountFunds) external returns (uint256 validationData); ``` - ValidationData: - Time-range: `validAfter`, `validUntil` - returned signature check: - signature aggregator (optional) - “0” - signature OK - “1” - sig check failed (ok during estimation) - BaseAccount - SimpleAccount: Proxy-based, EOA-like account Notes: missingfunds - maxPossiblecost --- ### Minimal Account ```solidity function validateUserOp(UserOperation userOp, bytes32 userOpHash, uint256 missingFunds) external returns (uint256 validationData) { require(msg.sender == address(entryPoint); bytes32 hash = userOpHash.toEthSignedMessageHash(); bool sigFailed = owner != hash.recover(userOp.signature); validationData = sigFailed ? 1 : 0; require(nonce++ == userOp.nonce); if (missingFunds != 0) entryPoint.depositTo{value : missingFunds}(msg.sender); } ``` --- ### Paymaster ```solidity function validatePaymasterUserOp(UserOperation userOp, bytes32 userOpHash, uint256 maxCost) returns (bytes context, uint256 validationData) function postOp(PostOpMode mode, bytes context, uint256 actualGasCost) ``` - May access account token balance - returned `validationData` like in Account. - May work without stake - But with no self-storage, and no context --- ### Custom Factory - Provided by each Account contract wallet. - <font color=blue>`UserOp.initCode`</font> : address + calldata - Can wrap existing factory (e.g. GnosisProxyFactory) - Can call “initializer” functions during construction - Must return same address for existing account --- ### Custom Factory ```solidity contract SimpleAccountFactory { function createAccount(address owner,bytes32 salt) public returns (address) { address addr = Create2.computeAddress(...); uint codeSize = addr.code.length; if (codeSize > 0) return addr; ret = new Proxy{salt : salt} ( accountImplementation, abi.encodeCall( SimpleAccount.initialize, (owner)) ); } } ``` --- ### **Key challenges - Why is it so Complicated** - **EOA** is secured by signature, nonce, gas fees. - An existing Tx in mempool can't be invalidated - **AA UserOperation** is validated by EVM code, and **can** be invalidated before paying. - **Our goal:** make invalidations expensive. DoS attack on the mempool should cost. A lot. - Putting **`n`** UserOps into the mempool should cost **`O(n)`** Note: The EP protects the account: only execute after its validation The separation of validation help the bundlers to validate userops fast. The rules below protect the bundlers: prevent DoS attacks --- ### Protection Rule Principles 1. **Sandboxing** - validation is the same on-chain and off-chain 2. **Isolation** - UserOperations should not share state 3. **Staking** - Bypassing rule (2) causes throttling. Staking make it expensive to re-deploy 4. **Low validation cost** --- ### Code Validation Rules - Prevent simulation and exectuion validation to behave differently. - Banned opcodes: NUMBER, TIMESTAMP, SELFDESTRUCT etc - Codehash must not change between 1st & 2nd simulations - Must not access EOA - GAS opcode: allowed just before *CALL - Must not revert on OOG --- ### Storage validation rules * Storage Rules * Allowed access to account storage (e.g. `account.getNonce()`) * Allowed access to referenced storage (e.g. `token.balanceOf(account)`) * Staked entities * All entities can be staked * Allowed to access its own storage * Can be Throttled/Banned * Reputations --- ### Bundler deep dive - Upon receiving `eth_sendUserOperation(userOp)`: - Save codehashes of accessed addresses - Run off-chain checks (paymaster balance etc.), then call debug_traceCall `simulateValidation(userOp)` (first simulation). If simulation succeeds, add userOp to mempool. --- ### Bundler deep dive - On bundle creation, for each candidate user operation from mempool perform the following: - validate no codehash changes - validate paymasters deposits - validate paymasters, aggregators, factories stakes/reputations if needed - validate bundle inclusion rules for accounts (e.g. 1 userOp per sender) - call debug_traceCall `simulateValidation(userOp)` (second simulation) --- ### RPC APIs * `eth_sendUserOperation` * `eth_estimateUserOperationGas` * `eth_getUserOperationReceipt` * `eth_getUserOperationByHash` * `eth_supportedEntryPoints` * `eth_chainId * As well as debug apis ` --- ### Signature Aggregation ```plantuml @startuml autonumber participant Bundler as node #lightgreen participant "EntryPoint\ncontract" as ep participant "Account\ncontract" as wallet participant "Signature\nAggregator" as agg activate node #lightgreen group <font color=green> Off-chain: pick UserOps from mempool node->ep++ #gold: traceCall:\nsimulateValidation ep->o wallet: validateUserOp return aggregator node->agg++ #gold: validateUserOpSignature() deactivate agg 'node->node: validate storage access end node->agg++ #gold: aggregateSignatures( UserOp [] ) deactivate agg group create transaction node->ep++ #blue: handleOps(bundle) ep->agg++ #gold: validateSignatures( UserOps [] ) deactivate agg group loop all UserOps for validation ep->o wallet #blue: account.validateUserOp end group loop all UserOps for execution ep->o wallet #blue: account.call(callData) end deactivate ep end deactivate node hide footbox ``` --- ## Bundler-Spec-Test - pytest tests validate enforcement of bundling rules, rpc compatibility etc.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully