Koh Wei Jie
    • 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
    # Fair NFT minting I propose to hack on this idea at ETHLisbon. ## The problem Many NFT projects feature NFTs with traits. Some traits are rarer than others, which makes them more valuable. Many NFT projects also distribute NFTs to minters at a constant mint price. To do so in an unbiased manner, projects need a source of fair randomness. Otherwise, a sophisticated attacker may use various techniques to mint rare NFTs for themselves and make a disproportionate profit. To generate on-chain randomness, however, is very hard. A poor solution is to make a smart contract use the current block hash, but this is highly inadvisable as a miner may easily manipulate this value. For instance, a malicious minter may bribe a miner to produce a block hash which will result in them receiving an extremely rare and valuable NFT when they perform a mint transaction. ## Existing solutions A popular solution is the Chainlink VRF service. Projects pay LINK tokens to Chainlink, which in turn generates a random number using a verifiable random function (VRF), and then calls the project's contract with the result. ## Why a new approach is useful We have nothing against Chainlink's VRF solution but it would be good for the ecosystem if teams can enjoy more choices. Teams that do not wish to use Chainlink VRF, for any reason whatsoever, should have an alternative. ## Our approach Our approach is to have the team and each minter commit to a secret value, and reveal it later. We use a ZKP to prove the correctness of multiple revealed values in a single transaction, allowing users and the team to save gas. Only one minter needs be honest for our approach to work. ## Technical details There are two actors in this protocol: 1. the NFT team ("the team") 2. the minters To begin the process, the team deploys a smart contract. The contract contains the following storage variables: | Name | Type | Set by | |-|-|-| | `mintDeadlineBlock` | `uint256` | Constructor | | `root` | `uint256` | Contract function | | `result` | `uint256` | Contract function | In the contract constructor, the team generates a random number `r` and inserts `h(r)` in the Merkle tree, updating `root`. Each minter then generates a random number `s`, and sends a transaction to the contract with the following: - `m` ETH, which is the constant mint price. - `h(s)`, which is the hash of `s`, represented as an `uint256` value. The contract inserts each `h(s)` in a Merkle tree with root `root` if the current block number is less than or equal to `mintDeadlineBlock`. After `mintDeadlineBlock`, each minter sends `s` to the team. As long as at least 1 minter does this after `mintDeadlineBlock`, this protocol should be collusion-resistant. Finally, the team generates a zero-knowledge proof (ZKP) and submits it to the contract. The ZKP proves the following: - The team knows the preimage `r` of the hash `h(r)`. - For each `h(s)` value, the prover knows the preimage `s`. - The prover knows a valid Merkle root to each leaf in the Merkle tree. - The prover knows an output `result` value which is the hash onion of `r` and all `s` values. - To illustrate, a hash onion of the values `[r, s1, s2, s3]` is `h(h(h(s3, r), s2), s1)`. The output signal `result` stored in the contract and used to randomly distribute NFTs using the Fisher-Yates shuffling algorithm. ## Why ZKPs are good for this use case A single ZKP can allow the team to prove that they know multiple (or even all) the `s` values. If there there is a high number of minters, the team or minters can save gas as the verification cost is constant. ## Downsides - To work around the hackerthon's time constraints, we limited our system to use a shallow Merkle tree, and compute the Merkle root in the circuit from *all* leaves. While this restricts the maximum number of minters due to the high number of circuit constraints and proving time, the solution is to verify the leaves in batches. - Every minter must submit their `s` value. At least one honest minter must do so after the deadline. This may not be user-friendly. - The process requires an additional step from each minter. - The mint function may be expensive if the protocol uses a snark-friendly hash function like Poseidon. - One way to alleviate the gas cost is to simply store each value, and have the team pay the gas needed to generate the Merkle root. This may be out of scope of this hackerthon. - Another solution is to use SHA256 for the Merkle tree, which is cheap in the EVM, but expensive for the prover. That said, circom 2 is very fast and a circuit that hashes 10 values using SHA256 (1230305 constraints) only requires 24 seconds to compile, though the resulting proving key will be extremely large (more than 1GB). ## Collusion resistance properties For the result to be unbiased, only one minter has to not collude with the team and other minters. To not collude, this minter must only reveal their secret `s` after the minting deadline. - If the team colludes with all the minters - The whole process is compromised if everyone colludes, but there is no point for the team to use this method. They might as well directly distribute the NFTs to the minters. - If all the minters collude, but not with the team - Since the team's `r` value is not known by the minters, the result is an unbiased random value.the result is an unbiased random value. - If the team colludes with **all but one** minters - If at least 1 minter withholds their `s` value, the result is an unbiased random value. - At least 1 honest minter must reveal their `s` value only after the beacon deadline so that colluding minters cannot select `s` values that bias the result.

    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