zkfriendly
    • 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
    • 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 Versions and GitHub Sync Note Insights 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Grant Proposal: Semaphore Paymaster *Thanks to John Guilding, Jake C-T, Yanis Meziane and Giacomo Corrias for review this proposal.* ## Project Overview This project provides a toolkit for web3 developers looking to create dapps that offer a seamless, gasless experience for their users by leveraging their Semaphore group membership—without the hassle of spending excessive time integrating Semaphore and ERC-4337 themselves. ### Problem Statement The decentralized nature of Ethereum is powerful, but it also presents well-known fundamental challenges: onchain activities are not privacy-preserving, and every transaction incurs a gas fee. Various efforts have been made to address these issues. Semaphore is a widely used tool that allows group members to send anonymous signals, while ERC-4337 enables gasless transactions for users. Although both tools are powerful, integrating them together into a single dapp is particularly challenging. Developers must navigate the complexities of combining these two technologies, which can be time-consuming and require deep technical expertise. This often leads to delays in development and increased costs. ### Proposed Solution To address these challenges, our project aims to provide open-source tools and modular components, including a Semaphore paymaster and frontend elements, specifically designed for building Account Abstraction applications. Our goal is to simplify the integration process, enabling developers to focus on building innovative features rather than getting bogged down by technical hurdles. This toolkit offers a robust and easily integrable base template for developers. **Key Features and Innovation** Paymaster is [an extension of the ERC-4337 entry point logic](https://eips.ethereum.org/EIPS/eip-4337#extension-paymasters). This feature allows application developers to subsidize fees for their users, enable users to pay fees with ERC-20 tokens, and support various other use cases. Consolidated with Paymaster, ERC-4337 significantly improves the user experience by freeing users from the need to understand and manage gas fees. If the [QF Round in Ethcon Korea 2023](https://qf.pse.dev/case-studies/ethcon-23) had utilized this approach, it likely would not have suffered from the low participation rate. However, it doesn't come without a trade-off: a lack of privacy. With this proposal, we introduce a paymaster leveraging Semaphore (aka. Semaphore Paymaster). The Semaphore paymaster subsidizes transactions for users who can prove their membership in a Semaphore group. This combination allows for privacy-preserving, gasless transactions, addressing both of the major challenges developers face today. **Use Case and Demonstration** We will demonstrate the use of these tools through a concrete use case that combines the Semaphore paymaster and MACI. This application enables users to prove their identity and vote anonymously, with their gas fees sponsored by the Semaphore paymaster. Our commitment to this goal is reflected in [the prototype](https://www.loom.com/share/67aa3d4d284c4e6294f00d6d852b4ad1?sid=43952cb2-c6fe-4a66-9502-9d1ae854715b) we delivered at the PSE Hackerhouse during EthCC 2024. Looking ahead, our timeline includes running an anonymous and gasless voting process for hackathon projects at [Ethereum Costa Rica](https://x.com/ethereumcr) in October. This event will showcase the practical implementation and benefits of our tools in a real-world scenario ## Project Details ### Core Modules #### Semaphore Paymaster - **Gatekeeper**: Allows a user to join a Semaphore group once their identity has been verified. - **Paymaster**: Sponsors gas fees anonymously for Semaphore group members. - **Documentation**: Comprehensive guides and tutorials. - **Boilerplate**: Frontend components for easy integration. #### Future Work - **Integration Support**: Request ZeroDev, Biconomy, and Pimlico to add support for the Semaphore paymaster. - **Gatekeeper Extensions** Integrate the gatekeeper with other identity verification applications such as Hats Protocol, Gitcoin Passport, or Zupass. These extensions are expected to require minimal effort for off-chain components, owing to the unified interface provided by Excubiae. ### Team #### Team Members - [zkfriendly](https://github.com/zkfriendly) - [jihoonsong](https://github.com/jihoonsong) - [baumstern](https://github.com/baumstern) - [brolag](https://github.com/brolag) #### Team's Experience Our team consists of experienced blockchain developers with a strong background in Ethereum smart contracts and privacy protocols. We have previously developed and contributed to several open-source projects, including the Semaphore protocol, ZkEmail and various Account Abstraction applications. Our expertise aligns well with the project's objectives, ensuring we have the necessary skills to successfully implement and deliver the Semaphore + Paymaster integration. ## Development Roadmap ### Milestone 1: Simple Semaphore Paymaster Smart Contract + An Optimization for Executing Batch User Operations. **Estimated Duration**: 2 weeks **Full-time equivalent (FTE)**: 2 **Costs**: [jihoonsong](https://github.com/jihoonsong): $2,400 [brolag](https://github.com/brolag): $4,800 Total amount: $7,200 We aim to deliver two Semaphore Paymasters: 1. **`SimpleSemaphorePaymaster`**: This paymaster will sponsor gas for semaphore group members without imposing any limitations on how much gas members can consume. 2. **`GasLimitedSemaphorePaymaster`**: This version will impose a periodic gas limit on how much gas members can consume. In this milestone, we will be designing and implementing the `SimpleSemaphorePaymaster`. #### Specification and High-Level Design: At its core, the `SimpleSemaphorePaymaster` has two main components: - Semaphore Group Membership verification and validation - `ERC-4337` Compatible Paymaster contract Essentially, the `Paymaster` contract will depend on a `Semaphore` contract to verify `Semaphore` membership proofs. ##### Paymaster Each `Paymaster` will depend on one `Semaphore` group. To this end, the `Paymaster` contract will be passed the `Semaphore` contract address and a `GroupId`. It will sponsor transactions that have a valid membership proof of the predefined `GroupId`. ###### Membership Proof A typical `Semaphore` membership proof is like this: ```solidity struct SemaphoreProof { uint256 merkleTreeDepth; uint256 merkleTreeRoot; uint256 nullifier; uint256 message; uint256 scope; uint256[8] points; } ``` And we need to have access to the above proof from within the paymaster to be able to verify the membership. For this we ABI encode the `SemaphoreProof` struct and embed it in the [`PaymasterData` field of the `UserOperation`](https://eips.ethereum.org/EIPS/eip-4337#useroperation). In the `validatePaymasterUserOp` we decode the attached proof, send it to the `Semaphore` contract to make sure the proof is valid. Once the verification passes, the `Paymaster` will pay for the `UserOperation`. Since the `SimpleSemaphorePaymaster` does not impose any sort of limitation, this is the only check that happens. ###### Optimization In case one wants to use the same AA wallet to execute multiple `UserOperations`, we can verify the membership proof once and store the result to avoid verifying expensive zk proofs each time the user wants to execute a `UserOperation`. This can be implemented in various ways: - An external method on the paymaster contract that stores a mapping between the account address and `isMember` and will be used in the `validatePaymasterUserOp` method: ```solidity mapping(address => bool) isMember; // stores the membership status function setIsMember(SemaphoreProof proof, address accountAddress); // sets the membership status ``` - It can be set after verifying the first `UserOperation` of the user. In the `postOp` phase of the paymaster, we can call `setIsMember` automatically, so the user won't need to provide membership proof again. The downside of these methods is that once the user is no longer part of the Semaphore group, there needs to be a mechanism to invalidate the `isMember` flag. This can be implemented by having a fixed expiry date for the flag. ###### Considerations - **Preventing proof front run**: In order to prevent malicious actors to front-run the membership proof, the user **MUST** include the wallet address that is sending the `UserOperation` in the `message` field of the `SemaphoreProof`. - **Proof reuse**: This is a less severe issue since the wallet address is already embeded in the `message`, however to prevent any other issues with reusing a proof more than once, we will return the proof `nullifier` in the `context` field of `validatePaymasterUserOp` so that we can mark it as used in the `PostOp` phase of the `Paymaster`.* In summery we will deliver the following: | Name | Deliverable | Specification | |----------------------|--------------------------|---------------------------------------------------| | `SimpleSemaphorePaymaster` | smart contract | `ERC-4337` compatible paymaster with described functionality that pays for `Semaphore` group members without any limitations | | `BatchOptimizedSemaphorePaymaster`| smart contract | Allows users to use the `SimpleSemaphorePaymaster` without proving proofs for each `UesrOperation` | Unit Tests | forge unit tests | comprehensvie unit test for the `SimpleSemaphorePaymaster` | Integration test | forge + hardhat tests | end to end tests that cover the flow of gas sponsorship in a local environment ### Milestone 2: Gas Limited Semaphore Paymaster **Estimated Duration**: 2 weeks **Full-time equivalent (FTE)**: 2 **Costs**: [jihoonsong](https://github.com/jihoonsong): $2,400 [brolag](https://github.com/brolag): $4,800 Total amount: $7,200 #### Overview In this milestone, we aim to implement the gas-limited `Paymaster` that imposes a predefined periodic gas limitation on requests. For example, the period could be one week, and the gas limit could be one million. This means that each member can execute `UserOperations` that consume at most one million gas each week. This limit will reset back to one million each week. This implementation will be a continuation of the `SimpleSemaphorePaymaster`, and therefore it will have all the mentioned properties of the `SimpleSemaphorePaymaster`. Additionally, it receives the following extra parameters when instantiating the `GasLimitedSemaphorePaymaster`: - `periodDuration`: Defines the gas limit reset period in seconds. - `startTimestamp`: Timestamp of the start of the first period. - `gasLimit`: Maximum cumulative gas that can be consumed by each member during each period. *Note: All the above parameters are set once during the construction of the contract and will remain immutable.* #### Proof `Scope` In order to enable and enforce periodic gas limits, we need to make use of the `scope` field in `SemaphoreProof`. As a reminder, the `nullifier` is [the hash of the user's private key and `scope`](https://docs.semaphore.pse.dev/glossary#nullifier). This means that if the user uses the same `scope` to generate proofs, it will result in the same `nullifier` each time. The `nullifier` is usually marked as `used` or `invalid` after the first time the proof is used to prevent double signaling. In our use case, the `scope` that the user must use to generate the proof is determined by the `GasLimitedSemaphorePaymaster` contract, which will be the active period: ```solidity= function getScope() public returns(uint256) { return (block.timestamp - startTimestamp) / periodDuration; } ``` This way, all the proofs that a user generates during each period will have the same `nullifier`. We can use this to track the gas consumption of the user and only mark the `nullifier` as `used` once the gas limit is reached. ***PRIVACY NOTICE: This means that all the transactions of a user are linked together during each period through the `nullifier`. However, it is still disconnected from the original identity of the user.*** #### Putting it all together The client reads (or calculates) the correct `scope` and generates a proof as before, attaching it to the `PaymasterData`. On the `Paymaster` side, not only is the proof verified, but the `scope` is also checked to ensure it corresponds to the active period. Moreover, the `Paymaster` checks if the already consumed gas by the user, plus the gas that the current `userOperation` is going to use, is still below the period gas limit. If the check passes, the `userOperation` will be sponsored; otherwise, it will be rejected. In the `PostOp` phase of the `Paymaster`, the actual gas consumed by the `userOperation` is added to the total gas consumed in the active period for the user (identified by the `nullifier`). If the total consumed gas goes above the limit, the `nullifier` will be marked as `used` and cannot be used anymore until the next period. In summary this milestone delivers the following: | Name | Deliverable | Specification | |----------------------|--------------------------|---------------------------------------------------| | `GasLimitedSemaphorePaymaster` | smart contract | `ERC-4337` compatible paymaster with described functionality that enforces a periodic gas limit | Unit Tests | forge unit tests | comprehensvie unit test for the `GasLimitedSemaphorePaymaster` | Integration test | forge + hardhat tests | end to end tests that cover the flow of gas sponsorship in a local environment ### Milestone 3: Gatekeeper Inheriting [Excubiae](https://github.com/privacy-scaling-explorations/zk-kit.solidity/tree/main/packages/excubiae) and End-to-end test **Estimated Duration**: 2 weeks **Full-time equivalent (FTE)**: 2 **Costs**: [jihoonsong](https://github.com/jihoonsong): $2,400 [brolag](https://github.com/brolag): $4,800 Total amount: $7,200 #### Overview We need a gatekeeper that permits a user with a verified identity to join a Semaphore group. The gatekeeper will be inheriting [Excubiae](https://github.com/privacy-scaling-explorations/zk-kit.solidity/tree/main/packages/excubiae), with the aim of facilitating seamless extension to incorporate other identity verification applications such as Hats Protocol, Gitcoin Passport, or Zupass. Having end-to-end testing with the gatekeeper and Semaphore paymaster will help us build a more robust system. Furthermore, the end-to-end testing environment can serve as a valuable example for other projects looking to construct their own end-to-end testing environments. | Name | Deliverable | Specification | |----------------------------|----------------|---------------------------------------------------| | Gatekeeper with Excubiae | smart contract | Add a gatekeeper inheriting Excubiae that allows all entry into a Semaphore group and incorporate it into the end-to-end test | | End-to-end test script | hardhat test | Add an end-to-end test script that is entering a semaphore group via the Gatekeeper, constructing an `UserOp` that transfer some ETH with gas sponsored by `SimpleSemaphorePaymaster` | ### Milestone 4: Gasless Voting Process and Frontend Optimization **Estimated Duration:** 3 weeks **Full-time equivalent (FTE)**: 2.5 **Costs**: [jihoonsong](https://github.com/jihoonsong): $2,800 [brolag](https://github.com/brolag): $5,600 Total amount: $8,400 #### Overview This milestone encompasses the implementation of a gasless voting process for hackathon projects at Ethereum Costa Rica and the optimization of the frontend codebase. Our goal is to provide a seamless, user-friendly voting experience while ensuring the frontend code is maintainable, modular, and scalable. This preparation is crucial for delivering a polished application at the event. #### Gasless Voting Process To support a gasless voting process, all hackathon participants will be whitelisted and can use their verified identities to sign up for a Semaphore group. Additionally, we will implement a frontend-based mechanism to verify if an address is part of the whitelist through a signed message. The process is as follows: 1. The user loads the application and the frontend fetches the whitelist JSON file stored in a GitHub repository. 2. The user signs a predefined message using their wallet (e.g., MetaMask). 3. The frontend recovers the user's address from the signed message and checks if the address is part of the fetched whitelist. 4. If the address is on the whitelist, the user is allowed to submit their signed request to the bundler to join the Semaphore group. | Name | Deliverable | Specification | |--------------------|----------------------|----------------------------------------------------------------------------------------------------| | Frontend and smart contracts integration | open source | Put gatekeeper, Semaphore, Semaphore Paymaster, and frontend all together | | Frontend Whitelist Verification | frontend code | Implement the capability in the frontend to verify if an address is part of the whitelist through a signed message | | Voting Dashboard | open source | Develop a dashboard for users to view and participate in the voting process, with real-time updates and results | #### Frontend Optimization In parallel, we will focus on cleaning up and optimizing the frontend code to ensure it aligns with best practices and is ready for scale. | Name | Deliverable | Specification | |--------------------|----------------------|-------------------------------------------------------------------------------------------------| | Code Refactoring | code refactor | Review and refactor existing frontend code to ensure clarity, reduce complexity, and remove redundancy | | Modularization | code modularization | Break down large components into smaller, reusable modules to promote code reuse and simplify development | | UI/UX Enhancements | design update | Address UI/UX issues to ensure an intuitive and standardized interface | | Testing and Bug Fixes | automated tests | Conduct testing to identify and fix bugs, and implement automated tests for critical paths | | Documentation | documentation update | Update documentation to reflect changes and provide clear instructions for future developers |

    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