Lucas Vogelsang
    • 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
    # Pre Commit & Commit # Implementation Steps 1) Implement Pre Commit without CentID verification, store ID but don't check that sender is allowed 2) Implement Commit without CentID verification, store ID but don't check that sender is the CentID it claims to be 3) Modify Cent IDs to store signing key that is compatible with Ethereum 4) Implement check to verify merkle proof that signing_root in pre commit matches document_root in commit 5) Implement Signature validation on Pre Commit & Commit methods # Implementation Details ## Signatures To authenticate a request, we rely on our own signatures, not the account the tx is sent from. This adds some gas but let's DO IT! A signature is signing all arguments of the call. E.g. for preCommit: Payload: **(_anchorId+_signignRoot+_centId)** Signature: **Sign(Payload)** with private key that has a public key on centId Verification can be done by the smart contract by fetching the public key, reconstructing payload out of function arguments and checking the signature. The specifics for Signatures still need to be documented. ## Data Store This is a pretty good article on how to efficiently store/pack data: https://medium.com/@novablitz/storing-structs-is-costing-you-gas-774da988895e | Description | Name | Type | |-------------------|-----------------|---------| | Pre Commit Root | preCommitRoot | uint256 | | Pre Commit Sender | preCommitSender | uint256 | | Pre Commit Expiry | expirationBlock | uint32 | | Commit Root | commitRoot | mapping[uint256] => uint256 | > [name=Razvan Dinicut] > It will For the commitment, we only need to store the commitment root. Therefore a mapping of `uint256` to `uint256` is the most efficient way to represent it. For the pre commit, we are storing the following struct: ```js= struct PreAnchor { uint256 anchorId; uint256 signatureRoot; uint128 centrifugeId; uint32 expirationBlock; } ``` @Razvan: Please add proper field length for expirationBlock. ## Verifying pre commit matches commit We can ensure that anchors are only published if they got a valid pre-anchor and that the signing_root in the pre anchor is part of the document root of the final anchor. In the pre-commit the user commits to the signing root which is also sent to the other parties. Once all signatures have been gathered, the commit root is submitted along with a Merkle proof proving that the `document_root` contains `signing_root`. ## Privacy leak in pre commit There is a privacy leak when one entity makes a pre-commit, let’s it expire and then a different entity makes a new pre commit. If the pre commit ID is the same as the commitment ID, an adversary could see that the two entities are both part of this transaction. One possible workaround could be to use a Hash(centID+commit root) as the ID for the pre commit. Two different pre-commits on the same commit root would now not be linkable anymore however by doing so, the anchor registry loses the capability to enforce that only one valid pre commit exists at a time. The process would look as follows: 1. Alice creates pre-commit for document 1: ID: `Hash(Alice+1) -> signingRoot: sr1a` 2. Bob creates pre-commit for document 1: ID: `Hash(Bob+1) -> signingRoot: sr1b` 3. Bob creates commit for document 1: `ID 1 -> documentRoot: dr1b` To prove that Bob created a valid pre commit before, the contract can check for the pre commit by hashing `Bob+1` which returns the valid pre commit created in 2. 4. Alice creates a commit for document 1: `ID 1 -> documentRoot: dr1a` * Even though the pre commit of Alice is still valid, Bob’s commit was accepted first. One way to mitigate this would be to check in step 4 if Alice’s pre commit was mined before Bob and overwrite it if that was the case. However doing so makes finality much harder. Now instead of just having to make sure the commit tx got mined, you need to wait for the final expiry of all other potential anchors expired. We chose not to address the privacy leak at this time and implement the solution as described and possibly add a mitigation to this (via an off chain way to agree on a new identifier) later on. ## Solidity Functions ### Pre Commit **function preCommit(uint256 _anchorId, uint256 _signingRoot, uint256 _centId, uint256 _signature) external payable_** preCommit: * Should check that hasValidPrecommit(_anchorId)_ returns false * Should verify that signature is valid for centId It should store: * _signingRoot * _centId * blockheight **function hasValidPrecommit(uint256 _anchorId) public view returns (bool);** * should return false if the precommit is not set * should return false if the precommit is set but the precommit has expired ( expirationBlockHeight[_anchorId] < block.number) ### Commit **function commit(uint256 _commitId, uint256 _documentRoot, uint256 _centId, uint256 _signature) external payable** It should check: * should verify that `msg.sender` is authorized to act on behalf on centId * ensure that preCommit.centId == _centId * Should verify that signature is valid for centId * Maybe: Require a merkle proof that proves `preCommit.signingId` is in` _documentRoot` * Maybe: call checkPreCommit() and ensure it returns true or check it's empty It should store: * _documentRoot Maybe for gas refund it should empty all precommit fields (check how much gas is refunded). ## Open questions: * Should we require a merkle proof for a matching signingId with documentRoot. Check the cost? * Conflicting precommit: reveals other party. Do we need to care about this?

    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