Chih-Cheng Liang
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • 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 No publishing access yet

        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.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        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
      • Make a copy
      • 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 Make a copy 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    10
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- lang: en image: https://i.imgur.com/7eRWde5.png --- # Mull Over The Nullifier *Thanks to Kobi Gurkan and Wanseob Lim for the reviews and the feedback* [TOC] ![](https://i.imgur.com/7eRWde5.png) > We're not talking about ["An item purchasable at the Main Shop, under Magical."](https://dota2.gamepedia.com/Nullifier) When I first looked into the zero-knowledge proof applications, the term nullifier confused me a lot. Many projects use nullifiers and define them differently depending on the context. In this post, we review those projects and extract the abstract idea that works for all. ## A Single-Use Gadget **Nullifier is a piece of data that ensures a message only takes effect once**. When we see the term nullifier, we can first restrict our attention to this primary function and take care of other details later. Why taking effect once matters? Consider the following applications: - Application A: A sender can send a message that instructs the system to move $10 from the sender's balance to a receiver, with the information of the sender, receiver, and value hidden from the public. - Application B: An user deposited $10 in the system some time ago. They can hire a relayer to send a message to withdraw the $10. The depositor can't be inferred from the message. - Application C: A voter can send a message to cast a vote to support a candidate without revealing the voter's name. These applications have something in common: - A message carries some economic value or causes some important things to happen. - A message hides information, but itself is broadcasted publicly. One can easily rebroadcast these messages to the system. Here's what would happen if we don't have a protection mechanism, and the same message takes effect twice or more. - Application A: The sender now sends another $10 to the receiver again. The receiver can drain all sender's money by resending the message again and again. - Application B: The user who deposited only $10 now withdraw another $10 from the system. The system can not maintain the balance and will go bankrupt. - Application C: The voter now cast two votes for the candidate. The tally becomes meaningless because anyone can throw as many votes they like. How can a nullifier come to help? Let's reveal the true identity of each application I choose arbitrarily. Note that people sometimes refer "nullifier" to secret data and "nullifier hash" to the secret's hash. Sometimes people refer "nullifier" to the hash of the secret and name the secret differently. In the former case, the nullifier is private information, while it is public in the latter case. ## Application A ### Zcash (Sprout) ``` Input Transparent 46252.81429411 ZEC + Shielded ? ZEC ▶JoinSplit▶ Output Transparent 0 ZEC + Shielded ? ZEC ``` > An example of [shielded payment](https://explorer.zcha.in/transactions/9329552a2acb3d686989b467bdd98ad1ae9ef77a608d7a731e093498df69c047) [Zcash](https://z.cash/technology/zksnarks/) allows a user to send a shielded payment, which hides receiver and amount information. ``` Nullifier = HASH(spending key, rho) ``` To send a shielded payment, the sender publishes an encrypted note along with its Nullifier. A note is the information of the receiver and amount. The full node tracks all the Nullifiers revealed so that a double spend can be detected. The Nullifier is a hash of the sender's spending key and a variable rho. In the older version Sprout, rho is just a unique identifier of the note. In contrast, in the newer version, Sapling, rho is the hash of the unique identifier and the note. ### Zkopru ``` Nullifier = HASH(nullifier_seed, utxo_leaf_index) ``` [Zkopru](https://docs.zkopru.network/how-it-works/grove#nullifier-tree) also allows users to send shielded payments, but on layer 2. Zkopru keeps the Nullifiers in a giant 254-depth Sparse Merkle Tree. A Nullifier is a hash of a secret `nullifier_seed` and the UTXO leaf index in the UTXO tree. The user sends a transaction and attaches a Nullifier with it. The coordinator runs the circuit off chain and tries to update each Nullifier leaf. A successful update should change the tree root. Otherwise, if the tree root remains the same after an update, it means the Nullifier is already in the tree, and thus the transaction is a double spend. ## Application B ### Tornado Cash ``` nullifierHash = HASH(nullifier) ``` When attempting to withdraw money from the Tornado Cash, the user provides a zk proof of the withdraw circuit validating the public nullifierHash is the hash of the private nullifier. The Tornado contract checks the nullifierHash hasn't been set before, then marks it sent on a successful withdraw. ```solidity contract Tornado { mapping(bytes32 => bool) public nullifierHashes; function withdraw(... bytes32 _nullifierHash, ...) { // ... require(!nullifierHashes[_nullifierHash], "The note has been already spent"); // ... nullifierHashes[_nullifierHash] = true; // ... } } ``` ## Application C ### OneOfUs ![](https://i.imgur.com/F00ii5U.png) The voting example came from the [OneOfUs](https://weijiek.medium.com/private-voting-and-whistleblowing-in-ethereum-using-semaphore-449b376808e) ([Github repo](https://github.com/weijiekoh/oneofus/blob/master/contracts/sol/OneOfUs.sol)), which lets a POAP token owner register and vote on questions. Voting is anonymous, and a user can only vote once per question so that no double vote is allowed. OneOfUs is built upon a more general private signaling framework called Semaphore. Let's talk about Semaphore first, then OneOfUs is easier to understand. ### Semaphore ``` // Semaphore nullifiers_hash = HASH(identity_nullifier, external_nullifier, identity_path_index) ``` Like Tornado Cash, arguably a specialized and simplified version of Semaphore, Semaphore contract also has a mapping `nullifierHashHistory` that tracks nullifier hash that has been published before. What makes Semaphore so special is that it has an _External Nullifier_, a piece of public data that acts as a topic. The application designer can exploit the external nullifier to limit a user's action to a particular topic only once, or even [rate limit](https://github.com/ChihChengLiang/semaphore_auth/issues/23) the user action three times, or once every 5 minutes. ``` // OneOfUs external_nullifier = HASH("Is the typhon going to hit Osaka?") ``` In the OneOfUs example, the external nullifier is just the hash of the question. Once the user answers the question 1 publishes the nullifier hash, they can't answer the question 1 again because that would publish a duplicated nullifier hash. But the user can still answer another question, say question 2 since the nullifier hash will be different and the Semaphore contract hasn't seen it before. ## Commitment We've focused on how nullifiers gurantee the signle use of the messages. The next natural question to ask is who is authorized to send that single valid nullifier in the first place? The nullifier usually comes with its counterpart, the commitment. Some project's document calls the combination a "commitment-nullifier scheme," which is a pattern that powers many Zero-knowledge proof applications. A commitment is a published hash of secrets, and it determines who is allowed to create a valid nullifier. As a result, the commitment hash and the nullifier hash share a common data field in their preimage so that the zk prover can cross-validate that data field for validity. Examples are: - Zcash (Sprout): The preimage of the Nullifier shares a note id `rho` with the commitment. - Zkopru: The UTXO is the commitment. The Nullifier has nullifier_seed and utxo_leaf_index. The former is derived from the sender's secret to make sure only the sender can create the nullifier. The latter makes sure the UTXO is only spent once. - Tornado Cash: A user deposits money and commits the secret named "nullifier." The zk proof convinces the system the user has deposited before by validating the commitment hash and nullifier hash. - Semaphore: Require a user to be registered to the system and commit a secret data named "identity nullifier." So only a registered user can create a valid nullifier hash. ## Conclusion We reviewed how several projects use nullifier hash to gurantee the single use of the message. We also explored the relationship between the nullifier and the commitment. We hope the post makes nullifier less a dangerous weapon and contributes to health regeneration for the dear readers.

    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
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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